homebox/frontend/stores/labels.ts
Hayden bd321af29f
chore: developer cleanup (#300)
* new PR tasks

* add homebox to know words

* formatting

* bump deps

* generate db models

* ts errors

* drop id

* fix accessor

* drop unused time field

* change CI

* add expected error

* add type check

* resolve serveral type errors

* hoise in CI
2023-02-17 21:41:01 -09:00

37 lines
954 B
TypeScript

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) {
this.client.labels.getAll().then(result => {
if (result.error) {
console.error(result.error);
}
});
}
return state.allLabels ?? [];
},
},
actions: {
async refresh() {
const result = await this.client.labels.getAll();
if (result.error) {
return result;
}
this.allLabels = result.data.items;
return result;
},
},
});