Preserve elapsed time when switching between schedule blocks
Previously, clicking a different block always fired 'start' which reset elapsed to zero — returning to a block lost all accumulated time. Store changes: - Add blockElapsedCache (blockId → elapsed seconds) that persists across block switches within a session - On 'pause' WS event: write the block's total elapsed into the cache - On 'start' WS event: restore elapsed from cache (0 if never worked) - On applySnapshot: seed cache with server-computed elapsed for the current block (so reloading preserves state correctly) - Clear cache when the session ends Dashboard selectBlock changes: - Auto-pause the currently running block before switching to another - Clicking the active block while paused now sends 'resume' instead of doing nothing - Clicking the already-running active block is a no-op Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -217,10 +217,25 @@ async function sendAction(type) {
|
||||
await scheduleStore.sendTimerAction(scheduleStore.session.id, type)
|
||||
}
|
||||
|
||||
function selectBlock(block) {
|
||||
async function selectBlock(block) {
|
||||
if (!scheduleStore.session) return
|
||||
scheduleStore.session.current_block_id = block.id
|
||||
scheduleStore.isPaused = false
|
||||
|
||||
const currentId = scheduleStore.session.current_block_id
|
||||
|
||||
// Clicking the current block while paused → resume it
|
||||
if (block.id === currentId && scheduleStore.isPaused) {
|
||||
scheduleStore.sendTimerAction(scheduleStore.session.id, 'resume')
|
||||
return
|
||||
}
|
||||
|
||||
// Clicking the current block while running → do nothing
|
||||
if (block.id === currentId) return
|
||||
|
||||
// Switching to a different block — pause the current one first if it's running
|
||||
if (currentId && !scheduleStore.isPaused) {
|
||||
await scheduleStore.sendTimerAction(scheduleStore.session.id, 'pause', currentId)
|
||||
}
|
||||
|
||||
scheduleStore.sendTimerAction(scheduleStore.session.id, 'start', block.id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user