mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 15:49:42 +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
53
frontend/composables/partials/use-store-factory.ts
Normal file
53
frontend/composables/partials/use-store-factory.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { ref, reactive, Ref } from "@nuxtjs/composition-api";
|
||||
import { useReadOnlyActions, useStoreActions } from "./use-actions-factory";
|
||||
import { BoundT } from "./types";
|
||||
import { BaseCRUDAPI, BaseCRUDAPIReadOnly } from "~/lib/api/base/base-clients";
|
||||
|
||||
export const useData = function<T extends BoundT>(defaultObject: T) {
|
||||
const data = reactive({ ...defaultObject });
|
||||
function reset() {
|
||||
Object.assign(data, defaultObject);
|
||||
};
|
||||
|
||||
return { data, reset };
|
||||
}
|
||||
|
||||
export const useReadOnlyStore = function<T extends BoundT>(
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
api: BaseCRUDAPIReadOnly<T>,
|
||||
) {
|
||||
const actions = {
|
||||
...useReadOnlyActions(api, store, loading),
|
||||
flushStore() {
|
||||
store.value = [];
|
||||
},
|
||||
};
|
||||
|
||||
if (!loading.value && (!store.value || store.value.length === 0)) {
|
||||
const result = actions.getAll();
|
||||
store.value = result.value || [];
|
||||
}
|
||||
|
||||
return { store, actions };
|
||||
}
|
||||
|
||||
export const useStore = function<T extends BoundT>(
|
||||
store: Ref<T[]>,
|
||||
loading: Ref<boolean>,
|
||||
api: BaseCRUDAPI<unknown, T, unknown>,
|
||||
) {
|
||||
const actions = {
|
||||
...useStoreActions(api, store, loading),
|
||||
flushStore() {
|
||||
store = ref([]);
|
||||
},
|
||||
};
|
||||
|
||||
if (!loading.value && (!store.value || store.value.length === 0)) {
|
||||
const result = actions.getAll();
|
||||
store.value = result.value || [];
|
||||
}
|
||||
|
||||
return { store, actions };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue