mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
desktop: Show newer commits on the repo home
The page keeps showing the code the user is reading and offers the newer commits when the branch moves.
This commit is contained in:
@@ -22,10 +22,21 @@
|
||||
baseRoute: SourceBaseRoute;
|
||||
active: "files" | "commits";
|
||||
extra?: Snippet;
|
||||
// Shown just before the peer selector, about the revision it selects.
|
||||
notice?: Snippet;
|
||||
}
|
||||
|
||||
const { repo, peer, revision, oid, commit, baseRoute, active, extra }: Props =
|
||||
$props();
|
||||
const {
|
||||
repo,
|
||||
peer,
|
||||
revision,
|
||||
oid,
|
||||
commit,
|
||||
baseRoute,
|
||||
active,
|
||||
extra,
|
||||
notice,
|
||||
}: Props = $props();
|
||||
|
||||
// The commit count requires a full history walk on the backend, so it is
|
||||
// fetched after render instead of blocking navigation. The key guard keeps
|
||||
@@ -127,6 +138,10 @@
|
||||
gap: 2px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.notice {
|
||||
display: flex;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
.commit-summary {
|
||||
color: var(--color-text-secondary);
|
||||
font: var(--txt-body-m-regular);
|
||||
@@ -171,6 +186,9 @@
|
||||
{/if}
|
||||
|
||||
<div class="selector-group">
|
||||
{#if notice}
|
||||
<span class="notice">{@render notice()}</span>
|
||||
{/if}
|
||||
<PeerSelector {baseRoute} {repo} {refs} {peer} {revision} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
||||
@@ -5,16 +5,20 @@
|
||||
import type { Blob } from "@bindings/source/Blob";
|
||||
import type { Tree } from "@bindings/source/Tree";
|
||||
|
||||
import { keys } from "@radicle-gui/core/keys";
|
||||
import { createQuery } from "@radicle-gui/ui/lib/query.svelte";
|
||||
import { toHtml } from "hast-util-to-html";
|
||||
import { capitalize } from "lodash";
|
||||
import { useOverlayScrollbars } from "overlayscrollbars-svelte";
|
||||
|
||||
import { invoke, InvokeError } from "@app/lib/invoke";
|
||||
import { queryClient } from "@app/lib/query";
|
||||
import * as router from "@app/lib/router";
|
||||
import type { SidebarData } from "@app/lib/router/definitions";
|
||||
import { highlight } from "@app/lib/syntax";
|
||||
|
||||
import Asciidoc from "@app/components/Asciidoc.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import FileBlock from "@app/components/FileBlock.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Id from "@app/components/Id.svelte";
|
||||
@@ -60,6 +64,35 @@
|
||||
revision,
|
||||
});
|
||||
|
||||
// The commit the shown revision resolves to now. A branch, or the default
|
||||
// branch without a revision, can move on while the user reads, so the page
|
||||
// keeps showing `oid` and offers the newer commit.
|
||||
const headKey = $derived(keys.head(repo.rid, peer, revision));
|
||||
// The loader has just resolved the revision, so that is the latest commit.
|
||||
// A ref update during the load may have moved it since, so then the head is
|
||||
// checked again at mount, and a push during the load still shows as newer.
|
||||
$effect.pre(() => {
|
||||
queryClient.setQueryData(headKey, oid);
|
||||
const loaded = keys.headLoaded(repo.rid, peer, revision);
|
||||
if (queryClient.getQueryState(loaded)?.isInvalidated) {
|
||||
void queryClient.invalidateQueries({ queryKey: headKey, exact: true });
|
||||
}
|
||||
});
|
||||
const head = createQuery<string>(queryClient, () => ({
|
||||
queryKey: headKey,
|
||||
queryFn: async () =>
|
||||
(
|
||||
await invoke<Commit>("repo_commit", {
|
||||
rid: repo.rid,
|
||||
peer,
|
||||
revision,
|
||||
})
|
||||
).id,
|
||||
}));
|
||||
const newerCommit = $derived(
|
||||
head.current.data !== undefined && head.current.data !== oid,
|
||||
);
|
||||
|
||||
let currentPath = $state("");
|
||||
let codeElement: HTMLElement | undefined = $state();
|
||||
let error: InvokeError | undefined = $state();
|
||||
@@ -206,7 +239,20 @@
|
||||
{oid}
|
||||
{commit}
|
||||
{baseRoute}
|
||||
active="files" />
|
||||
active="files">
|
||||
{#snippet notice()}
|
||||
{#if newerCommit}
|
||||
<Button
|
||||
variant="outline"
|
||||
styleHeight="1.75rem"
|
||||
title="There are newer commits. Show the latest."
|
||||
onclick={() => void router.replace({ ...baseRoute, path })}>
|
||||
<Icon name="refresh" />
|
||||
Newer commits
|
||||
</Button>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</SourceHeader>
|
||||
<div
|
||||
style:display="grid"
|
||||
style:grid-template-columns="16.5rem 1fr"
|
||||
|
||||
@@ -389,6 +389,10 @@ async function loadSourceContext(route: {
|
||||
peer?: string;
|
||||
revision?: string;
|
||||
}): Promise<SourceContext> {
|
||||
markLoading(
|
||||
queryClient,
|
||||
keys.headLoaded(route.rid, route.peer, route.revision),
|
||||
);
|
||||
const [sidebarData, repo, commit] = await Promise.all([
|
||||
loadSidebarData(),
|
||||
load(repoInfo(route.rid)),
|
||||
|
||||
@@ -7,6 +7,25 @@ export const keys = {
|
||||
repo: (rid: string) => ["repo", rid] as const,
|
||||
repoInfo: (rid: string) => ["repo", rid, "info"] as const,
|
||||
code: (rid: string) => ["repo", rid, "code"] as const,
|
||||
// The commit a revision resolves to; no revision means the default branch.
|
||||
head: (rid: string, peer: string | undefined, revision: string | undefined) =>
|
||||
["repo", rid, "code", "head", peer ?? "", revision ?? ""] as const,
|
||||
// When a route last resolved that revision, so that a ref update during the
|
||||
// load can tell the view to check the head again.
|
||||
headLoaded: (
|
||||
rid: string,
|
||||
peer: string | undefined,
|
||||
revision: string | undefined,
|
||||
) =>
|
||||
[
|
||||
"repo",
|
||||
rid,
|
||||
"code",
|
||||
"head",
|
||||
peer ?? "",
|
||||
revision ?? "",
|
||||
"loaded",
|
||||
] as const,
|
||||
issues: (rid: string) => ["repo", rid, "issues"] as const,
|
||||
// One status's list; `status` is the filter as the view names it.
|
||||
issueList: (rid: string, status: string) =>
|
||||
|
||||
Reference in New Issue
Block a user