feat(time-tracking) : add pending complete entry flow and redesign sidebar timer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 23:19:58 +01:00
parent d4c5660ba6
commit 7484ce3e45
3 changed files with 91 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ import { useTimeEntryService } from '~/services/time-entries'
export const useTimerStore = defineStore('timer', () => {
const activeEntry = ref<TimeEntry | null>(null)
const pendingCompleteEntry = ref<TimeEntry | null>(null)
const now = ref(Date.now())
let intervalId: ReturnType<typeof setInterval> | null = null
@@ -78,9 +79,11 @@ export const useTimerStore = defineStore('timer', () => {
startedAt: new Date().toISOString(),
user: `/api/users/${authStore.user.id}`,
title: task.title,
project: task.project?.['@id'] ?? `/api/projects/${task.project?.id}`,
task: task['@id'] ?? `/api/tasks/${task.id}`,
types: task.types.map((t) => t['@id'] ?? `/api/task_types/${t.id}`),
project: task.project
? (typeof task.project === 'string' ? task.project : (task.project['@id'] ?? (task.project.id ? `/api/projects/${task.project.id}` : null)))
: null,
task: typeof task === 'string' ? task : (task['@id'] ?? `/api/tasks/${task.id}`),
types: task.types?.map((t) => typeof t === 'string' ? t : (t['@id'] ?? `/api/task_types/${t.id}`)) ?? [],
})
startTicking()
}
@@ -88,16 +91,27 @@ export const useTimerStore = defineStore('timer', () => {
async function stop() {
if (!activeEntry.value) return
const wasEmpty = !activeEntry.value.task
const { update } = useTimeEntryService()
await update(activeEntry.value.id, {
const stoppedEntry = await update(activeEntry.value.id, {
stoppedAt: new Date().toISOString(),
})
activeEntry.value = null
stopTicking()
if (wasEmpty) {
pendingCompleteEntry.value = stoppedEntry
}
}
function clearPendingEntry() {
pendingCompleteEntry.value = null
}
return {
activeEntry,
pendingCompleteEntry,
isRunning,
elapsed,
elapsedFormatted,
@@ -105,5 +119,6 @@ export const useTimerStore = defineStore('timer', () => {
start,
startFromTask,
stop,
clearPendingEntry,
}
})