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.
This commit is contained in:
Rūdolfs Ošiņš
2026-11-20 19:32:17 +01:00
parent e9c519068d
commit 680a781398
7 changed files with 89 additions and 17 deletions
@@ -204,8 +204,18 @@
// Kept while navigating inside the repo, so the badge doesn't flicker.
let releaseCount = $state<number | undefined>(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;
+16 -1
View File
@@ -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)]
: [];
}
}
+28 -4
View File
@@ -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<Set<string>>(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);
+25 -1
View File
@@ -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<ReleaseCounts>("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);
</script>
<style>
+2
View File
@@ -578,6 +578,7 @@ export async function loadReleases(
route: RepoReleasesRoute,
): Promise<LoadedRepoReleasesRoute> {
const scope = route.scope ?? "trusted";
markLoading(queryClient, keys.releaseList(route.rid, scope));
const [sidebarData, repo, releases, releaseCounts] = await Promise.all([
loadSidebarData(),
load(repoInfo(route.rid)),
@@ -606,6 +607,7 @@ export async function loadReleases(
export async function loadRelease(
route: RepoReleaseRoute,
): Promise<LoadedRepoReleaseRoute | LoadedRepoReleasesRoute> {
markLoading(queryClient, keys.release(route.rid, route.release));
const [sidebarData, repo, release] = await Promise.all([
loadSidebarData(),
load(repoInfo(route.rid)),
+3 -11
View File
@@ -85,25 +85,17 @@ const outsideCache = [
"retire_actor",
"update_actor_profile",
"withdraw_actor_revision",
// Writes outside the cache: boards, releases, artifacts, embeds, files and
// notifications, which their views reload themselves.
"add_artifact_location",
"attest_artifact",
// Writes outside the cache. The board shows its own writes as they land,
// and a reload after each would make cards jump while the user moves more.
// Artifact seeding, embeds and files aren't in the cache.
"create_board",
"create_or_open_release",
"delete_release",
"download_artifact",
"redact_artifact",
"register_artifact",
"remove_artifact_location",
"remove_artifact_metadata",
"rename_board",
"save_diff_to_disk",
"save_embed_by_bytes",
"save_embed_by_path",
"save_embed_to_disk",
"seed_artifact",
"set_artifact_metadata",
"set_board_columns",
"unseed_artifact",
"update_board",
+5
View File
@@ -37,6 +37,11 @@ export const keys = {
patch: (rid: string, id: string) => ["repo", rid, "patch", id] as const,
patchDetails: (rid: string) => ["repo", rid, "patch"] as const,
releases: (rid: string) => ["repo", rid, "releases"] as const,
releaseList: (rid: string, scope: string) =>
["repo", rid, "releases", "list", scope] as const,
release: (rid: string, id: string) =>
["repo", rid, "releases", "release", id] as const,
releaseCount: (rid: string) => ["repo", rid, "releases", "count"] as const,
boards: (rid: string) => ["repo", rid, "boards"] as const,
jobs: (rid: string) => ["repo", rid, "jobs"] as const,
repos: () => ["repos"] as const,