From e0ccaedf356f3c710d4c23a2edc82b4d411e7eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Fri, 20 Nov 2026 10:55:29 +0100 Subject: [PATCH] desktop: Refresh the identity view Proposals and votes show as they arrive. Identity COB updates now refresh only the identity instead of the whole repository. --- desktop/src/lib/cobQueries.ts | 10 +++++++++- desktop/src/views/repo/Identity.svelte | 10 +++++++++- desktop/src/views/repo/router.ts | 12 ++++++++---- shared/core/src/keys.ts | 2 ++ shared/core/src/refUpdates.ts | 6 ++++++ shared/core/tests/refUpdates.test.ts | 9 +++++++++ 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/desktop/src/lib/cobQueries.ts b/desktop/src/lib/cobQueries.ts index a4a23c2f8..be117261b 100644 --- a/desktop/src/lib/cobQueries.ts +++ b/desktop/src/lib/cobQueries.ts @@ -5,6 +5,7 @@ import type { Action as PatchAction } from "@bindings/cob/patch/Action"; import type { Patch } from "@bindings/cob/patch/Patch"; import type { Revision } from "@bindings/cob/patch/Revision"; import type { Thread } from "@bindings/cob/thread/Thread"; +import type { Identity } from "@bindings/identity/Identity"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; import type { Key } from "@radicle-gui/core/keys"; import type { QueryOptions } from "@radicle-gui/ui/lib/query.svelte"; @@ -23,7 +24,14 @@ export function repoInfo(rid: string): QueryOptions { }; } -// `issue` is null once the issue is deleted. +export function identity(rid: string): QueryOptions { + return { + queryKey: keys.identity(rid), + queryFn: () => invoke("identity_by_repo", { rid }), + }; +} + +// `issue` is undefined once the issue is deleted. export interface IssueDetail { issue: Issue | undefined; activity: Operation[]; diff --git a/desktop/src/views/repo/Identity.svelte b/desktop/src/views/repo/Identity.svelte index 942943bda..89a13d650 100644 --- a/desktop/src/views/repo/Identity.svelte +++ b/desktop/src/views/repo/Identity.svelte @@ -2,10 +2,13 @@ import type { Identity } from "@bindings/identity/Identity"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; + import { createQuery } from "@radicle-gui/ui/lib/query.svelte"; import { slide } from "svelte/transition"; + import { identity as identityQuery } from "@app/lib/cobQueries"; import { stateCaption, stateIcon } from "@app/lib/identityState"; import { motion } from "@app/lib/motion"; + import { queryClient } from "@app/lib/query"; import type { SidebarData } from "@app/lib/router/definitions"; import { absoluteTimestamp, @@ -33,7 +36,12 @@ sidebarData: SidebarData; } - const { repo, identity, sidebarData }: Props = $props(); + const { repo, identity: loadedIdentity, sidebarData }: Props = $props(); + + // Proposals and votes show as they arrive. The route loader already put the + // identity in the cache. + const query = createQuery(queryClient, () => identityQuery(repo.rid)); + const identity = $derived(query.current.data ?? loadedIdentity); const current = $derived( identity.revisions.find(r => r.id === identity.current), diff --git a/desktop/src/views/repo/router.ts b/desktop/src/views/repo/router.ts index f0ed92956..457f04677 100644 --- a/desktop/src/views/repo/router.ts +++ b/desktop/src/views/repo/router.ts @@ -26,7 +26,13 @@ import { markLoading } from "@radicle-gui/ui/lib/query.svelte"; import type { BoardView } from "@app/lib/board"; import { loadView } from "@app/lib/boardView"; -import { issueDetail, load, patchDetail, repoInfo } from "@app/lib/cobQueries"; +import { + identity as identityQuery, + issueDetail, + load, + patchDetail, + repoInfo, +} from "@app/lib/cobQueries"; import { cachedGetCommitDiff, cachedGetDiffText, @@ -495,9 +501,7 @@ export async function loadIdentity( const [sidebarData, repo, identity] = await Promise.all([ loadSidebarData(), load(repoInfo(route.rid)), - invoke("identity_by_repo", { - rid: route.rid, - }), + load(identityQuery(route.rid)), ]); return { diff --git a/shared/core/src/keys.ts b/shared/core/src/keys.ts index c1513f39d..e2492e200 100644 --- a/shared/core/src/keys.ts +++ b/shared/core/src/keys.ts @@ -6,6 +6,8 @@ export type Key = readonly string[]; export const keys = { repo: (rid: string) => ["repo", rid] as const, repoInfo: (rid: string) => ["repo", rid, "info"] as const, + // The identity document's revisions and proposals. + identity: (rid: string) => ["repo", rid, "identity"] 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) => diff --git a/shared/core/src/refUpdates.ts b/shared/core/src/refUpdates.ts index 076b9cb60..e0dc11a18 100644 --- a/shared/core/src/refUpdates.ts +++ b/shared/core/src/refUpdates.ts @@ -17,6 +17,7 @@ export const cobTypes = { // Releases are artifact COBs. release: "dev.radicle.artifact", board: "works.monadic.board", + identity: "xyz.radicle.id", } as const; const { issue: ISSUE, @@ -24,6 +25,7 @@ const { job: JOB, release: RELEASE, board: BOARD, + identity: IDENTITY, } = cobTypes; export function affectedKeys({ rid, refs }: RefUpdate): Key[] { @@ -54,6 +56,10 @@ export function affectedKeys({ rid, refs }: RefUpdate): Key[] { add(keys.releases(rid)); } else if (cob && cob[1] === BOARD) { add(keys.boards(rid)); + } else if (cob && cob[1] === IDENTITY) { + // Proposals and votes. An accepted revision also moves `refs/rad/id`, + // which affects the whole repository. + add(keys.identity(rid)); } else if (/^refs\/(heads|tags)\//.test(name)) { add(keys.code(rid)); add(keys.repoInfo(rid)); diff --git a/shared/core/tests/refUpdates.test.ts b/shared/core/tests/refUpdates.test.ts index 0afcc64ba..f2a8d8f2b 100644 --- a/shared/core/tests/refUpdates.test.ts +++ b/shared/core/tests/refUpdates.test.ts @@ -86,4 +86,13 @@ describe("affectedKeys", () => { }), ).toEqual([keys.repo(rid)]); }); + + test("identity proposals affect only the identity", () => { + expect( + affectedKeys({ + rid, + refs: [`refs/namespaces/${nid}/refs/cobs/xyz.radicle.id/${issue}`], + }), + ).toEqual([keys.identity(rid)]); + }); });