Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ export const useTimerStore = defineStore('timer', () => {
})

nextPhase()
startTimer()
syncToBackend()
}

function registerSWListener(): void {
Expand Down
45 changes: 40 additions & 5 deletions alfy-bot-frontend/src/features/tasks/ui/TaskDetailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,27 @@
>
{{ formatPomodoro(task.pomodoroCompleted || 0) }}/{{ localPomodoroCount }}
</span>
<span
v-if="timerState !== 'idle'"
class="shrink-0 flex items-center gap-1 text-[11px]"
:class="timerState === 'running' ? 'text-red-500' : 'text-muted-foreground'"
>
<span
class="size-1.5 rounded-full bg-current"
:class="timerState === 'running' && 'animate-pulse motion-reduce:animate-none'"
/>
{{ timerState === 'running' ? 'идёт' : 'пауза' }}
</span>
<Button
v-if="task.isPomodoroTask"
variant="ghost"
size="icon"
class="h-7 w-7 shrink-0"
@click="handleStartTimer"
:aria-label="timerActionLabel"
@click="handleToggleTimer"
>
<Play :size="14" class="text-red-500" />
<Pause v-if="timerState === 'running'" :size="14" class="text-red-500" />
<Play v-else :size="14" class="text-red-500" />
</Button>
<Switch
v-if="effectiveEditable"
Expand Down Expand Up @@ -536,6 +549,7 @@

<script setup lang="ts">
import { ref, computed, watch, nextTick } from 'vue'
import { storeToRefs } from 'pinia'
import { useMediaQuery } from '@vueuse/core'
import {
X,
Expand All @@ -552,6 +566,7 @@ import {
Bell,
Repeat,
Play,
Pause,
} from 'lucide-vue-next'
import { Dialog, DialogContent, DialogClose } from '@/components/ui/dialog'
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from '@/components/ui/drawer'
Expand All @@ -578,7 +593,7 @@ import { getPriorityColor } from '../lib/priority'
import { type DueDateUrgency, getDueDateUrgency } from '../lib/urgency'
import { createChecklistItem, computeChecklistProgress } from '../lib/checklist'
import { countFromDurationMinutes } from '../lib/duration'
import { toTimerTask, useTimerStore } from '@/features/task-timer'
import { getTaskTimerState, toTimerTask, useTimerStore } from '@/features/task-timer'

const URGENCY_CLASSES: Record<DueDateUrgency, string> = {
overdue: 'text-red-500',
Expand Down Expand Up @@ -703,10 +718,30 @@ const localOnMissed = ref<'shift' | 'freeze'>('shift')

// Timer
const timerStore = useTimerStore()
const { activeTaskId, phase, isActive } = storeToRefs(timerStore)

const timerState = computed(() => {
if (!props.task?.isPomodoroTask) return 'idle' as const
return getTaskTimerState(props.task.id, {
activeTaskId: activeTaskId.value,
phase: phase.value,
isActive: isActive.value,
})
})

const timerActionLabel = computed(() => {
if (timerState.value === 'running') return 'Пауза помодоро'
if (timerState.value === 'paused') return 'Продолжить помодоро'
return 'Запустить помодоро'
})

function handleStartTimer() {
function handleToggleTimer() {
if (!props.task?.isPomodoroTask) return
timerStore.startTask(toTimerTask(props.task))
if (timerState.value === 'idle') {
timerStore.startTask(toTimerTask(props.task))
return
}
timerStore.toggleTimer()
}

// Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ describe('timer store — запись помодоро', () => {
vi.mocked(api.delete).mockResolvedValue({ data: {} })
})

it('startTask сразу запускает таймер', () => {
const timer = useTimerStore()

timer.startTask(POMODORO_TASK)

expect(timer.isActive).toBe(true)
expect(timer.phase).toBe(1)
expect(timer.timeBlock).toBeGreaterThan(0)
})

it('завершение рабочей фазы делегирует инкремент в task-store', async () => {
const timer = useTimerStore()
const tasks = useTaskStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,18 @@ describe('currentTaskWidget', () => {
const wrapper = mountWith([activeTask()])
const timer = useTimerStore()
timer.startTask(toTimerTask(activeTask()))
timer.isActive = true
await wrapper.vm.$nextTick()

expect(wrapper.text()).toContain('идёт')
// Кнопки нет намеренно: startTask отмотал бы сессию к первой фазе.
expect(wrapper.find('button').exists()).toBe(false)
})

// startTask только взводит сессию, тикать она начинает отдельно — поэтому
// сразу после клика строка оказывается именно в этом состоянии.
it('взведённая, но не тикающая сессия показывается как пауза и сохраняет кнопку', async () => {
it('пауза сохраняет кнопку «Продолжить»', async () => {
const wrapper = mountWith([activeTask()])
const timer = useTimerStore()
timer.startTask(toTimerTask(activeTask()))
timer.pauseTimer()
await wrapper.vm.$nextTick()

expect(wrapper.text()).toContain('пауза')
Expand All @@ -141,6 +139,7 @@ describe('currentTaskWidget', () => {
const wrapper = mountWith([activeTask()])
const timer = useTimerStore()
timer.startTask(toTimerTask(activeTask()))
timer.pauseTimer()
await wrapper.vm.$nextTick()

const resume = vi.spyOn(timer, 'toggleTimer').mockImplementation(() => {})
Expand Down
Loading