- 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 <[email protected]>
156 lines
3.7 KiB
Vue
156 lines
3.7 KiB
Vue
<template>
|
|
<div v-if="compact" class="timer-compact">
|
|
<span class="timer-time-compact">{{ display }}</span>
|
|
<span class="timer-label-compact">{{ label }}</span>
|
|
</div>
|
|
<div v-else class="timer-wrap">
|
|
<!-- SVG circular ring -->
|
|
<svg class="timer-ring" viewBox="0 0 200 200">
|
|
<circle cx="100" cy="100" r="88" class="ring-bg" />
|
|
<circle
|
|
cx="100" cy="100" r="88"
|
|
class="ring-fill"
|
|
:style="{ strokeDashoffset: dashOffset, stroke: ringColor }"
|
|
/>
|
|
</svg>
|
|
<div class="timer-inner">
|
|
<div class="timer-time">{{ display }}</div>
|
|
<div class="timer-label">{{ label }}</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, onUnmounted, ref } from 'vue'
|
|
|
|
const props = defineProps({
|
|
block: { type: Object, default: null },
|
|
session: { type: Object, default: null },
|
|
isPaused: { type: Boolean, default: false },
|
|
compact: { type: Boolean, default: false },
|
|
blockStartedAt: { type: Number, default: null }, // ms timestamp, null when paused
|
|
blockElapsedOffset: { type: Number, default: 0 }, // seconds already elapsed
|
|
})
|
|
|
|
// Tick so computed elapsed re-evaluates each second
|
|
const now = ref(Date.now())
|
|
const ticker = setInterval(() => { now.value = Date.now() }, 1000)
|
|
onUnmounted(() => clearInterval(ticker))
|
|
|
|
function parseTime(str) {
|
|
if (!str) return 0
|
|
const [h, m, s = 0] = str.split(':').map(Number)
|
|
return h * 3600 + m * 60 + s
|
|
}
|
|
|
|
const blockDuration = computed(() => {
|
|
if (!props.block) return 0
|
|
if (props.block.duration_minutes != null) return props.block.duration_minutes * 60
|
|
return parseTime(props.block.time_end) - parseTime(props.block.time_start)
|
|
})
|
|
|
|
const elapsed = computed(() => {
|
|
const base = props.blockElapsedOffset
|
|
if (!props.blockStartedAt) return base
|
|
return base + Math.floor((now.value - props.blockStartedAt) / 1000)
|
|
})
|
|
|
|
const remaining = computed(() => Math.max(0, blockDuration.value - elapsed.value))
|
|
|
|
const display = computed(() => {
|
|
const s = blockDuration.value - elapsed.value
|
|
if (s < 0) {
|
|
const abs = Math.abs(s)
|
|
return `-${String(Math.floor(abs / 60)).padStart(2, '0')}:${String(abs % 60).padStart(2, '0')}`
|
|
}
|
|
return `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`
|
|
})
|
|
|
|
const label = computed(() => {
|
|
if (remaining.value === 0) return 'Done!'
|
|
return 'remaining'
|
|
})
|
|
|
|
const CIRCUMFERENCE = 2 * Math.PI * 88
|
|
const dashOffset = computed(() => {
|
|
if (!blockDuration.value) return CIRCUMFERENCE
|
|
const pct = Math.max(0, remaining.value / blockDuration.value)
|
|
return CIRCUMFERENCE * (1 - pct)
|
|
})
|
|
|
|
const ringColor = computed(() => props.block?.subject?.color || '#4f46e5')
|
|
</script>
|
|
|
|
<style scoped>
|
|
.timer-wrap {
|
|
position: relative;
|
|
width: 280px;
|
|
height: 280px;
|
|
}
|
|
|
|
.timer-ring {
|
|
width: 100%;
|
|
height: 100%;
|
|
transform: rotate(-90deg);
|
|
}
|
|
|
|
.ring-bg {
|
|
fill: none;
|
|
stroke: #1e293b;
|
|
stroke-width: 12;
|
|
}
|
|
|
|
.ring-fill {
|
|
fill: none;
|
|
stroke-width: 12;
|
|
stroke-linecap: round;
|
|
stroke-dasharray: 552.92; /* 2π×88 */
|
|
transition: stroke-dashoffset 1s linear, stroke 0.5s;
|
|
}
|
|
|
|
.timer-inner {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.timer-time {
|
|
font-size: 4rem;
|
|
font-weight: 700;
|
|
font-variant-numeric: tabular-nums;
|
|
line-height: 1;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
.timer-label {
|
|
font-size: 0.9rem;
|
|
color: #64748b;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.1em;
|
|
}
|
|
|
|
.timer-compact {
|
|
display: flex;
|
|
align-items: baseline;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.timer-time-compact {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
font-variant-numeric: tabular-nums;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
.timer-label-compact {
|
|
font-size: 0.8rem;
|
|
color: #64748b;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
}
|
|
</style>
|