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:
@@ -18,17 +18,36 @@ router = APIRouter(prefix="/api/sessions", tags=["sessions"])
|
||||
|
||||
async def _broadcast_session(db: AsyncSession, session: DailySession) -> None:
|
||||
"""Build a snapshot dict and broadcast it to all connected TVs for this child."""
|
||||
# Load template blocks if available
|
||||
blocks = []
|
||||
day_start_time = None
|
||||
day_end_time = None
|
||||
|
||||
if session.template_id:
|
||||
result = await db.execute(
|
||||
blocks_result = await db.execute(
|
||||
select(ScheduleBlock)
|
||||
.where(ScheduleBlock.template_id == session.template_id)
|
||||
.order_by(ScheduleBlock.order_index)
|
||||
)
|
||||
blocks = [{"id": b.id, "subject_id": b.subject_id, "time_start": str(b.time_start),
|
||||
"time_end": str(b.time_end), "label": b.label, "order_index": b.order_index}
|
||||
for b in result.scalars().all()]
|
||||
blocks = [
|
||||
{
|
||||
"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
|
||||
events_result = await db.execute(
|
||||
@@ -50,6 +69,8 @@ async def _broadcast_session(db: AsyncSession, session: DailySession) -> None:
|
||||
},
|
||||
"blocks": blocks,
|
||||
"completed_block_ids": completed_ids,
|
||||
"day_start_time": day_start_time,
|
||||
"day_end_time": day_end_time,
|
||||
}
|
||||
await manager.broadcast(session.child_id, payload)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user