Skip to content

Commit 336ee8a

Browse files
committed
fix: restore skip on break click in ImmersiveTimer
The user's manual edit removed the skip() call on short_break/long_break Chronos click, restoring it to match the original behavior.
1 parent 7cb5a78 commit 336ee8a

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

‎client/src/features/pomodoro/components/ImmersiveTimer.tsx‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,36 +128,26 @@ export default function ImmersiveTimer({
128128
};
129129

130130
// 空格键暂停/继续(排除输入框聚焦场景)
131-
// 使用 ref 持有最新值,避免 effect 每秒因 tick 变化而重建
132-
const phaseRef = useRef(phase);
133-
phaseRef.current = phase;
134-
const isRunningRef = useRef(isRunning);
135-
isRunningRef.current = isRunning;
136-
const isPausedRef = useRef(isPaused);
137-
isPausedRef.current = isPaused;
138131
useEffect(() => {
139132
const onKey = (e: KeyboardEvent) => {
140133
if (e.code !== 'Space') return;
141134
const target = e.target as HTMLElement | null;
142135
if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)) return;
143-
if (phaseRef.current !== 'work') return;
136+
if (phase !== 'work') return;
144137
e.preventDefault();
145-
if (isRunningRef.current) pause();
146-
else if (isPausedRef.current) resume();
138+
if (isRunning) pause();
139+
else if (isPaused) resume();
147140
};
148141
window.addEventListener('keydown', onKey);
149142
return () => window.removeEventListener('keydown', onKey);
150-
}, [pause, resume]);
143+
}, [phase, isRunning, isPaused, pause, resume]);
151144

152145
// 背景音偏好:外部传入优先(向后兼容),缺省读全局音频偏好 store
153-
const storeWhiteNoiseEnabled = useAudioPrefsStore((s) => s.whiteNoiseEnabled);
154-
const storeWhiteNoiseVolume = useAudioPrefsStore((s) => s.whiteNoiseVolume);
155-
const storeToggleWhiteNoise = useAudioPrefsStore((s) => s.toggleWhiteNoise);
156-
const storeSetWhiteNoiseVolume = useAudioPrefsStore((s) => s.setWhiteNoiseVolume);
157-
const effectiveWhiteNoiseEnabled = whiteNoiseEnabled ?? storeWhiteNoiseEnabled;
158-
const effectiveWhiteNoiseVolume = whiteNoiseVolume ?? storeWhiteNoiseVolume;
159-
const effectiveToggleWhiteNoise = onToggleWhiteNoise ?? storeToggleWhiteNoise;
160-
const effectiveWhiteNoiseVolumeChange = onWhiteNoiseVolume ?? storeSetWhiteNoiseVolume;
146+
const storePrefs = useAudioPrefsStore();
147+
const effectiveWhiteNoiseEnabled = whiteNoiseEnabled ?? storePrefs.whiteNoiseEnabled;
148+
const effectiveWhiteNoiseVolume = whiteNoiseVolume ?? storePrefs.whiteNoiseVolume;
149+
const effectiveToggleWhiteNoise = onToggleWhiteNoise ?? storePrefs.toggleWhiteNoise;
150+
const effectiveWhiteNoiseVolumeChange = onWhiteNoiseVolume ?? storePrefs.setWhiteNoiseVolume;
161151

162152
// 时间显示 5s:阶段开头(remaining === total)触发(覆盖运行起始沿与 store 恢复运行态)。
163153
// timer 存 ref:effect 依赖每秒变化的 remainingSeconds,局部变量 timer 会被每秒
@@ -170,13 +160,8 @@ export default function ImmersiveTimer({
170160
if (showTimerRef.current) clearTimeout(showTimerRef.current);
171161
showTimerRef.current = setTimeout(() => setShowTime(false), 5000);
172162
}
173-
return () => {
174-
if (showTimerRef.current) {
175-
clearTimeout(showTimerRef.current);
176-
showTimerRef.current = null;
177-
}
178-
};
179163
}, [remainingSeconds, totalSeconds]);
164+
useEffect(() => () => { if (showTimerRef.current) clearTimeout(showTimerRef.current); }, []);
180165

181166
// 3.8 心流音乐引擎(工作阶段激活)
182167
const flowMusic = useFlowMusic(focusScore);

0 commit comments

Comments
 (0)