Show timer remaining per block and fix single-click block switching
- Block list on both dashboards now shows time remaining on each block's timer (allocated duration minus elapsed) instead of total duration; the active block counts down live every second - Fix block switching requiring 2 clicks: replace separate pause+start requests with a single start request; backend implicitly records a pause event for the previous block atomically - Export blockElapsedCache from store so views can compute per-block elapsed for both running and paused blocks Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ const props = defineProps({
|
||||
isCurrent: { type: Boolean, default: false },
|
||||
isCompleted: { type: Boolean, default: false },
|
||||
compact: { type: Boolean, default: false },
|
||||
elapsedSeconds: { type: Number, default: 0 },
|
||||
})
|
||||
|
||||
function formatTime(str) {
|
||||
@@ -46,17 +47,30 @@ function formatTime(str) {
|
||||
const subjectColor = computed(() => props.block.subject?.color || '#475569')
|
||||
const subjectName = computed(() => props.block.subject?.name || null)
|
||||
|
||||
const durationLabel = computed(() => {
|
||||
if (props.block.duration_minutes != null) return `${props.block.duration_minutes} min`
|
||||
function blockTotalSeconds() {
|
||||
if (props.block.duration_minutes != null) return props.block.duration_minutes * 60
|
||||
const start = props.block.time_start
|
||||
const end = props.block.time_end
|
||||
if (start && end) {
|
||||
const [sh, sm] = start.split(':').map(Number)
|
||||
const [eh, em] = end.split(':').map(Number)
|
||||
const mins = (eh * 60 + em) - (sh * 60 + sm)
|
||||
if (mins > 0) return `${mins} min`
|
||||
return ((eh * 60 + em) - (sh * 60 + sm)) * 60
|
||||
}
|
||||
return ''
|
||||
return 0
|
||||
}
|
||||
|
||||
const durationLabel = computed(() => {
|
||||
const totalSec = blockTotalSeconds()
|
||||
if (totalSec <= 0) return ''
|
||||
const remSec = Math.max(0, totalSec - props.elapsedSeconds)
|
||||
const remMin = Math.floor(remSec / 60)
|
||||
if (remMin <= 0) return '0 min'
|
||||
if (remMin >= 60) {
|
||||
const h = Math.floor(remMin / 60)
|
||||
const m = remMin % 60
|
||||
return m === 0 ? `${h}h` : `${h}h ${m}m`
|
||||
}
|
||||
return `${remMin} min`
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user