From 887c0bc6f968f80ac90220f24bb578438e05708a Mon Sep 17 00:00:00 2001 From: Solstice Date: Tue, 9 Jun 2026 01:10:46 -0700 Subject: fix: resolve final release blockers --- src/store/audioStore.ts | 14 +++++--------- src/store/taskStore.ts | 7 +++++++ src/store/timerStore.ts | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) (limited to 'src/store') diff --git a/src/store/audioStore.ts b/src/store/audioStore.ts index 39cbf8b..36d593d 100644 --- a/src/store/audioStore.ts +++ b/src/store/audioStore.ts @@ -53,15 +53,15 @@ export const useAudioStore = create((set, get) => ({ try { if (sound === 'none') { await invoke('stop_ambient'); - set({ playing: false, sound: 'none' }); + await get().fetchStatus(); return; } await invoke('play_ambient', { sound }); - set({ available: true, playing: true, sound }); + await get().fetchStatus(); } catch (error) { console.error('play_ambient error:', error); - set({ available: false, playing: false, sound: 'none' }); + await get().fetchStatus(); } }, @@ -71,14 +71,10 @@ export const useAudioStore = create((set, get) => ({ try { await invoke('set_ambient_volume', { volume: nextVolume }); - set({ available: true }); + await get().fetchStatus(); } catch (error) { console.error('set_ambient_volume error:', error); - set({ - available: false, - playing: false, - sound: get().sound, - }); + await get().fetchStatus(); } }, })); diff --git a/src/store/taskStore.ts b/src/store/taskStore.ts index 94386ac..2a3a8be 100644 --- a/src/store/taskStore.ts +++ b/src/store/taskStore.ts @@ -1,5 +1,6 @@ import { create } from 'zustand'; import { invoke } from '@tauri-apps/api/core'; +import { useTimerStore } from './timerStore'; export interface Task { id: string; @@ -79,5 +80,11 @@ export const useTaskStore = create((set) => ({ setCurrentTask: async (id) => { await invoke('set_current_task', { taskId: id }); + useTimerStore.getState().setCurrentTaskId(id); + try { + await useTimerStore.getState().syncFromBackend(); + } catch (e) { + console.error('syncFromBackend after set_current_task error:', e); + } }, })); diff --git a/src/store/timerStore.ts b/src/store/timerStore.ts index 6a81e20..79170a4 100644 --- a/src/store/timerStore.ts +++ b/src/store/timerStore.ts @@ -1,3 +1,4 @@ +import { invoke } from '@tauri-apps/api/core'; import { create } from 'zustand'; export type TimerPhase = 'work' | 'short_break' | 'long_break'; @@ -10,6 +11,15 @@ export interface TimerTickPayload { current_task_id: string | null; } +export interface TimerStatus { + phase: TimerPhase; + remaining_secs: number; + total_secs: number; + running: boolean; + session_count: number; + current_task_id: string | null; +} + interface TimerState { phase: TimerPhase; remainingSecs: number; @@ -17,8 +27,10 @@ interface TimerState { running: boolean; sessionCount: number; currentTaskId: string | null; + syncFromBackend: () => Promise; setTimerTick: (payload: TimerTickPayload) => void; setRunning: (running: boolean) => void; + setCurrentTaskId: (currentTaskId: string | null) => void; } export const useTimerStore = create((set) => ({ @@ -29,6 +41,18 @@ export const useTimerStore = create((set) => ({ sessionCount: 0, currentTaskId: null, + syncFromBackend: async () => { + const status = await invoke('get_timer_status'); + set({ + phase: status.phase, + remainingSecs: status.remaining_secs, + totalSecs: status.total_secs, + running: status.running, + sessionCount: status.session_count, + currentTaskId: status.current_task_id, + }); + }, + setTimerTick: (payload) => set({ phase: payload.phase, @@ -39,4 +63,5 @@ export const useTimerStore = create((set) => ({ }), setRunning: (running) => set({ running }), + setCurrentTaskId: (currentTaskId) => set({ currentTaskId }), })); -- cgit v1.3-2-g0d8e