Skip to content

Commit 54c94ee

Browse files
[feat/map-certificaiton-update] 목표 인증 메뉴 보완 (#24)
* feat: 인증완료시 포인트 및 데이터 업데이트 * feat: 장소 검색 리스트가 최대 10개만 보이도록 수정
1 parent 1f38424 commit 54c94ee

4 files changed

Lines changed: 39 additions & 11 deletions

File tree

src/features/map-certification/components/map-certification.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import Gps from "@/asset/map/gps.svg?react";
55
import notContainTargetUrl from "@/asset/map/not-contain-target.svg?url";
66
import positionIconUrl from "@/asset/map/position.svg?url";
77
import { getDistance } from "@/utils/map";
8-
import { useMutation, useQuery } from "@tanstack/react-query";
8+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
99
import { join, map, replace } from "es-toolkit/compat";
1010
import { Circle, Map, MapMarker } from "react-kakao-maps-sdk";
1111
import { useNavigate } from "react-router";
1212

13+
import { useUserStore } from "@/stores/user";
1314
import {
1415
generate_qo_getGoals,
16+
generate_qo_getGoalsCheck,
17+
generate_qo_getGoalsComplete,
1518
generate_qo_postGoalsAchieve
1619
} from "@/lib/react-query/queryOptions/goals";
1720
import useUserLocation from "@/hooks/useUserLocation";
@@ -26,7 +29,10 @@ const DISTANCE_DIFFRENCE = 20;
2629

2730
function MapCertification() {
2831
// Hooks
32+
const { addPoint } = useUserStore();
2933
const navigate = useNavigate();
34+
const client = useQueryClient();
35+
3036
const { center, position, setCenterToMyPosition, updateCenterWhenMapMoved } =
3137
useUserLocation();
3238
const {
@@ -43,7 +49,16 @@ function MapCertification() {
4349
const { mutate, isPending } = useMutation({
4450
...generate_qo_postGoalsAchieve(1),
4551
onSuccess: (data) => {
46-
/** @todo 홈 페이지에 사용도되는 데이터 쿼리 무효화 필요, 응답값으로 point 받아 성공 페이지로 전달 */
52+
const progressGoalKey = generate_qo_getGoalsCheck.DELETE_KEY();
53+
const completeGoalKey = generate_qo_getGoalsComplete.DELETE_KEY();
54+
55+
Promise.all([
56+
client.invalidateQueries({ queryKey: progressGoalKey }),
57+
client.invalidateQueries({ queryKey: completeGoalKey })
58+
// client.invalidateQueries({ queryKey: ["home"] }) // 홈페이지 데이터 무효화
59+
]);
60+
61+
addPoint(data.point);
4762

4863
navigate("/map/certification/success", {
4964
state: { name, point: data.point }

src/features/map-search/components/map.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import containTargetUrl from "@/asset/map/contain-target.svg?url";
44
import Gps from "@/asset/map/gps.svg?react";
55
import positionIconUrl from "@/asset/map/position.svg?url";
66
import { getFormattedDistance } from "@/utils/map";
7-
import { map } from "es-toolkit/compat";
7+
import { map, slice } from "es-toolkit/compat";
88
import { Map, MapMarker } from "react-kakao-maps-sdk";
99

1010
import useKakaoPlaces from "@/hooks/useKakaoMapService";
@@ -98,7 +98,7 @@ function KakaoMap() {
9898
lat: Number(y)
9999
})
100100
);
101-
setPlacesData(data);
101+
setPlacesData(slice(data, 0, 10));
102102
});
103103
}, [keyword, placesService, serviceStatus]);
104104

src/lib/react-query/queryOptions/goals.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,31 @@ export const generate_qo_postGoalsAchieve: GenerateQoPostGoalsAchieve = (
3333
};
3434

3535
interface UseQueryGoalsCheckOptions
36-
extends UseQueryOptions<ProgressGoal[], AxiosError, ProgressGoal[]> {}
36+
extends UseQueryOptions<ProgressGoal[], AxiosError, ProgressGoal[]> {
37+
DELETE_KEY?: [string];
38+
}
3739
type GenerateQoGetGoalsCheck = () => UseQueryGoalsCheckOptions;
38-
export const generate_qo_getGoalsCheck: GenerateQoGetGoalsCheck = () => {
39-
return {
40+
export const generate_qo_getGoalsCheck = (() => {
41+
const options: UseQueryGoalsCheckOptions = {
4042
queryKey: [GOALS_CHECK],
4143
queryFn: () => getGoalsCheck().then((data) => data)
4244
};
43-
};
45+
46+
return options;
47+
}) as GenerateQoGetGoalsCheck & { DELETE_KEY: () => [string] };
48+
49+
generate_qo_getGoalsCheck.DELETE_KEY = () => [GOALS_CHECK];
4450

4551
interface UseQueryGoalsCompleteOptions
4652
extends UseQueryOptions<CompleteGoal[], AxiosError, CompleteGoal[]> {}
4753
type GenerateQoGetGoalsComplete = () => UseQueryGoalsCompleteOptions;
48-
export const generate_qo_getGoalsComplete: GenerateQoGetGoalsComplete = () => {
49-
return {
54+
export const generate_qo_getGoalsComplete = (() => {
55+
const options: UseQueryGoalsCompleteOptions = {
5056
queryKey: [GOALS_COMPLETE],
5157
queryFn: () => getGoalsComplete().then((data) => data)
5258
};
53-
};
59+
60+
return options;
61+
}) as GenerateQoGetGoalsComplete & { DELETE_KEY: () => [string] };
62+
63+
generate_qo_getGoalsComplete.DELETE_KEY = () => [GOALS_COMPLETE];

src/stores/user.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface UserState {
55
point: number;
66
userId: string;
77
setPoint: (point: number) => void;
8+
addPoint: (addPoint: number) => void;
89
setUserName: (userName: string) => void;
910
}
1011

@@ -13,5 +14,7 @@ export const useUserStore = create<UserState>((set) => ({
1314
point: 100000,
1415
userId: "0",
1516
setPoint: (point) => set({ point }),
17+
addPoint: (addPoint: number) =>
18+
set((state) => ({ point: state.point + addPoint })),
1619
setUserName: (userName) => set({ userName })
1720
}));

0 commit comments

Comments
 (0)