diff --git a/src/lib/components/RecipeEditor.svelte b/src/lib/components/RecipeEditor.svelte index e1eecc8..cc12717 100644 --- a/src/lib/components/RecipeEditor.svelte +++ b/src/lib/components/RecipeEditor.svelte @@ -2,7 +2,8 @@ import { untrack } from 'svelte'; import { Plus, Trash2, ChevronUp, ChevronDown, ImagePlus, ImageOff } from 'lucide-svelte'; import type { Recipe, Ingredient, Step } from '$lib/types'; - import { alertAction, confirmAction } from '$lib/client/confirm.svelte'; + import { confirmAction } from '$lib/client/confirm.svelte'; + import { asyncFetch } from '$lib/client/api-fetch-wrapper'; import { requireOnline } from '$lib/client/require-online'; type Props = { @@ -48,18 +49,12 @@ try { const fd = new FormData(); fd.append('file', file); - const res = await fetch(`/api/recipes/${recipe.id}/image`, { - method: 'POST', - body: fd - }); - if (!res.ok) { - const body = await res.json().catch(() => ({})); - await alertAction({ - title: 'Upload fehlgeschlagen', - message: body.message ?? `HTTP ${res.status}` - }); - return; - } + const res = await asyncFetch( + `/api/recipes/${recipe.id}/image`, + { method: 'POST', body: fd }, + 'Upload fehlgeschlagen' + ); + if (!res) return; const body = await res.json(); imagePath = body.image_path; onimagechange?.(imagePath); @@ -80,14 +75,12 @@ if (!requireOnline('Das Entfernen')) return; uploading = true; try { - const res = await fetch(`/api/recipes/${recipe.id}/image`, { method: 'DELETE' }); - if (!res.ok) { - await alertAction({ - title: 'Entfernen fehlgeschlagen', - message: `HTTP ${res.status}` - }); - return; - } + const res = await asyncFetch( + `/api/recipes/${recipe.id}/image`, + { method: 'DELETE' }, + 'Entfernen fehlgeschlagen' + ); + if (!res) return; imagePath = null; onimagechange?.(null); } finally {