From ef22910154f1b26c1377ec86df7dd444eb9b18c8 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 15:39:25 -0400 Subject: [PATCH] DRY pass #3: the labels store swaps a returned label in one way (#5373) rename and setColor each found the label and replaced it, keeping the count the single-label PATCH doesn't recompute; keepingCount(updated) is that. Co-Authored-By: Claude Opus 5.5 --- frontend/src/stores/labels.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/stores/labels.ts b/frontend/src/stores/labels.ts index 403347d..ece0494 100644 --- a/frontend/src/stores/labels.ts +++ b/frontend/src/stores/labels.ts @@ -18,6 +18,13 @@ export const useLabelsStore = defineStore("labels", () => { items.value.sort((a, b) => a.name.localeCompare(b.name)); } + // Put a label the server sent back in place of ours. A single-label PATCH doesn't + // recompute the count, so the one we have is kept. + function keepingCount(updated: Label): void { + const idx = items.value.findIndex((lb) => lb.id === updated.id); + if (idx >= 0) items.value[idx] = { ...updated, count: items.value[idx].count }; + } + async function load(): Promise { items.value = await repo.labels.list(); loaded.value = true; @@ -62,16 +69,12 @@ export const useLabelsStore = defineStore("labels", () => { await load(); return; } - const idx = items.value.findIndex((lb) => lb.id === id); - // The single-label PATCH doesn't recompute the count — keep the one we have. - if (idx >= 0) items.value[idx] = { ...updated, count: items.value[idx].count }; + keepingCount(updated); sort(); } async function setColor(id: string, color: string): Promise { - const updated = await repo.labels.setColor(id, color); - const idx = items.value.findIndex((lb) => lb.id === id); - if (idx >= 0) items.value[idx] = { ...updated, count: items.value[idx].count }; + keepingCount(await repo.labels.setColor(id, color)); } async function remove(id: string): Promise {