-
Notifications
You must be signed in to change notification settings - Fork 0
[REFACTOR] 타이머 상태 관리 동기화 구조 정리 #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jjangminii
merged 12 commits into
develop
from
refactor/web/279-unify-timer-query-invalidation
Sep 13, 2026
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4c8a04f
refactor(web): 타이머 쿼리 무효화 로직 통일 (#279)
jjangminii c43cbed
refactor(web): 타이머 overtime 상태를 zustand 스토어로 전환
jjangminii 89f3408
refactor(web): 타이머 진행률 계산을 공통 훅으로 추출
jjangminii d8d468d
fix(web): 타이머 진행 중 액션에도 통계 쿼리 무효화 (#279)
jjangminii ed45072
refactor(web): use-timer-progress를 utils로 이동하고 getTimerProgress로 개명 (…
jjangminii b2967e2
refactor(web): getTimerProgress로 개명한 파일과 호출부 반영 (#279)
jjangminii e732db0
refactor(web): overtime storage 파싱을 unknown 후 타입가드로 좁히도록 수정 (#279)
jjangminii 84b8185
refactor(web): use-focus-session도 invalidateTimerFinish 공유 (#279)
jjangminii 848ce9e
docs(web): 타이머 무효화 헬퍼에 JSDoc 추가 (#279)
jjangminii f21ad3a
refactor(web): 타이머 진행 무효화에 옵션 추가하고 개별 훅의 중복 로직 통일 (#279)
jjangminii 24b94cf
Merge branch 'develop' of https://github.com/Team-Timo/Timo-client in…
jjangminii 850b92e
fix(web): 투두 완료 처리 PATCH 이후 재검증 누락 레이스 컨디션 수정 (#279)
jjangminii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,17 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import type { ActiveTimer } from "@/schemas/timer/timer-schema"; | ||
|
|
||
| const STORAGE_KEY_PREFIX = "timo:overtime-base:"; | ||
|
|
||
| const readStoredBase = (timerId: number): number | null => { | ||
| if (typeof window === "undefined") return null; | ||
|
|
||
| const raw = window.sessionStorage.getItem(`${STORAGE_KEY_PREFIX}${timerId}`); | ||
| if (raw === null) return null; | ||
|
|
||
| const parsed = Number(raw); | ||
| return Number.isFinite(parsed) ? parsed : null; | ||
| }; | ||
| import { useTimerOvertimeStore } from "@/stores/timer/useTimerOvertimeStore"; | ||
|
|
||
| export const useTimerOvertime = (timer: ActiveTimer | undefined) => { | ||
| const timerId = timer?.timerId; | ||
| const [overtimeBaseSeconds, setOvertimeBaseSeconds] = useState<number | null>( | ||
| null, | ||
| const overtimeBaseSeconds = useTimerOvertimeStore((state) => | ||
| state.timerId === timerId ? state.baseSeconds : null, | ||
| ); | ||
| const markOvertimeStart = useTimerOvertimeStore( | ||
| (state) => state.markOvertimeStart, | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| setOvertimeBaseSeconds(timerId ? readStoredBase(timerId) : null); | ||
| }, [timerId]); | ||
|
|
||
| const markOvertimeStart = (timerId: number, baseSeconds: number) => { | ||
| setOvertimeBaseSeconds(baseSeconds); | ||
| window.sessionStorage.setItem( | ||
| `${STORAGE_KEY_PREFIX}${timerId}`, | ||
| String(baseSeconds), | ||
| ); | ||
| }; | ||
|
|
||
| return { overtimeBaseSeconds, markOvertimeStart }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { ActiveTimer } from "@/schemas/timer/timer-schema"; | ||
|
|
||
| import { convertDurationToMinutes } from "@/utils/duration/convert-duration-to-minutes"; | ||
|
|
||
| export interface UseTimerProgressOptions { | ||
| timer: ActiveTimer | undefined; | ||
| overtimeBaseSeconds: number | null; | ||
| /** 활성 타이머가 없을 때 사용할 계획 시간(초). 기본값 0 */ | ||
| fallbackPlannedSeconds?: number; | ||
| } | ||
|
|
||
| export const useTimerProgress = ({ | ||
| timer, | ||
| overtimeBaseSeconds, | ||
| fallbackPlannedSeconds = 0, | ||
| }: UseTimerProgressOptions) => { | ||
| const plannedSeconds = timer | ||
| ? timer.plannedSeconds + timer.extendedSeconds | ||
| : fallbackPlannedSeconds; | ||
| const remainingSeconds = timer ? timer.remainingSeconds : plannedSeconds; | ||
| const progress = | ||
| plannedSeconds > 0 | ||
| ? ((plannedSeconds - remainingSeconds) / plannedSeconds) * 100 | ||
| : 0; | ||
|
|
||
| const isOvertime = overtimeBaseSeconds !== null; | ||
| const overtimeTotal = timer | ||
| ? timer.plannedSeconds + timer.extendedSeconds - (overtimeBaseSeconds ?? 0) | ||
| : 0; | ||
| const overtimeProgress = | ||
| timer && overtimeBaseSeconds !== null && overtimeTotal > 0 | ||
| ? Math.min( | ||
| 100, | ||
| Math.max( | ||
| 0, | ||
| ((timer.elapsedSeconds - overtimeBaseSeconds) / overtimeTotal) * | ||
| 100, | ||
| ), | ||
| ) | ||
| : 0; | ||
|
|
||
| const plannedMinutes = convertDurationToMinutes(plannedSeconds); | ||
| // 완료 모달의 "계획"은 연장 시간을 제외한 순수 계획 시간만 보여줘야 한다 | ||
| const basePlannedMinutes = convertDurationToMinutes( | ||
| timer ? timer.plannedSeconds : fallbackPlannedSeconds, | ||
| ); | ||
| const actualMinutes = convertDurationToMinutes(timer?.elapsedSeconds ?? 0); | ||
|
|
||
| return { | ||
| plannedSeconds, | ||
| remainingSeconds, | ||
| progress, | ||
| isOvertime, | ||
| overtimeProgress, | ||
| plannedMinutes, | ||
| basePlannedMinutes, | ||
| actualMinutes, | ||
| }; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.