Skip to content

Commit 43ec2d5

Browse files
committed
refactor: SKSK-60 query params를 주입하지 않고 customQuery에서 store 호출하도록 리팩토링
1 parent 9ee4559 commit 43ec2d5

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/pages/Home/components/HomeWithPosition/index.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,14 @@ import KakaoMap from '@/pages/Home/components/KakaoMap';
33
import PlaceList from '@/pages/Home/components/PlaceList';
44
import { PlaceListSkeleton } from '@/pages/Home/components/PlaceList/PlaceListSkeleton';
55
import { usePlacesQuery } from '@/pages/Home/hooks/usePlacesQuery';
6-
import { useQueryParamsStore } from '@/pages/Home/hooks/useQueryParamsStore';
76
import styles from '../../index.module.scss';
87

98
interface HomeWithPositionProps {
109
position: PositionType;
1110
}
1211

1312
export const HomeWithPosition = ({ position }: HomeWithPositionProps) => {
14-
const [pickPoint, radius_KM, numOfPlaces] = useQueryParamsStore(state => [
15-
state.pickPoint,
16-
state.radius_KM,
17-
state.numOfPlaces
18-
]);
19-
const { data: places, isLoading } = usePlacesQuery(
20-
{
21-
numOfRows: numOfPlaces,
22-
mapX: pickPoint ? pickPoint.lon : position?.lon,
23-
mapY: pickPoint ? pickPoint.lat : position?.lat,
24-
radius: radius_KM * 1000
25-
},
26-
position
27-
);
13+
const { data: places, isLoading } = usePlacesQuery(position);
2814
return (
2915
<>
3016
<KakaoMap position={position} places={places} isLoading={isLoading} />

src/pages/Home/hooks/usePlacesQuery.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ import { PlaceParams, PlaceType } from '@/pages/Home/types';
44
import { getPlaces } from '@/query/queryFn';
55
import queryKeys from '@/query/queryKeys';
66
import { PositionType } from '@/pages/Home';
7+
import { useQueryParamsStore } from '@/pages/Home/hooks/useQueryParamsStore';
8+
9+
export const usePlacesQuery = (position: PositionType) => {
10+
const [pickPoint, radius_KM, numOfPlaces] = useQueryParamsStore(state => [
11+
state.pickPoint,
12+
state.radius_KM,
13+
state.numOfPlaces
14+
]);
15+
16+
const placeParams: PlaceParams = {
17+
numOfRows: numOfPlaces,
18+
mapX: pickPoint ? pickPoint.lon : position?.lon,
19+
mapY: pickPoint ? pickPoint.lat : position?.lat,
20+
radius: radius_KM * 1000
21+
};
722

8-
export const usePlacesQuery = (placeParams: PlaceParams, position: PositionType) => {
9-
//! TODO 여기에서 useQueryParamsStore 호출? 고민해보기
10-
// const [pickPoint, radius_KM, numOfPlaces] = useQueryParamsStore(state => [..])
1123
const query = useQuery({
1224
queryKey: queryKeys.PLACES(placeParams),
1325
queryFn: async () => await getPlaces(placeParams),

src/pages/Home/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PlaceType } from '@/pages/Home/types';
77
import { renderAppWithRouterMatch } from '@/utils/test/renderWidthQuery';
88
import { fireEvent, render, screen } from '@testing-library/react';
99

10-
describe('위치를 모를ㅎ때', () => {
10+
describe('위치를 모를때', () => {
1111
test("위치추적 안되었을때 '현재 위치를 받아오고 있다는 문구' 노출", () => {
1212
render(renderAppWithRouterMatch(<Home />));
1313
const loadingTextForGettingPosition = screen.getByText('현재 위치를 받아오고 있습니다.');

0 commit comments

Comments
 (0)