Files
radicle-explorer/src/lib/patchCounts.svelte.ts
T
Sebastian Martinez 499a0983ea Add rebuild cache functionality to issue and patch listing
In case of an outdated cobs cache we display a banner on top of the
patch or issue listing, to allow users to rebuild the cobs cache of a
repo similar to running `rad patch cache`
After rebuilding we fetch the issues or patches from the start.

Small caveat with patches:
The banner can only be shown after a user fetched all patches from the
backend, so we are sure we tried to fetch all of them.
2025-06-11 18:24:27 +02:00

42 lines
1.1 KiB
TypeScript

import type { PatchStatus } from "@app/views/repo/router";
import type { ProjectPayload } from "@bindings/repo/ProjectPayload";
import sum from "lodash/sum";
export const patchCounts = $state<
Record<PatchStatus | "all", { sidebar: number | null; total: number | null }>
>({
draft: { sidebar: null, total: null },
open: { sidebar: null, total: null },
archived: { sidebar: null, total: null },
merged: { sidebar: null, total: null },
all: { sidebar: null, total: null },
});
export function patchCountMismatch(status?: PatchStatus) {
return (
patchCounts[status || "all"].total !== patchCounts[status || "all"].sidebar
);
}
export function resetPatchCounts() {
Object.values(patchCounts).forEach(count => {
count.sidebar = null;
count.total = null;
});
}
export function updatePatchCounts(
itemCount: number,
sidebarCount: ProjectPayload["meta"]["patches"],
status?: PatchStatus,
) {
if (status) {
patchCounts[status].total = itemCount;
patchCounts[status].sidebar = sidebarCount[status];
} else {
patchCounts["all"].total = itemCount;
patchCounts["all"].sidebar = sum(Object.values(sidebarCount));
}
}