Skip to content

Commit ef5d781

Browse files
Merge pull request #190 from SOPT-36-NINEDOT/refactor/#186/upperTodo
Refactor: 상위 목표 뷰 리팩토링
2 parents 5aeddf6 + 92af93f commit ef5d781

File tree

27 files changed

+398
-310
lines changed

27 files changed

+398
-310
lines changed

src/api/domain/edit/hook.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const useUpperGoalIds = (mandalartId: number) => {
2222
return useQuery({
2323
queryKey: EDIT_QUERY_KEY.upperGoalIds(mandalartId),
2424
queryFn: () => getUpperGoalIds(mandalartId),
25+
enabled: !!mandalartId,
2526
});
2627
};
2728

@@ -31,10 +32,13 @@ export const useSubGoals = (
3132
cycle?: CycleType,
3233
options?: Omit<UseQueryOptions<BaseResponse<SubGoalsResponse>>, 'queryKey' | 'queryFn'>,
3334
) => {
35+
const enabled = !!mandalartId && (options?.enabled ?? true);
36+
3437
return useQuery({
3538
queryKey: EDIT_QUERY_KEY.subGoals(mandalartId, coreGoalId, cycle),
3639
queryFn: () => getSubGoals(mandalartId, coreGoalId, cycle),
3740
...options,
41+
enabled,
3842
});
3943
};
4044

@@ -61,5 +65,6 @@ export const useCoreGoals = (mandalartId: number) => {
6165
return useQuery({
6266
queryKey: EDIT_QUERY_KEY.coreGoals(mandalartId),
6367
queryFn: () => getCoreGoals(mandalartId),
68+
enabled: !!mandalartId,
6469
});
6570
};

src/api/domain/history/hook/useGetHistory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const useGetHistory = (mandalartId: number) => {
88
return useQuery<historyResponse>({
99
queryKey: QUERY_KEY.HISTORY(mandalartId),
1010
queryFn: () => getHistory(mandalartId),
11+
enabled: !!mandalartId,
1112
});
1213
};

src/api/domain/history/hook/useGetStreak.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const useGetStreak = (mandalartId: number) => {
88
return useQuery<StreakResponse>({
99
queryKey: QUERY_KEY.STREAK(mandalartId),
1010
queryFn: () => getStreak(mandalartId),
11+
enabled: !!mandalartId,
1112
});
1213
};

src/api/domain/lowerTodo/hook/useCoreGoals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const useCoreGoals = (mandalartId: number) => {
88
return useQuery({
99
queryKey: QUERY_KEY.MANDALART_CORE_GOALS(mandalartId),
1010
queryFn: () => getCoreGoals(mandalartId),
11+
enabled: !!mandalartId,
1112
});
1213
};

src/api/domain/mandalAll/hook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export const useMandalAll = (mandalartId: number) => {
1111
return useQuery({
1212
queryKey: MANDAL_ALL_KEY.detail(mandalartId),
1313
queryFn: () => getMandalAll(mandalartId),
14+
enabled: !!mandalartId,
1415
});
1516
};

src/api/domain/myTodo/hook/useGetRecommendation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const useGetRecommendation = (mandalartId: number, date: string) => {
77
return useQuery({
88
queryKey: [QUERY_KEY.RECOMMENDED_TODO(mandalartId), date],
99
queryFn: () => getRecommendation(mandalartId, { date }),
10+
enabled: !!mandalartId,
1011
});
1112
};

src/api/domain/myTodo/hook/useMyMandal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ export const useGetMandalAll = (mandalartId: number) => {
1919
return useQuery({
2020
queryKey: [QUERY_KEY.ENTIRE_GOAL, mandalartId],
2121
queryFn: () => getMandalAll(mandalartId),
22+
enabled: !!mandalartId,
2223
});
2324
};
2425

2526
export const useGetMandalCoreGoals = (mandalartId: number) => {
2627
return useQuery<MandalCoreGoalsResponse>({
2728
queryKey: [QUERY_KEY.CORE_GOALS, mandalartId],
2829
queryFn: () => getMandalCoreGoals(mandalartId),
30+
enabled: !!mandalartId,
2931
});
3032
};
3133

src/api/domain/upperTodo/hook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const useGetMandalAll = (mandalartId: number) => {
1616
return useQuery({
1717
queryKey: [QUERY_KEY.ENTIRE_GOAL, mandalartId],
1818
queryFn: () => getMandalAll(mandalartId),
19+
enabled: !!mandalartId,
1920
});
2021
};
2122

src/api/domain/upperTodo/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const getMandalAll = async (mandalartId: number) => {
1515
};
1616

1717
export const getCoreGoalIdPositions = async (mandalartId: number) => {
18-
const res = await axiosInstance.get<BaseResponse<{ coreGoalIds: CoreGoalIdPosition[] }>>( // 응답 구조 변경
18+
const res = await axiosInstance.get<BaseResponse<{ coreGoalIds: CoreGoalIdPosition[] }>>(
1919
`/${END_POINT.MANDALART}/${mandalartId}/${END_POINT.CORE_GOAL}/id-positions`,
2020
);
2121
return res.data.data;

src/common/hook/useMandalartId.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useEffect, useState } from 'react';
2+
3+
const readMandalartId = () => {
4+
if (typeof window === 'undefined') {
5+
return 0;
6+
}
7+
const value = localStorage.getItem('mandalartId');
8+
return value ? Number(value) : 0;
9+
};
10+
11+
export const useMandalartId = () => {
12+
const [mandalartId, setMandalartId] = useState(0);
13+
14+
useEffect(() => {
15+
const syncMandalartId = () => setMandalartId(readMandalartId());
16+
17+
syncMandalartId();
18+
19+
const handleStorage = (e: StorageEvent) => {
20+
if (e.key === 'mandalartId') {
21+
syncMandalartId();
22+
}
23+
};
24+
25+
window.addEventListener('storage', handleStorage);
26+
return () => window.removeEventListener('storage', handleStorage);
27+
}, []);
28+
29+
return mandalartId;
30+
};

0 commit comments

Comments
 (0)