Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit b4e267c

Browse files
authored
feat: pomodoro api v2 교체 (#71, #patch)
* 뽀모도로 저장 api v2로 변경 * 통계 api 스펙 변경 대응 및 요청시 타임존 추가 * api 요청 중복으로 보내지않도록 방어코드 추가
1 parent 9ab7a00 commit b4e267c

File tree

9 files changed

+18
-12
lines changed

9 files changed

+18
-12
lines changed

src/renderer/entities/stats/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Stats } from './types';
22

33
import { createIsoDuration } from '@/shared/utils';
44

5-
export const mockTrend: Stats['weaklyFocusTimeTrend'] = {
5+
export const mockTrend: Stats['weeklyFocusTimeTrend'] = {
66
startDate: '2025-06-19',
77
endDate: '2025-06-25',
88
dateToFocusTimeStatistics: [

src/renderer/entities/stats/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Stats = {
1010
startedAt: string;
1111
doneAt: string;
1212
}>;
13-
weaklyFocusTimeTrend: {
13+
weeklyFocusTimeTrend: {
1414
startDate: string;
1515
endDate: string;
1616
dateToFocusTimeStatistics: Array<{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMutation } from '@tanstack/react-query';
2+
import { Pomodoro } from 'shared/type';
23

3-
import { Pomodoro } from '@/entities/pomodoro';
44
import { useAuthClient } from '@/shared/hooks';
55

66
type AddPomodoroBody = Pomodoro[];
@@ -9,7 +9,7 @@ export const useAddPomodoro = () => {
99
const authClient = useAuthClient();
1010
return useMutation({
1111
mutationFn: async ({ body }: { body: AddPomodoroBody }) => {
12-
return await authClient?.post<void, AddPomodoroBody>('/api/v1/focus-times', body);
12+
return await authClient?.post<void, AddPomodoroBody>('/api/v2/focus-times', body);
1313
},
1414
});
1515
};

src/renderer/features/stats/hooks/use-stats.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import { useAuthClient } from '@/shared/hooks';
99
*/
1010
export const useStats = (date: string) => {
1111
const authClient = useAuthClient();
12+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
13+
const queryString = new URLSearchParams({ timezone }).toString();
1214
return useQuery({
13-
queryKey: [...QUERY_KEY.STATS, date],
15+
queryKey: [...QUERY_KEY.STATS, date, timezone],
1416
queryFn: async () => {
15-
return await authClient?.get<Stats>(`/api/v1/statistics/${date}`);
17+
return await authClient?.get<Stats>(`/api/v1/statistics/${date}?${queryString}`);
1618
},
1719
enabled: !!authClient && !!date,
1820
staleTime: 0,
21+
gcTime: 0,
1922
});
2023
};

src/renderer/features/stats/ui/stats-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Stats } from '@/entities/stats';
1616
import { cn, isoDurationToMs } from '@/shared/utils';
1717

1818
export type StatsChartProps = {
19-
dataFromServer: Stats['weaklyFocusTimeTrend'];
19+
dataFromServer: Stats['weeklyFocusTimeTrend'];
2020
};
2121

2222
type YAxisProps = ComponentProps<typeof YAxis>;

src/renderer/pages/pomodoro.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const Pomodoro = () => {
4747

4848
const { currentCategory } = useCategories();
4949
const { data: user } = useUser();
50-
const { mutate: updateCategory } = useUpdateCategory();
51-
const { mutate: savePomodoro } = useAddPomodoro();
50+
const { mutate: updateCategory, isPending: isUpdating } = useUpdateCategory();
51+
const { mutate: savePomodoro, isPending: isSaving } = useAddPomodoro();
5252
const { minimized, setMinimized } = useMinimize();
5353
const { alwaysOnTop, setAlwaysOnTop } = useAlwaysOnTop();
5454

@@ -92,14 +92,15 @@ const Pomodoro = () => {
9292
timeoutDialogProps.onOpen();
9393
}
9494

95-
if (currentCategory) {
95+
if (currentCategory && !isSaving) {
9696
savePomodoro({
9797
body: [
9898
{
9999
clientFocusTimeId: Date.now().toString(),
100100
categoryNo: currentCategory.no,
101101
focusedTime: msToIsoDuration(focusedTime),
102102
restedTime: msToIsoDuration(restedTime),
103+
startedAt: new Date(cycles[0].startAt).toISOString(),
103104
doneAt: new Date().toISOString(),
104105
},
105106
],
@@ -116,6 +117,7 @@ const Pomodoro = () => {
116117

117118
const updateCategoryTime = (type: 'focusTime' | 'restTime', currentMinutes: number) => {
118119
if (!selectedNextAction || !currentCategory) return;
120+
if (isUpdating) return;
119121

120122
updateCategory({
121123
no: currentCategory.no,

src/renderer/pages/stats.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const StatsPage = () => {
4343
<div>
4444
<h2 className="header-4 px-4 py-5">집중 추세</h2>
4545
<div className="px-4 pb-5">
46-
<StatsChart dataFromServer={stats.weaklyFocusTimeTrend} />
46+
<StatsChart dataFromServer={stats.weeklyFocusTimeTrend} />
4747
</div>
4848
</div>
4949
<div>

src/renderer/shared/constants/keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const QUERY_KEY = {
66
CATEGORIES: ['category', 'all'],
77

88
// stats
9-
STATS: ['stats', 'all'],
9+
STATS: ['stat', 'all'],
1010

1111
// user
1212
ME: ['me'],

src/shared/type/pomodoro.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type Pomodoro = {
2727
categoryNo: number;
2828
focusedTime: string;
2929
restedTime: string;
30+
startedAt: string;
3031
doneAt: string;
3132
};
3233

0 commit comments

Comments
 (0)