import { defineStore } from "pinia"; import { ref } from "vue"; import { repo } from "../adapters"; export interface Label { id: string; name: string; color: string; // Number of notes carrying this label (from GET /api/labels; used in label management). count?: number; } export const useLabelsStore = defineStore("labels", () => { const items = ref([]); const loaded = ref(false); function sort() { 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; } async function create(name: string): Promise