From 67f02463eed9105f84107bec66afbcc7fba35aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 20 Apr 2023 16:38:44 +0200 Subject: [PATCH] Refactor commit history view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rūdolfs Ošiņš --- src/components/List.svelte | 58 -------------- src/views/projects/History.svelte | 123 ++++++++++++++++++++---------- src/views/projects/View.svelte | 13 +--- 3 files changed, 83 insertions(+), 111 deletions(-) delete mode 100644 src/components/List.svelte diff --git a/src/components/List.svelte b/src/components/List.svelte deleted file mode 100644 index cfd12c7ef..000000000 --- a/src/components/List.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - - - - -{#if !complete} - - {#if loading} -
- -
- {:else} -
- -
- {/if} -
-{/if} diff --git a/src/views/projects/History.svelte b/src/views/projects/History.svelte index e650dfefb..9307f1be7 100644 --- a/src/views/projects/History.svelte +++ b/src/views/projects/History.svelte @@ -5,31 +5,61 @@ import { HttpdClient } from "@httpd-client"; import { groupCommits } from "@app/lib/commit"; + import Button from "@app/components/Button.svelte"; import CommitTeaser from "./Commit/CommitTeaser.svelte"; - import List from "@app/components/List.svelte"; + import ErrorMessage from "@app/components/ErrorMessage.svelte"; + import Loading from "@app/components/Loading.svelte"; - export let id: string; + export let projectId: string; export let baseUrl: BaseUrl; - export let history: CommitHeader[]; + export let parentCommit: string; + + const perPage = 30; + + let page = 0; + let error: any; + let loading = false; + let totalCommitCount: number | undefined = undefined; + let history: CommitHeader[] = []; const api = new HttpdClient(baseUrl); - const fetchMoreCommits = async (): Promise => { - const response = await api.project.getAllCommits(id, { - // Fetching 31 elements since we remove the first one - parent: history[history.length - 1].id, - perPage: 31, - }); - // Removing the first element of the array, since it's the same as the last of the current list - return response.commits.slice(1).map(c => c.commit); - }; + async function loadHistory(): Promise { + loading = true; + try { + const response = await api.project.getAllCommits(projectId, { + parent: parentCommit, + page, + perPage, + }); + history = [...history, ...response.commits.map(c => c.commit)]; + totalCommitCount = response.stats.commits; + page += 1; + } catch (e) { + error = e; + } finally { + loading = false; + } + } - const browseCommit = (event: { detail: string }) => { + function goToSourceTreeAtCommit(event: { detail: string }) { router.updateProjectRoute({ view: { resource: "tree" }, revision: event.detail, }); - }; + } + + function goToCommit(revision: string) { + router.updateProjectRoute({ + view: { resource: "commits" }, + revision, + }); + } + + $: showMoreButton = + !loading && !error && totalCommitCount && history.length < totalCommitCount; + + loadHistory(); -
- - - {@const commits = groupCommits(items)} - {#each commits as group (group.time)} -
-
-

{group.date}

-
-
- {#each group.commits as commit (commit.id)} - { - router.updateProjectRoute({ - view: { resource: "commits" }, - revision: commit.id, - }); - }} - on:browseCommit={browseCommit} /> - {/each} -
+{#if history} +
+ {#each groupCommits(history) as group (group.time)} +
+
+

{group.date}

+
+
+ {#each group.commits as commit (commit.id)} + goToCommit(commit.id)} + on:browseCommit={goToSourceTreeAtCommit} /> + {/each}
- {/each} - - -
+
+ {/each} +
+ {#if loading} + + {/if} + + {#if showMoreButton} + + {/if} +
+
+{/if} + +{#if error} +
+ +
+{/if} diff --git a/src/views/projects/View.svelte b/src/views/projects/View.svelte index 527d576dd..1f38ba43f 100644 --- a/src/views/projects/View.svelte +++ b/src/views/projects/View.svelte @@ -198,18 +198,7 @@ {#if activeRoute.params.view.resource === "tree"} {:else if activeRoute.params.view.resource === "history"} - {#await api.project.getAllCommits(project.id, { parent: commit })} - - {:then history} - c.commit)} /> - {:catch e} -
- -
- {/await} + {:else if activeRoute.params.view.resource === "commits"} {#await api.project.getCommitBySha(id, commit)}