mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-27 00:04:23 -04:00
fix: re-ordering of cookbooks (#5975)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import type { Composer } from "vue-i18n";
|
||||
import { useReadOnlyStore, useStore } from "../partials/use-store-factory";
|
||||
import type { ReadCookBook } from "~/lib/api/types/cookbook";
|
||||
import type { ReadCookBook, UpdateCookBook } from "~/lib/api/types/cookbook";
|
||||
import { usePublicExploreApi, useUserApi } from "~/composables/api";
|
||||
|
||||
const store: Ref<ReadCookBook[]> = ref([]);
|
||||
const cookbooks: Ref<ReadCookBook[]> = ref([]);
|
||||
const loading = ref(false);
|
||||
const publicLoading = ref(false);
|
||||
|
||||
export const useCookbookStore = function (i18n?: Composer) {
|
||||
const api = useUserApi(i18n);
|
||||
return useStore<ReadCookBook>(store, loading, api.cookbooks);
|
||||
const store = useStore<ReadCookBook>(cookbooks, loading, api.cookbooks);
|
||||
|
||||
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 };
|
||||
};
|
||||
|
||||
export const usePublicCookbookStore = function (groupSlug: string, i18n?: Composer) {
|
||||
const api = usePublicExploreApi(groupSlug, i18n).explore;
|
||||
return useReadOnlyStore<ReadCookBook>(store, publicLoading, api.cookbooks);
|
||||
return useReadOnlyStore<ReadCookBook>(cookbooks, publicLoading, api.cookbooks);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user