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 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,13 @@ export const useLabelsStore = defineStore("labels", () => {
|
|||||||
items.value.sort((a, b) => a.name.localeCompare(b.name));
|
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<void> {
|
async function load(): Promise<void> {
|
||||||
items.value = await repo.labels.list();
|
items.value = await repo.labels.list();
|
||||||
loaded.value = true;
|
loaded.value = true;
|
||||||
@@ -62,16 +69,12 @@ export const useLabelsStore = defineStore("labels", () => {
|
|||||||
await load();
|
await load();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const idx = items.value.findIndex((lb) => lb.id === id);
|
keepingCount(updated);
|
||||||
// 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 };
|
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setColor(id: string, color: string): Promise<void> {
|
async function setColor(id: string, color: string): Promise<void> {
|
||||||
const updated = await repo.labels.setColor(id, color);
|
keepingCount(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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function remove(id: string): Promise<void> {
|
async function remove(id: string): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user