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 {