mealie/frontend/composables/use-recipe-context.ts
Hayden 40462a95f1
fix(frontend): 🐛 fix section titles carrying over on deleted items (#765)
* fix(frontend): 🐛 fix section titles carrying over on deleted items

Added a UUID generator to generate unique id's and prevent list changes from causing proper virtual dom re-renders.

* lazy load json editor

* fix ingredient rendering error

* move text to input

* update settings styling

* improve mobile view

Co-authored-by: Hayden <hay-kot@pm.me>
2021-10-31 14:46:46 -08:00

44 lines
1.1 KiB
TypeScript

import { useAsync, ref } from "@nuxtjs/composition-api";
import { useApiSingleton } from "~/composables/use-api";
import { Recipe } from "~/types/api-types/recipe";
export const useRecipeContext = function () {
const api = useApiSingleton();
const loading = ref(false);
function getBySlug(slug: string) {
loading.value = true;
const recipe = useAsync(async () => {
const { data } = await api.recipes.getOne(slug);
return data;
}, slug);
loading.value = false;
return recipe;
}
async function fetchRecipe(slug: string) {
loading.value = true;
const { data } = await api.recipes.getOne(slug);
loading.value = false;
return data;
}
async function deleteRecipe(slug: string) {
loading.value = true;
const { data } = await api.recipes.deleteOne(slug);
loading.value = false;
return data;
}
async function updateRecipe(slug: string, recipe: Recipe) {
loading.value = true;
const { data } = await api.recipes.updateOne(slug, recipe);
loading.value = false;
return data;
}
return { loading, getBySlug, deleteRecipe, updateRecipe, fetchRecipe };
};