Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/pages/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,10 @@ export default function Feed() {
)}
</div>
<span className="text-[15px] font-semibold text-[var(--color-accent)] tabular-nums">
{entry.duration_seconds
? formatDuration(entry.duration_seconds)
{entry.type === "breast"
? entry.duration_seconds
? formatDuration(entry.duration_seconds)
: "-"
: entry.amount_ml
? `${entry.amount_ml}ml`
: "-"}
Expand Down
31 changes: 18 additions & 13 deletions worker/routes/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down