mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-23 15:31:37 -04:00
* use generic context menu * implement organizer stores * add basic organizer types * refactor selectors to apply for all organizers * remove legacy organizer composables
48 lines
962 B
TypeScript
48 lines
962 B
TypeScript
import { reactive, ref, Ref } from "@nuxtjs/composition-api";
|
|
import { useStoreActions } from "../partials/use-actions-factory";
|
|
import { useUserApi } from "~/composables/api";
|
|
import { RecipeCategory } from "~/types/api-types/admin";
|
|
|
|
const categoryStore: Ref<RecipeCategory[]> = ref([]);
|
|
|
|
export function useCategoryData() {
|
|
const data = reactive({
|
|
id: "",
|
|
name: "",
|
|
slug: undefined,
|
|
});
|
|
|
|
function reset() {
|
|
data.id = "";
|
|
data.name = "";
|
|
data.slug = undefined;
|
|
}
|
|
|
|
return {
|
|
data,
|
|
reset,
|
|
};
|
|
}
|
|
|
|
export function useCategoryStore() {
|
|
const api = useUserApi();
|
|
const loading = ref(false);
|
|
|
|
const actions = {
|
|
...useStoreActions<RecipeCategory>(api.categories, categoryStore, loading),
|
|
flushStore() {
|
|
categoryStore.value = [];
|
|
},
|
|
};
|
|
|
|
if (!categoryStore.value || categoryStore.value?.length === 0) {
|
|
actions.getAll();
|
|
}
|
|
|
|
return {
|
|
items: categoryStore,
|
|
actions,
|
|
loading,
|
|
};
|
|
}
|