Fixed array splitting
This commit is contained in:
@@ -122,7 +122,7 @@
|
|||||||
|
|
||||||
<v-list v-else class="ingredients-list">
|
<v-list v-else class="ingredients-list">
|
||||||
<v-list-item
|
<v-list-item
|
||||||
v-for="(ing, index) in selectedRecipe.ingredients?.split('\n').filter(i => i.trim())"
|
v-for="(ing, index) in (Array.isArray(selectedRecipe.ingredients) ? selectedRecipe.ingredients : selectedRecipe.ingredients?.split('\n') || [])"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="ingredient-item px-0"
|
class="ingredient-item px-0"
|
||||||
>
|
>
|
||||||
@@ -148,7 +148,7 @@
|
|||||||
></v-textarea>
|
></v-textarea>
|
||||||
|
|
||||||
<div v-else
|
<div v-else
|
||||||
v-for="(step, index) in selectedRecipe.instructions?.split('\n').filter(s => s.trim())"
|
v-for="(step, index) in (Array.isArray(selectedRecipe.instructions) ? selectedRecipe.instructions : selectedRecipe.instructions?.split('\n') || [])"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="instruction-step mb-4"
|
class="instruction-step mb-4"
|
||||||
>
|
>
|
||||||
@@ -226,10 +226,19 @@ const openRecipe = (recipe) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const editRecipe = (recipe) => {
|
const editRecipe = (recipe) => {
|
||||||
originalRecipe.value = JSON.parse(JSON.stringify(recipe))
|
const editableRecipe = JSON.parse(JSON.stringify(recipe));
|
||||||
selectedRecipe.value = { ...recipe }
|
|
||||||
isEditing.value = true
|
if (Array.isArray(editableRecipe.ingredients)) {
|
||||||
showDetails.value = true
|
editableRecipe.ingredients = editableRecipe.ingredients.join('\n');
|
||||||
|
}
|
||||||
|
if (Array.isArray(editableRecipe.instructions)) {
|
||||||
|
editableRecipe.instructions = editableRecipe.instructions.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
originalRecipe.value = JSON.parse(JSON.stringify(recipe));
|
||||||
|
selectedRecipe.value = editableRecipe;
|
||||||
|
isEditing.value = true;
|
||||||
|
showDetails.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeDetails = () => {
|
const closeDetails = () => {
|
||||||
@@ -247,17 +256,25 @@ const closeDetails = () => {
|
|||||||
|
|
||||||
const saveChanges = async () => {
|
const saveChanges = async () => {
|
||||||
try {
|
try {
|
||||||
|
const payload = { ...selectedRecipe.value };
|
||||||
|
if (typeof payload.ingredients === 'string') {
|
||||||
|
payload.ingredients = payload.ingredients.split('\n').filter(i => i.trim());
|
||||||
|
}
|
||||||
|
if (typeof payload.instructions === 'string') {
|
||||||
|
payload.instructions = payload.instructions.split('\n').filter(i => i.trim());
|
||||||
|
}
|
||||||
|
|
||||||
await $fetch(`${config.public.apiBase}api/recipe/update/${selectedRecipe.value.id}`, {
|
await $fetch(`${config.public.apiBase}api/recipe/update/${selectedRecipe.value.id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: selectedRecipe.value
|
body: payload
|
||||||
})
|
});
|
||||||
|
|
||||||
await fetchRecipes()
|
await fetchRecipes();
|
||||||
closeDetails()
|
closeDetails();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to update recipe:", e)
|
console.error("Failed to update recipe:", e);
|
||||||
alert("Could not save changes. Your session might have expired.")
|
alert("Could not save changes.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<header class="text-center mb-10">
|
<header class="text-center mb-10">
|
||||||
<div class="brand-icon-container mb-4">
|
<div class="brand-icon-container mb-4">
|
||||||
<v-img
|
<v-img
|
||||||
:src="'/images/seasoned-logo.png'"
|
:src="'/images/seasoned-icon.png'"
|
||||||
alt="Seasoned Logo"
|
alt="Seasoned Logo"
|
||||||
width="120"
|
width="120"
|
||||||
class="mx-auto"
|
class="mx-auto"
|
||||||
|
|||||||
Reference in New Issue
Block a user