1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-31 02:59:42 +02:00
mealie/frontend/composables/store/use-label-store.ts
Kuchenpirat 13e7dfe920
Some checks failed
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docker Nightly Production / Backend Server Tests (push) Has been cancelled
Docker Nightly Production / Frontend and End-to-End Tests (push) Has been cancelled
Docker Nightly Production / Build Tagged Release (push) Has been cancelled
Docker Nightly Production / Notify Discord (push) Has been cancelled
getAll if array is empty or non existant (#3120)
2024-02-05 07:37:15 -06:00

49 lines
1,010 B
TypeScript

import { reactive, ref, Ref } from "@nuxtjs/composition-api";
import { useStoreActions } from "../partials/use-actions-factory";
import { MultiPurposeLabelOut } from "~/lib/api/types/labels";
import { useUserApi } from "~/composables/api";
let labelStore: Ref<MultiPurposeLabelOut[] | null> = ref([]);
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();
const loading = ref(false);
const actions = {
...useStoreActions<MultiPurposeLabelOut>(api.multiPurposeLabels, labelStore, loading),
flushStore() {
labelStore.value = [];
},
};
if (!labelStore.value || labelStore.value?.length === 0) {
labelStore = actions.getAll();
}
return {
labels: labelStore,
actions,
loading,
};
}