mirror of
https://github.com/pomber/git-history.git
synced 2024-09-11 14:35:57 +03:00
Add vscode pagination
This commit is contained in:
parent
b95426cae4
commit
33c7f44157
@ -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,
|
||||
|
@ -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}`
|
||||
);
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -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} />
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user