From 98a8022ddfb25b296735dda0f84eb7ddec284568 Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Sun, 19 Apr 2026 11:39:42 +0200 Subject: [PATCH] refactor(editor): Bild-Upload/Delete auf asyncFetch (Item H) RecipeEditor war noch die letzte Stelle im UI, die das handgeschriebene "if (!res.ok) { alertAction(...) }"-Pattern benutzte, welches wir in review-fixes-2026-04-18 ueberall sonst durch asyncFetch() ersetzt hatten. Netto: -14 Zeilen, konsistenter Fehlermessage-Fallback (body.message > res.status), eine Import-Zeile weniger (alertAction raus, asyncFetch rein). Gate: svelte-check clean, 184/184 Tests, Upload/Delete-Flow per Hand zu testen beim naechsten Editor-Touch. Refs docs/superpowers/plans/2026-04-19-post-review-roadmap.md Item H. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lib/components/RecipeEditor.svelte | 35 +++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) 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 {