From 680a7813982be0a1cbea8eaa9822d856ec5082f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 19 Nov 2026 15:58:34 +0100 Subject: [PATCH] desktop: Refresh releases on updates Releases were the one COB with keys of their own that nothing listened on: the release list, a release and the sidebar count now refresh when a release changes, and the user's own release writes refresh them too. --- desktop/src/components/SidebarRepoList.svelte | 10 ++++++ desktop/src/lib/writes.ts | 17 +++++++++- desktop/src/views/repo/Release.svelte | 32 ++++++++++++++++--- desktop/src/views/repo/Releases.svelte | 26 ++++++++++++++- desktop/src/views/repo/router.ts | 2 ++ desktop/tests/unit/writeCoverage.test.ts | 14 ++------ shared/core/src/keys.ts | 5 +++ 7 files changed, 89 insertions(+), 17 deletions(-) diff --git a/desktop/src/components/SidebarRepoList.svelte b/desktop/src/components/SidebarRepoList.svelte index fe75a61a9..be1fce4f0 100644 --- a/desktop/src/components/SidebarRepoList.svelte +++ b/desktop/src/components/SidebarRepoList.svelte @@ -204,8 +204,18 @@ // Kept while navigating inside the repo, so the badge doesn't flicker. let releaseCount = $state(undefined); let countedRid: string | undefined = undefined; + // Bumped when the active repo's releases change, to count them again. + let releasesChanged = $state(0); + onInvalidate( + queryClient, + () => keys.releaseCount(activeRepo?.rid ?? ""), + async () => { + releasesChanged++; + }, + ); $effect(() => { + void releasesChanged; const rid = activeRepo?.rid; if (rid === undefined) { releaseCount = undefined; diff --git a/desktop/src/lib/writes.ts b/desktop/src/lib/writes.ts index a11b474d8..5aa5bd9ac 100644 --- a/desktop/src/lib/writes.ts +++ b/desktop/src/lib/writes.ts @@ -12,6 +12,18 @@ interface WriteArgs { args?: { rid?: unknown }; } +const releaseWrites = [ + "create_or_open_release", + "delete_release", + "attest_artifact", + "redact_artifact", + "register_artifact", + "add_artifact_location", + "remove_artifact_location", + "set_artifact_metadata", + "remove_artifact_metadata", +]; + // Write commands whose effect on the cache is mapped below. Other writes change // data the cache doesn't hold. export const mappedWrites = [ @@ -29,6 +41,7 @@ export const mappedWrites = [ "unseed", "clean", "clear_notifications", + ...releaseWrites, ]; // The keys a command's write affects, so that the user's own changes show @@ -84,6 +97,8 @@ export function writtenKeys( case "clear_notifications": return [keys.notifications()]; default: - return []; + return releaseWrites.includes(cmd) && typeof rid === "string" + ? [keys.releases(rid)] + : []; } } diff --git a/desktop/src/views/repo/Release.svelte b/desktop/src/views/repo/Release.svelte index 31ecee96d..e8f2520ed 100644 --- a/desktop/src/views/repo/Release.svelte +++ b/desktop/src/views/repo/Release.svelte @@ -5,10 +5,15 @@ import type { Config } from "@bindings/config/Config"; import type { RepoInfo } from "@bindings/repo/RepoInfo"; + import { keys } from "@radicle-gui/core/keys"; + import { onInvalidate } from "@radicle-gui/ui/lib/query.svelte"; + import { onDestroy } from "svelte"; + import { pickFiles, pickFolder } from "@app/lib/artifactPickers"; import { basename } from "@app/lib/embeds"; import { invoke } from "@app/lib/invoke"; import { show } from "@app/lib/modal"; + import { queryClient } from "@app/lib/query"; import { artifactView, releaseWarning } from "@app/lib/releases"; import * as router from "@app/lib/router"; import type { Picked, StagedArtifact } from "@app/lib/stageArtifacts"; @@ -200,10 +205,16 @@ title, shared: release.artifacts.some(a => a.author.did !== ownDid), confirm: async () => { - await invoke("delete_release", { - rid: repo.rid, - releaseId: release.id, - }); + deleting = true; + try { + await invoke("delete_release", { + rid: repo.rid, + releaseId: release.id, + }); + } catch (error) { + deleting = false; + throw error; + } await router.push({ resource: "repo.releases", rid: repo.rid }); }, }, @@ -211,6 +222,16 @@ } let seededCids = $state>(new Set()); + // Deleting it here navigates by itself, as does leaving the view while a + // refresh is under way. + let deleting = false; + onDestroy(() => { + deleting = true; + }); + + // Other people's changes to the release, such as new artifacts or + // attestations, show as they arrive. + onInvalidate(queryClient, () => keys.release(repo.rid, release.id), refresh); async function refreshSeeded() { try { @@ -246,6 +267,9 @@ }); if (updated) { release = updated; + } else if (!deleting) { + // Deleted elsewhere while shown. + await router.push({ resource: "repo.releases", rid: repo.rid }); } } catch (error) { console.error("Refreshing the release failed", error); diff --git a/desktop/src/views/repo/Releases.svelte b/desktop/src/views/repo/Releases.svelte index c07175da2..e036833ba 100644 --- a/desktop/src/views/repo/Releases.svelte +++ b/desktop/src/views/repo/Releases.svelte @@ -6,9 +6,13 @@ import type { RepoInfo } from "@bindings/repo/RepoInfo"; import { listReleases, RELEASES_PER_PAGE } from "@app/views/repo/router"; + import { keys } from "@radicle-gui/core/keys"; + import { onInvalidate } from "@radicle-gui/ui/lib/query.svelte"; + import { invoke } from "@app/lib/invoke"; import { modalStore, show } from "@app/lib/modal"; import { createPaginatedList } from "@app/lib/paginatedList.svelte"; + import { queryClient } from "@app/lib/query"; import * as router from "@app/lib/router"; import { isMac } from "@app/lib/utils"; @@ -31,7 +35,15 @@ showFilters: boolean; } - const { repo, releases, releaseCounts, scope, showFilters }: Props = $props(); + const { + repo, + releases, + releaseCounts: loadedCounts, + scope, + showFilters, + }: Props = $props(); + + let releaseCounts = $derived(loadedCounts); const delegateIds = $derived(new Set(repo.delegates.map(d => d.did))); @@ -46,6 +58,18 @@ pageSize: RELEASES_PER_PAGE, id: release => release.id, }); + + async function refresh() { + const [, counts] = await Promise.all([ + list.revalidate(Math.max(list.items.length, RELEASES_PER_PAGE)), + invoke("release_counts", { rid: repo.rid }), + ]); + releaseCounts = counts; + } + + // The paginated list keeps its own pages, so the cache only tells it when + // to refresh. + onInvalidate(queryClient, () => keys.releaseList(repo.rid, scope), refresh);