Add vscode pagination

This commit is contained in:
Rodrigo Pombo 2019-02-18 23:47:16 -03:00
parent b95426cae4
commit 33c7f44157
5 changed files with 7 additions and 27 deletions

View File

@ -5,8 +5,7 @@ import {
useLanguageLoader,
useDocumentTitle,
Loading,
Error,
useLoader
Error
} from "./app-helpers";
import getGitProvider from "./git-providers/providers";
@ -62,19 +61,16 @@ function useCommitsLoader(gitProvider, path) {
const loadMore = () => {
setState(old => {
const shouldFetchMore = !old.loading && !old.noMore;
console.log(shouldFetchMore);
return shouldFetchMore
? { ...old, last: old.last + 10, loading: true }
: old;
});
};
console.log(state.loading, state.last);
useEffect(() => {
gitProvider
.getCommits(path, state.last)
.then(data => {
console.log("loaded", data.length, state.last);
setState(old => ({
data,
loading: false,

View File

@ -6,17 +6,8 @@ function showLanding() {
return false;
}
const cache = {
path: null,
commits: null,
promise: null
};
async function getCommits(path, last) {
// if (path !== cache.path) {
// cache = {};
// }
// TODO cache
const response = await fetch(
`/api/commits?path=${encodeURIComponent(path)}&last=${last}`
);

View File

@ -8,9 +8,7 @@ function showLanding() {
return false;
}
function getCommits() {
const path = getPath();
function getCommits(path, last) {
return new Promise((resolve, reject) => {
window.addEventListener(
"message",
@ -25,7 +23,8 @@ function getCommits() {
vscode.postMessage({
command: "commits",
params: {
path
path,
last
}
});
});

View File

@ -100,14 +100,8 @@ export default function History({ commits, language, loadMore }) {
const codes = commits.map(commit => commit.content);
const slideLines = getSlides(codes, language);
const cronologicalSlideLines = slideLines;
const cornologicalCommits = commits;
return (
<Slides
slideLines={cronologicalSlideLines}
commits={cornologicalCommits}
loadMore={loadMore}
/>
<Slides slideLines={slideLines} commits={commits} loadMore={loadMore} />
);
}

View File

@ -63,7 +63,7 @@ function activate(context) {
message => {
switch (message.command) {
case "commits":
const { path, last = 15, before = null } = message.params.path;
const { path, last = 15, before = null } = message.params;
getCommits(path, last, before)
.then(commits => {
panel.webview.postMessage(commits);