fix(photos): delete photo uses local event metadata, not a missing GET route

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 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 22:38:01 +02:00
parent c28fa8188f
commit f470120add
+4 -4
View File
@@ -69,13 +69,13 @@ export default function PhotosPage() {
const current = lightbox ? lightbox.events[lightbox.index] : null; const current = lightbox ? lightbox.events[lightbox.index] : null;
async function deletePhoto(eventId: string) { async function deletePhoto(eventId: string) {
const res = await fetch(`/api/events/${eventId}`); const ev = allEvents.find((e) => e.id === eventId);
const ev = await res.json(); const existingMeta: Record<string, unknown> = ev ? { ...ev.metadata } : {};
const existingMeta = ev.metadata ?? {}; delete existingMeta.photo;
await fetch(`/api/events/${eventId}`, { await fetch(`/api/events/${eventId}`, {
method: "PATCH", method: "PATCH",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ metadata: { ...existingMeta, photo: null } }), body: JSON.stringify({ metadata: existingMeta }),
}); });
qc.invalidateQueries({ queryKey: ["photo-events", selectedBaby?.id] }); qc.invalidateQueries({ queryKey: ["photo-events", selectedBaby?.id] });
setLightbox(null); setLightbox(null);