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);