2022-09-13 03:36:22 +00:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import { 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) {
|
2023-02-18 06:41:01 +00:00
|
|
|
this.client.labels.getAll().then(result => {
|
|
|
|
if (result.error) {
|
|
|
|
console.error(result.error);
|
|
|
|
}
|
2023-02-18 18:47:04 +00:00
|
|
|
|
2023-03-21 05:48:22 +00:00
|
|
|
this.allLabels = result.data;
|
2023-02-18 06:41:01 +00:00
|
|
|
});
|
2022-09-13 03:36:22 +00:00
|
|
|
}
|
2023-02-18 06:41:01 +00:00
|
|
|
return state.allLabels ?? [];
|
2022-09-13 03:36:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
2023-02-18 06:41:01 +00:00
|
|
|
async refresh() {
|
2022-09-13 03:36:22 +00:00
|
|
|
const result = await this.client.labels.getAll();
|
|
|
|
if (result.error) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-21 05:48:22 +00:00
|
|
|
this.allLabels = result.data;
|
2022-09-13 03:36:22 +00:00
|
|
|
return result;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|