mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-03 04:25:24 +02:00
Feature/restore-recipe-functionality (#810)
* feat(frontend): ✨ add back support for assets * feat(backend): ✨ add back support for assets * feat(frontend): ✨ add support for recipe tools * feat(backend): ✨ add support for recipe tools * feat(frontend): ✨ add onHand support for recipe toosl * feat(backend): ✨ add onHand support for backend * refactor(frontend): ♻️ move items to recipe folder and break apart types * feat(frontend): ✨ add support for recipe comments * feat(backend): ✨ Add support for recipe comments * fix(backend): 💥 disable comments import * fix(frontend): 🐛 fix rendering issue with titles when moving steps * add tools to changelog * fix type errors Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
parent
912cc6d956
commit
7afdd5b577
43 changed files with 1221 additions and 423 deletions
|
@ -6,3 +6,4 @@ export { useRecipes, recentRecipes, allRecipes, useLazyRecipes, useSorter } from
|
|||
export { useTags, useCategories, allCategories, allTags } from "./use-tags-categories";
|
||||
export { parseIngredientText } from "./use-recipe-ingredients";
|
||||
export { useRecipeSearch } from "./use-recipe-search";
|
||||
export { useTools } from "./use-recipe-tools";
|
||||
|
|
93
frontend/composables/recipes/use-recipe-tools.ts
Normal file
93
frontend/composables/recipes/use-recipe-tools.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
import { reactive, ref, useAsync } from "@nuxtjs/composition-api";
|
||||
import { useAsyncKey } from "../use-utils";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
|
||||
export const useTools = function (eager = true) {
|
||||
const workingToolData = reactive({
|
||||
id: 0,
|
||||
name: "",
|
||||
onHand: false,
|
||||
});
|
||||
|
||||
const api = useUserApi();
|
||||
const loading = ref(false);
|
||||
const validForm = ref(false);
|
||||
|
||||
const actions = {
|
||||
getAll() {
|
||||
loading.value = true;
|
||||
const units = useAsync(async () => {
|
||||
const { data } = await api.tools.getAll();
|
||||
return data;
|
||||
}, useAsyncKey());
|
||||
|
||||
loading.value = false;
|
||||
return units;
|
||||
},
|
||||
|
||||
async refreshAll() {
|
||||
loading.value = true;
|
||||
const { data } = await api.tools.getAll();
|
||||
|
||||
if (data) {
|
||||
tools.value = data;
|
||||
}
|
||||
|
||||
loading.value = false;
|
||||
},
|
||||
|
||||
async createOne(domForm: VForm | null = null) {
|
||||
if (domForm && !domForm.validate()) {
|
||||
validForm.value = false;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
|
||||
const { data } = await api.tools.createOne(workingToolData);
|
||||
|
||||
if (data) {
|
||||
tools.value?.push(data);
|
||||
}
|
||||
|
||||
domForm?.reset();
|
||||
this.reset();
|
||||
},
|
||||
|
||||
async updateOne() {
|
||||
loading.value = true;
|
||||
const { data } = await api.tools.updateOne(workingToolData.id, workingToolData);
|
||||
if (data) {
|
||||
tools.value?.push(data);
|
||||
}
|
||||
this.reset();
|
||||
},
|
||||
|
||||
async deleteOne(id: number) {
|
||||
loading.value = true;
|
||||
await api.tools.deleteOne(id);
|
||||
this.reset();
|
||||
},
|
||||
|
||||
reset() {
|
||||
workingToolData.name = "";
|
||||
workingToolData.id = 0;
|
||||
loading.value = false;
|
||||
validForm.value = true;
|
||||
},
|
||||
};
|
||||
|
||||
const tools = (() => {
|
||||
if (eager) {
|
||||
return actions.getAll();
|
||||
} else {
|
||||
return ref([]);
|
||||
}
|
||||
})();
|
||||
|
||||
return {
|
||||
tools,
|
||||
actions,
|
||||
workingToolData,
|
||||
loading,
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue