Add stopwatch tab to Timer widget
Deploy with Docker Compose / deploy (push) Successful in 52s
Weekly Maintenance / maintenance (push) Successful in 3m40s

Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
2026-09-23 16:28:24 +01:00
co-authored by Claude Code
parent ac8b3dadf3
commit 6dcb6b1384
+49 -4
View File
@@ -12,8 +12,35 @@ import Header from "@/components/text/Header.vue";
import { ref, onUnmounted } from "vue";
/** Which widget is showing — countdown timer or stopwatch. */
const tab = ref("timer");
const timer = ref(null);
// --- Stopwatch ---
// Same interval-tick pattern as the countdown, but counts up with no target.
const stopwatchInterval = ref(null);
const stopwatchRunning = ref(false);
const stopwatchMs = ref(0);
function stopwatchTick() {
stopwatchMs.value += 1000;
}
function toggleStopwatch() {
stopwatchRunning.value = !stopwatchRunning.value;
if (stopwatchRunning.value) {
stopwatchInterval.value = setInterval(stopwatchTick, 1000);
} else {
clearInterval(stopwatchInterval.value);
}
}
function resetStopwatch() {
clearInterval(stopwatchInterval.value);
stopwatchRunning.value = false;
stopwatchMs.value = 0;
}
/** "idle" | "running" | "paused" | "finished" */
const state = ref("idle");
@@ -69,6 +96,7 @@ function resetTimer() {
onUnmounted(() => {
clearInterval(timer.value);
clearInterval(stopwatchInterval.value);
});
function playFinishedSound() {
@@ -79,7 +107,24 @@ function playFinishedSound() {
<template>
<div class="timer-root flex flex-col gap-1 p-1 items-center">
<Header>Timer</Header>
<div v-if="state === 'idle'" class="flex flex-col">
<div class="flex gap-1">
<Button @click="tab = 'timer'">Timer</Button>
<Button @click="tab = 'stopwatch'">Stopwatch</Button>
</div>
<div v-if="tab === 'stopwatch'" class="flex flex-col">
<p>
{{ Math.floor(stopwatchMs / 60000).toString().padStart(2, "0") }}:{{
Math.floor((stopwatchMs % 60000) / 1000)
.toString()
.padStart(2, "0")
}}
</p>
<Button @click="toggleStopwatch">
{{ stopwatchRunning ? "Pause" : "Start" }}
</Button>
<Button @click="resetStopwatch">Reset</Button>
</div>
<div v-else-if="state === 'idle'" class="flex flex-col">
<div class="flex flex-row p-2 place-content-around">
<input
class="w-2/3"
@@ -104,11 +149,11 @@ function playFinishedSound() {
</div>
<Button @click="startTimer">Proceed</Button>
</div>
<div v-if="state === 'finished'" class="flex flex-col">
<div v-else-if="state === 'finished'" class="flex flex-col">
<h1>Timer finished!</h1>
<Button @click="resetTimer">Reset</Button>
</div>
<div v-if="state === 'paused'" class="flex flex-col">
<div v-else-if="state === 'paused'" class="flex flex-col">
<h1>Paused</h1>
<p>
{{ minutes.toString().padStart(2, "0") }}:{{
@@ -118,7 +163,7 @@ function playFinishedSound() {
<Button @click="pauseTimer">Resume</Button>
<Button @click="resetTimer">Reset</Button>
</div>
<div v-if="state === 'running'" class="flex flex-col">
<div v-else-if="state === 'running'" class="flex flex-col">
<p>
{{ minutes.toString().padStart(2, "0") }}:{{
seconds.toString().padStart(2, "0")