diff --git a/src/pages/Feed.tsx b/src/pages/Feed.tsx index c4e3e4b..15a8e40 100644 --- a/src/pages/Feed.tsx +++ b/src/pages/Feed.tsx @@ -316,8 +316,10 @@ export default function Feed() { )} - {entry.duration_seconds - ? formatDuration(entry.duration_seconds) + {entry.type === "breast" + ? entry.duration_seconds + ? formatDuration(entry.duration_seconds) + : "-" : entry.amount_ml ? `${entry.amount_ml}ml` : "-"} diff --git a/worker/routes/feed.ts b/worker/routes/feed.ts index af4a294..9c61ad7 100644 --- a/worker/routes/feed.ts +++ b/worker/routes/feed.ts @@ -158,19 +158,24 @@ feed.put("/:id", zValidator("json", editSchema), async (c) => { if (body.amount_ml !== undefined) updates.amount_ml = body.amount_ml; if (body.notes !== undefined) updates.notes = body.notes; - // Recalculate duration if times changed (breast feeds) - const startedAt = (updates.started_at as string) ?? entry.started_at; - const endedAt = (updates.ended_at as string) ?? entry.ended_at; - if ( - (body.started_at !== undefined || body.ended_at !== undefined) && - endedAt - ) { - const pauses: Pause[] = JSON.parse(entry.pauses); - updates.duration_seconds = calculateElapsedSeconds( - startedAt, - pauses, - endedAt, - ); + if (entry.type === "breast") { + // Recalculate duration if times changed + const startedAt = (updates.started_at as string) ?? entry.started_at; + const endedAt = (updates.ended_at as string) ?? entry.ended_at; + if ( + (body.started_at !== undefined || body.ended_at !== undefined) && + endedAt + ) { + const pauses: Pause[] = JSON.parse(entry.pauses); + updates.duration_seconds = calculateElapsedSeconds( + startedAt, + pauses, + endedAt, + ); + } + } else if (body.started_at !== undefined) { + // Formula/expressed are instant events — keep ended_at in sync + updates.ended_at = body.started_at; } await repo.update(id, updates);