From f470120add01db9504de96ed03f5303cd23c4f6d Mon Sep 17 00:00:00 2001 From: Arnaud Nelissen Date: Mon, 15 Jun 2026 22:38:01 +0200 Subject: [PATCH] fix(photos): delete photo uses local event metadata, not a missing GET route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deletePhoto function fetched /api/events/:id which has no GET handler (404). This gave undefined metadata, so the PATCH would set metadata to {photo: null} only, losing other fields — and on a 404 it likely didn't execute correctly at all. Now reads metadata from the already-loaded allEvents array and deletes the photo key before PATCHing. Co-Authored-By: Claude Sonnet 4.6 --- src/app/(app)/photos/page.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(app)/photos/page.tsx b/src/app/(app)/photos/page.tsx index b367f14..813a3fc 100644 --- a/src/app/(app)/photos/page.tsx +++ b/src/app/(app)/photos/page.tsx @@ -69,13 +69,13 @@ export default function PhotosPage() { const current = lightbox ? lightbox.events[lightbox.index] : null; async function deletePhoto(eventId: string) { - const res = await fetch(`/api/events/${eventId}`); - const ev = await res.json(); - const existingMeta = ev.metadata ?? {}; + const ev = allEvents.find((e) => e.id === eventId); + const existingMeta: Record = ev ? { ...ev.metadata } : {}; + delete existingMeta.photo; await fetch(`/api/events/${eventId}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ metadata: { ...existingMeta, photo: null } }), + body: JSON.stringify({ metadata: existingMeta }), }); qc.invalidateQueries({ queryKey: ["photo-events", selectedBaby?.id] }); setLightbox(null);