2022-05-29 17:29:59 -08:00
|
|
|
import { reactive, ref, Ref } from "@nuxtjs/composition-api";
|
|
|
|
import { useStoreActions } from "../partials/use-actions-factory";
|
2022-10-22 11:51:07 -08:00
|
|
|
import { MultiPurposeLabelOut } from "~/lib/api/types/labels";
|
2022-05-29 17:29:59 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
|
|
|
|
2024-02-04 19:55:14 +01:00
|
|
|
let labelStore: Ref<MultiPurposeLabelOut[] | null> = ref([]);
|
2024-03-12 17:36:30 -05:00
|
|
|
const storeLoading = ref(false);
|
2022-05-29 17:29:59 -08:00
|
|
|
|
|
|
|
export function useLabelData() {
|
|
|
|
const data = reactive({
|
|
|
|
groupId: "",
|
|
|
|
id: "",
|
|
|
|
name: "",
|
|
|
|
color: "",
|
|
|
|
});
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
data.groupId = "";
|
|
|
|
data.id = "";
|
|
|
|
data.name = "";
|
|
|
|
data.color = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
data,
|
|
|
|
reset,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useLabelStore() {
|
|
|
|
const api = useUserApi();
|
2024-03-12 17:36:30 -05:00
|
|
|
const loading = storeLoading;
|
2022-05-29 17:29:59 -08:00
|
|
|
|
|
|
|
const actions = {
|
|
|
|
...useStoreActions<MultiPurposeLabelOut>(api.multiPurposeLabels, labelStore, loading),
|
|
|
|
flushStore() {
|
2024-02-05 14:37:15 +01:00
|
|
|
labelStore.value = [];
|
2022-05-29 17:29:59 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-03-12 17:36:30 -05:00
|
|
|
if (!loading.value && (!labelStore.value || labelStore.value?.length === 0)) {
|
2022-05-29 17:29:59 -08:00
|
|
|
labelStore = actions.getAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labelStore,
|
|
|
|
actions,
|
|
|
|
loading,
|
|
|
|
};
|
|
|
|
}
|