2025-07-08 08:32:18 -05:00
|
|
|
import type { Composer } from "vue-i18n";
|
2025-06-24 02:36:40 -05:00
|
|
|
import { useReadOnlyStore, useStore } from "../partials/use-store-factory";
|
2025-08-29 23:50:09 +02:00
|
|
|
import type { ReadCookBook, UpdateCookBook } from "~/lib/api/types/cookbook";
|
2025-06-24 02:36:40 -05:00
|
|
|
import { usePublicExploreApi, useUserApi } from "~/composables/api";
|
|
|
|
|
|
2025-08-29 23:50:09 +02:00
|
|
|
const cookbooks: Ref<ReadCookBook[]> = ref([]);
|
2025-06-24 02:36:40 -05:00
|
|
|
const loading = ref(false);
|
|
|
|
|
const publicLoading = ref(false);
|
|
|
|
|
|
2025-07-08 08:32:18 -05:00
|
|
|
export const useCookbookStore = function (i18n?: Composer) {
|
|
|
|
|
const api = useUserApi(i18n);
|
2025-09-27 19:17:08 -05:00
|
|
|
const store = useStore<ReadCookBook>("cookbook", cookbooks, loading, api.cookbooks);
|
2025-08-29 23:50:09 +02:00
|
|
|
|
|
|
|
|
const updateAll = async function (updateData: UpdateCookBook[]) {
|
|
|
|
|
loading.value = true;
|
|
|
|
|
updateData.forEach((cookbook, index) => {
|
|
|
|
|
cookbook.position = index;
|
|
|
|
|
});
|
|
|
|
|
const { data } = await api.cookbooks.updateAll(updateData);
|
|
|
|
|
loading.value = false;
|
|
|
|
|
return data;
|
|
|
|
|
};
|
|
|
|
|
return { ...store, updateAll };
|
2025-06-24 02:36:40 -05:00
|
|
|
};
|
|
|
|
|
|
2025-07-08 08:32:18 -05:00
|
|
|
export const usePublicCookbookStore = function (groupSlug: string, i18n?: Composer) {
|
|
|
|
|
const api = usePublicExploreApi(groupSlug, i18n).explore;
|
2025-09-27 19:17:08 -05:00
|
|
|
return useReadOnlyStore<ReadCookBook>("cookbook", cookbooks, publicLoading, api.cookbooks);
|
2025-06-24 02:36:40 -05:00
|
|
|
};
|