2025-07-08 08:32:18 -05:00
|
|
|
import type { Composer } from "vue-i18n";
|
2024-09-22 09:59:20 -05:00
|
|
|
import { useData, useReadOnlyStore, useStore } from "../partials/use-store-factory";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { RecipeCategory } from "~/lib/api/types/recipe";
|
2024-09-22 09:59:20 -05:00
|
|
|
import { usePublicExploreApi, useUserApi } from "~/composables/api";
|
2022-06-03 20:12:32 -08:00
|
|
|
|
2024-09-22 09:59:20 -05:00
|
|
|
const store: Ref<RecipeCategory[]> = ref([]);
|
|
|
|
const loading = ref(false);
|
|
|
|
const publicLoading = ref(false);
|
2022-06-03 20:12:32 -08:00
|
|
|
|
2024-09-22 09:59:20 -05:00
|
|
|
export const useCategoryData = function () {
|
|
|
|
return useData<RecipeCategory>({
|
2022-06-03 20:12:32 -08:00
|
|
|
id: "",
|
|
|
|
name: "",
|
2024-09-22 09:59:20 -05:00
|
|
|
slug: "",
|
2022-06-03 20:12:32 -08:00
|
|
|
});
|
2025-06-20 00:09:12 +07:00
|
|
|
};
|
2023-09-14 09:01:24 -05:00
|
|
|
|
2025-07-08 08:32:18 -05:00
|
|
|
export const useCategoryStore = function (i18n?: Composer) {
|
|
|
|
const api = useUserApi(i18n);
|
2024-09-22 09:59:20 -05:00
|
|
|
return useStore<RecipeCategory>(store, loading, api.categories);
|
2025-06-20 00:09:12 +07:00
|
|
|
};
|
2022-06-03 20:12:32 -08:00
|
|
|
|
2025-07-08 08:32:18 -05:00
|
|
|
export const usePublicCategoryStore = function (groupSlug: string, i18n?: Composer) {
|
|
|
|
const api = usePublicExploreApi(groupSlug, i18n).explore;
|
2024-09-22 09:59:20 -05:00
|
|
|
return useReadOnlyStore<RecipeCategory>(store, publicLoading, api.categories);
|
2025-06-20 00:09:12 +07:00
|
|
|
};
|