Tie break timer and main block timer together
- Starting break now pauses the main block timer (frontend optimistic + backend implicit pause event recorded before break_start) - Resuming/starting the main block while break is active pauses the break timer and exits break mode on all clients including TV - Timer display counts negative past zero so overtime is visible while label stays "Done!" - Fixed WS start handler incorrectly skipping break-mode clear when restarting the same block; resume handler now also clears break mode Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -191,18 +191,30 @@ async def timer_action(
|
||||
BREAK_EVENTS = {"break_start", "break_pause", "break_resume", "break_reset"}
|
||||
if body.event_type in BREAK_EVENTS:
|
||||
block_id = body.block_id or session.current_block_id
|
||||
event = TimerEvent(
|
||||
|
||||
# When break starts, implicitly pause the main block timer so elapsed
|
||||
# time is captured accurately in the activity log and on page reload.
|
||||
if body.event_type == "break_start" and block_id:
|
||||
db.add(TimerEvent(
|
||||
session_id=session.id,
|
||||
block_id=block_id,
|
||||
event_type="pause",
|
||||
))
|
||||
|
||||
db.add(TimerEvent(
|
||||
session_id=session.id,
|
||||
block_id=block_id,
|
||||
event_type=body.event_type,
|
||||
)
|
||||
db.add(event)
|
||||
))
|
||||
await db.commit()
|
||||
await db.refresh(session)
|
||||
|
||||
break_elapsed_seconds = 0
|
||||
block_elapsed_seconds = 0
|
||||
if body.event_type in ("break_start", "break_reset") and block_id:
|
||||
break_elapsed_seconds, _ = await compute_break_elapsed(db, session.id, block_id)
|
||||
if body.event_type == "break_start" and block_id:
|
||||
block_elapsed_seconds, _ = await compute_block_elapsed(db, session.id, block_id)
|
||||
|
||||
ws_payload = {
|
||||
"event": body.event_type,
|
||||
@@ -211,6 +223,7 @@ async def timer_action(
|
||||
"current_block_id": session.current_block_id,
|
||||
"is_active": session.is_active,
|
||||
"break_elapsed_seconds": break_elapsed_seconds,
|
||||
"block_elapsed_seconds": block_elapsed_seconds,
|
||||
}
|
||||
await manager.broadcast(session.child_id, ws_payload)
|
||||
return session
|
||||
|
||||
Reference in New Issue
Block a user