mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 08:35:43 +00:00
b77c9be36f
* bump prettier/eslint-plugin * bump nuxt pwa * use typed imports * set vue version to fix layout errors * disable import
39 lines
994 B
TypeScript
39 lines
994 B
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(),
|
|
}),
|
|
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[] {
|
|
if (state.allLabels === null) {
|
|
this.client.labels.getAll().then(result => {
|
|
if (result.error) {
|
|
console.error(result.error);
|
|
}
|
|
|
|
this.allLabels = result.data;
|
|
});
|
|
}
|
|
return state.allLabels ?? [];
|
|
},
|
|
},
|
|
actions: {
|
|
async refresh() {
|
|
const result = await this.client.labels.getAll();
|
|
if (result.error) {
|
|
return result;
|
|
}
|
|
|
|
this.allLabels = result.data;
|
|
return result;
|
|
},
|
|
},
|
|
});
|