Fix day progress missing on TV dashboard after session start

The WS broadcast payload was missing day_start_time, day_end_time, and
duration_minutes, so applySnapshot nulled them out on session_update.
Now _broadcast_session fetches the template and includes all fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 10:30:50 -08:00
parent 23aaea462d
commit 1042c20fbb

View File

@@ -18,17 +18,36 @@ router = APIRouter(prefix="/api/sessions", tags=["sessions"])
async def _broadcast_session(db: AsyncSession, session: DailySession) -> None: async def _broadcast_session(db: AsyncSession, session: DailySession) -> None:
"""Build a snapshot dict and broadcast it to all connected TVs for this child.""" """Build a snapshot dict and broadcast it to all connected TVs for this child."""
# Load template blocks if available
blocks = [] blocks = []
day_start_time = None
day_end_time = None
if session.template_id: if session.template_id:
result = await db.execute( blocks_result = await db.execute(
select(ScheduleBlock) select(ScheduleBlock)
.where(ScheduleBlock.template_id == session.template_id) .where(ScheduleBlock.template_id == session.template_id)
.order_by(ScheduleBlock.order_index) .order_by(ScheduleBlock.order_index)
) )
blocks = [{"id": b.id, "subject_id": b.subject_id, "time_start": str(b.time_start), blocks = [
"time_end": str(b.time_end), "label": b.label, "order_index": b.order_index} {
for b in result.scalars().all()] "id": b.id,
"subject_id": b.subject_id,
"time_start": str(b.time_start),
"time_end": str(b.time_end),
"duration_minutes": b.duration_minutes,
"label": b.label,
"order_index": b.order_index,
}
for b in blocks_result.scalars().all()
]
template_result = await db.execute(
select(ScheduleTemplate).where(ScheduleTemplate.id == session.template_id)
)
template = template_result.scalar_one_or_none()
if template:
day_start_time = str(template.day_start_time) if template.day_start_time else None
day_end_time = str(template.day_end_time) if template.day_end_time else None
# Gather completed block IDs from timer events # Gather completed block IDs from timer events
events_result = await db.execute( events_result = await db.execute(
@@ -50,6 +69,8 @@ async def _broadcast_session(db: AsyncSession, session: DailySession) -> None:
}, },
"blocks": blocks, "blocks": blocks,
"completed_block_ids": completed_ids, "completed_block_ids": completed_ids,
"day_start_time": day_start_time,
"day_end_time": day_end_time,
} }
await manager.broadcast(session.child_id, payload) await manager.broadcast(session.child_id, payload)