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
3 changes: 3 additions & 0 deletions alfy-bot-frontend/src/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ArrowLeft, Target, PanelLeftOpen } from 'lucide-vue-next'
import { inject, ref, type Ref } from 'vue'
import { useRouter } from 'vue-router'
import { Button } from '@/components/ui/button'
import HeaderTimer from '@/features/task-timer/ui/HeaderTimer.vue'

const props = defineProps<{
title: string
Expand All @@ -13,6 +14,7 @@ const props = defineProps<{

const router = useRouter()
const desktopSidebarCollapsed = inject<Ref<boolean>>('desktopSidebarCollapsed', ref(false))
const taskTimerAvailable = inject('taskTimerAvailable', false)
</script>

<template>
Expand Down Expand Up @@ -49,6 +51,7 @@ const desktopSidebarCollapsed = inject<Ref<boolean>>('desktopSidebarCollapsed',

<!-- right slot -->
<slot name="right" />
<HeaderTimer v-if="taskTimerAvailable" />
</div>
</header>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useStorage } from '@vueuse/core'
import { defineStore } from 'pinia'
import { ref } from 'vue'

/** Хранит локальный режим отображения таймера, не изменяя его сессию. */
export const useTimerDisplayStore = defineStore('timer-display', () => {
const isQuiet = useStorage('alfy:timer:quiet', false)
const isFullscreen = ref(false)

return { isQuiet, isFullscreen }
})
73 changes: 73 additions & 0 deletions alfy-bot-frontend/src/features/task-timer/ui/HeaderTimer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script setup lang="ts">
import { Maximize2, PanelBottom, Pause } from 'lucide-vue-next'
import { computed, ref, watch } from 'vue'
import { Button } from '@/components/ui/button'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { useTimerDisplayStore } from '../model/timer-display-store'
import { useTimerStore } from '../model/timer-store'
import TimerControls from './TimerControls.vue'

const store = useTimerStore()
const display = useTimerDisplayStore()
const isOpen = ref(false)
const isVisible = computed(() => store.phase > 0 && display.isQuiet && !display.isFullscreen)
const time = computed(() => store.formatTime(store.timeBlock))
const status = computed(() => `${store.namePhase}${store.isActive ? '' : ', пауза'}`)

watch(isVisible, () => {
isOpen.value = false
})

function showFullscreen() {
isOpen.value = false
display.isFullscreen = true
}

function showPanel() {
isOpen.value = false
display.isQuiet = false
}
</script>

<template>
<Popover v-if="isVisible" v-model:open="isOpen">
<PopoverTrigger as-child>
<button
type="button"
class="quiet-timer relative flex size-11 shrink-0 cursor-pointer items-center justify-center rounded-full border border-border bg-transparent text-foreground hover:bg-muted/50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
:class="{ 'quiet-timer-work': store.isActive && !store.isBreakPhase, 'quiet-timer-break': store.isActive && store.isBreakPhase }"
:aria-label="`Открыть таймер: ${status}, ${time}`"
:title="`${status} · ${time}`"
>
<span class="font-mono text-[11px] font-medium tabular-nums">{{ time }}</span>
<Pause v-if="!store.isActive" :size="8" class="absolute bottom-1 text-muted-foreground" aria-hidden="true" />
</button>
</PopoverTrigger>
<PopoverContent align="end" :side-offset="8" class="w-60">
<div class="mb-3 flex items-center justify-between gap-3">
<span class="text-sm text-muted-foreground">{{ status }}</span>
<span class="font-mono text-sm tabular-nums">{{ time }}</span>
</div>
<div class="flex items-center justify-between gap-3">
<TimerControls />
<Button type="button" variant="ghost" size="icon" aria-label="Открыть таймер на весь экран" title="На весь экран" @click="showFullscreen">
<Maximize2 :size="16" />
</Button>
</div>
<Button type="button" variant="ghost" class="mt-3 w-full justify-start text-muted-foreground" @click="showPanel">
<PanelBottom :size="16" />
Вернуть нижнюю панель
</Button>
</PopoverContent>
</Popover>
</template>

<style scoped>
.quiet-timer-work {
border-color: oklch(0.65 0.045 25 / 0.65);
}

.quiet-timer-break {
border-color: oklch(0.65 0.035 250 / 0.65);
}
</style>
75 changes: 43 additions & 32 deletions alfy-bot-frontend/src/features/task-timer/ui/TimeBlock.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { Pause, Play, Square } from 'lucide-vue-next'
import { computed, onMounted, onUnmounted, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { Maximize2, Minimize2, PanelTop } from 'lucide-vue-next'
import { Button } from '@/components/ui/button'
import { useSse } from '@/composables/useSse'
import { useTimerStore } from '../model/timer-store'
import { useTimerDisplayStore } from '../model/timer-display-store'
import TimerControls from './TimerControls.vue'

const store = useTimerStore()
const isFullscreen = ref(false)
const display = useTimerDisplayStore()
const { isFullscreen } = storeToRefs(display)
let wakeLock: WakeLockSentinel | null = null

const formattedTime = computed(() => {
Expand Down Expand Up @@ -41,7 +45,7 @@ watch(
(shouldLock) => shouldLock ? requestWakeLock() : releaseWakeLock()
)

document.addEventListener('visibilitychange', async () => {
const handleVisibilityChange = async () => {
if (document.visibilityState === 'visible') {
if (store.phase > 0) {
store.recalcTimeBlock()
Expand All @@ -51,9 +55,10 @@ document.addEventListener('visibilitychange', async () => {
await requestWakeLock()
}
}
})
}

onMounted(() => {
document.addEventListener('visibilitychange', handleVisibilityChange)
store.restoreSession()
})

Expand All @@ -63,6 +68,8 @@ useSse('/events', (event) => {
})

onUnmounted(() => {
document.removeEventListener('visibilitychange', handleVisibilityChange)
isFullscreen.value = false
releaseWakeLock()
})
</script>
Expand All @@ -75,27 +82,35 @@ onUnmounted(() => {
leave-to-class="timer-leave-to"
>
<div
v-if="store.phase > 0"
v-if="store.phase > 0 && (!display.isQuiet || isFullscreen)"
:class="[
'timer-block z-[1000] pointer-events-auto',
timerColorClass,
isFullscreen ? 'timer-fullscreen' : 'timer-compact group'
]"
>
<button
<Button
v-if="!isFullscreen"
@click="toggleFullscreen"
class="absolute top-[5px] left-[5px] z-10 w-5 h-5 bg-muted rounded cursor-pointer transition-all duration-200 opacity-0 group-hover:opacity-100 hover:bg-muted-foreground/20 flex items-center justify-center"
type="button"
variant="ghost"
size="icon"
aria-label="Свернуть таймер в шапку"
title="Свернуть в шапку"
@click="display.isQuiet = true"
>
<span class="text-muted-foreground text-[10px] leading-none">□</span>
</button>
<button
<PanelTop :size="16" />
</Button>
<Button
v-if="isFullscreen"
type="button"
variant="ghost"
size="icon"
aria-label="Выйти из полноэкранного таймера"
@click="toggleFullscreen"
class="absolute z-10 top-4 left-4 text-white hover:opacity-70 cursor-pointer transition-all duration-200"
class="absolute z-10 top-4 left-4 text-white"
>
−
</button>
<Minimize2 :size="20" />
</Button>

<div v-if="isFullscreen" class="phase-name">{{ store.namePhase }}</div>

Expand All @@ -115,21 +130,17 @@ onUnmounted(() => {
</div>

<div class="flex gap-2 items-center">
<TimerControls />
<Button
@click="store.toggleTimer"
variant="outline"
size="icon"
>
<Play v-if="!store.isActive" :size="16" />
<Pause v-else :size="16" />
</Button>
<Button
v-if="store.phase > 0"
@click="store.isActive || !store.isStartTimeBlock() ? store.stopTimeBlock(true) : store.resetToInitialState()"
variant="outline"
v-if="!isFullscreen"
type="button"
variant="ghost"
size="icon"
aria-label="Открыть таймер на весь экран"
title="На весь экран"
@click="toggleFullscreen"
>
<Square :size="16" />
<Maximize2 :size="16" />
</Button>
</div>
</div>
Expand Down Expand Up @@ -185,12 +196,12 @@ onUnmounted(() => {

/* Light */
.timer-work.timer-compact {
background-color: oklch(0.95 0.03 25);
border-color: oklch(0.88 0.05 25);
background-color: oklch(0.97 0.008 25);
border-color: oklch(0.88 0.02 25);
}

.timer-work.timer-fullscreen {
background-color: oklch(0.18 0.06 25 / 0.96);
background-color: oklch(0.18 0.012 25 / 0.96);
}

/* ── Break phase — soft blue ── */
Expand All @@ -207,8 +218,8 @@ onUnmounted(() => {

/* ── Dark mode overrides ── */
.dark .timer-work.timer-compact {
background-color: oklch(0.25 0.06 25);
border-color: oklch(0.35 0.08 25);
background-color: oklch(0.22 0.012 25);
border-color: oklch(0.35 0.025 25);
}

.dark .timer-break.timer-compact {
Expand Down
34 changes: 34 additions & 0 deletions alfy-bot-frontend/src/features/task-timer/ui/TimerControls.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup lang="ts">
import { Pause, Play, Square } from 'lucide-vue-next'
import { Button } from '@/components/ui/button'
import { useTimerStore } from '../model/timer-store'

const store = useTimerStore()
</script>

<template>
<div class="flex gap-2 items-center">
<Button
type="button"
variant="outline"
size="icon"
:aria-label="store.isActive ? 'Приостановить таймер' : 'Продолжить таймер'"
:title="store.isActive ? 'Приостановить таймер' : 'Продолжить таймер'"
@click="store.toggleTimer"
>
<Play v-if="!store.isActive" :size="16" />
<Pause v-else :size="16" />
</Button>
<Button
v-if="store.phase > 0"
type="button"
variant="outline"
size="icon"
aria-label="Завершить интервал"
title="Завершить интервал"
@click="store.isActive || !store.isStartTimeBlock() ? store.stopTimeBlock(true) : store.resetToInitialState()"
>
<Square :size="16" />
</Button>
</div>
</template>
3 changes: 2 additions & 1 deletion alfy-bot-frontend/src/views/TasksLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { onMounted, provide } from 'vue'
import { useProjectStore } from '@/features/projects/model/project-store'
import { TimeBlock } from '@/features/task-timer'

const projectStore = useProjectStore()
provide('taskTimerAvailable', true)

onMounted(() => {
if (projectStore.projects.length === 0) {
Expand Down
Loading
Loading