mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-04 21:15:22 +02:00
feat: Filter Recipes By Household (and a ton of bug fixes) (#4207)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
2a6922a85c
commit
7c274de778
65 changed files with 896 additions and 590 deletions
|
@ -1,73 +1,28 @@
|
|||
import { ref, reactive, Ref } from "@nuxtjs/composition-api";
|
||||
import { usePublicStoreActions, useStoreActions } from "../partials/use-actions-factory";
|
||||
import { usePublicExploreApi } from "../api/api-client";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import { ref, Ref } from "@nuxtjs/composition-api";
|
||||
import { useData, useReadOnlyStore, useStore } from "../partials/use-store-factory";
|
||||
import { IngredientFood } from "~/lib/api/types/recipe";
|
||||
import { usePublicExploreApi, useUserApi } from "~/composables/api";
|
||||
|
||||
let foodStore: Ref<IngredientFood[] | null> = ref([]);
|
||||
const publicStoreLoading = ref(false);
|
||||
const storeLoading = ref(false);
|
||||
const store: Ref<IngredientFood[]> = ref([]);
|
||||
const loading = ref(false);
|
||||
const publicLoading = ref(false);
|
||||
|
||||
/**
|
||||
* useFoodData returns a template reactive object
|
||||
* for managing the creation of foods. It also provides a
|
||||
* function to reset the data back to the initial state.
|
||||
*/
|
||||
export const useFoodData = function () {
|
||||
const data: IngredientFood = reactive({
|
||||
return useData<IngredientFood>({
|
||||
id: "",
|
||||
name: "",
|
||||
description: "",
|
||||
labelId: undefined,
|
||||
onHand: false,
|
||||
});
|
||||
|
||||
function reset() {
|
||||
data.id = "";
|
||||
data.name = "";
|
||||
data.description = "";
|
||||
data.labelId = undefined;
|
||||
data.onHand = false;
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
reset,
|
||||
};
|
||||
};
|
||||
|
||||
export const usePublicFoodStore = function (groupSlug: string) {
|
||||
const api = usePublicExploreApi(groupSlug).explore;
|
||||
const loading = publicStoreLoading;
|
||||
|
||||
const actions = {
|
||||
...usePublicStoreActions(api.foods, foodStore, loading),
|
||||
flushStore() {
|
||||
foodStore = ref([]);
|
||||
},
|
||||
};
|
||||
|
||||
if (!loading.value && (!foodStore.value || foodStore.value.length === 0)) {
|
||||
foodStore = actions.getAll();
|
||||
}
|
||||
|
||||
return { foods: foodStore, actions };
|
||||
};
|
||||
}
|
||||
|
||||
export const useFoodStore = function () {
|
||||
const api = useUserApi();
|
||||
const loading = storeLoading;
|
||||
return useStore<IngredientFood>(store, loading, api.foods);
|
||||
}
|
||||
|
||||
const actions = {
|
||||
...useStoreActions(api.foods, foodStore, loading),
|
||||
flushStore() {
|
||||
foodStore.value = [];
|
||||
},
|
||||
};
|
||||
|
||||
if (!loading.value && (!foodStore.value || foodStore.value.length === 0)) {
|
||||
foodStore = actions.getAll();
|
||||
}
|
||||
|
||||
return { foods: foodStore, actions };
|
||||
};
|
||||
export const usePublicFoodStore = function (groupSlug: string) {
|
||||
const api = usePublicExploreApi(groupSlug).explore;
|
||||
return useReadOnlyStore<IngredientFood>(store, publicLoading, api.foods);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue