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:
@@ -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<string, unknown> = 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);
|
||||
|
||||
Reference in New Issue
Block a user