mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-06 04:10:31 +08:00
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.
42 lines
1.1 KiB
TypeScript
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));
|
|
}
|
|
}
|