Files
homebox/frontend/stores/labels.ts
Benjamin Wolff 2bdd085289 Item search query parameter modernisation (#1040)
* await labels and locations properly

* update query params with every search

* don't persist default settings in query params

* conceptualize optional parameters

* add run script for development

* lint

* consider typescript

* remove run.sh

* capitalize QueryParamValue

* make query parameter updates predictable

This reverts commit 5c0c48cea5.

* capitalize typename again

---------

Co-authored-by: Benji <benji@DG-SM-7059.local>
Co-authored-by: Benji <benji@mac.home.internal>
Co-authored-by: Benji <benji@dg-sm-7059.home.internal>
2025-10-21 19:40:46 +01:00

42 lines
1.1 KiB
TypeScript

import { defineStore } from "pinia";
import type { LabelOut } from "~~/lib/api/types/data-contracts";
export const useLabelStore = defineStore("labels", {
state: () => ({
allLabels: null as LabelOut[] | null,
client: useUserApi(),
refreshAllLabelsPromise: null as Promise<void> | null,
}),
getters: {
/**
* labels represents the labels that are currently in the store. The store is
* synched with the server by intercepting the API calls and updating on the
* response.
*/
labels(state): LabelOut[] {
return state.allLabels ?? [];
},
},
actions: {
async ensureAllLabelsFetched() {
if (this.allLabels !== null) {
return;
}
if (this.refreshAllLabelsPromise === null) {
this.refreshAllLabelsPromise = this.refresh().then(() => {});
}
await this.refreshAllLabelsPromise;
},
async refresh() {
const result = await this.client.labels.getAll();
if (result.error) {
return result;
}
this.allLabels = result.data;
return result;
},
},
});