Skip to content

Commit d5004d8

Browse files
committed
feat: 주변 크루 목록 가져오는 api 함수 작성
- getNearCrewList 함수 - useNearCrewListQuery 훅
1 parent ef09ba4 commit d5004d8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/api/crews/getNearCrewList.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { axiosInstance } from '@api/axiosInstance';
2+
3+
import {
4+
GetNearCrewListRequest,
5+
GetNearCrewListResponse,
6+
} from '@type/api/crews';
7+
8+
export const getNearCrewList = async (params: GetNearCrewListRequest) => {
9+
const { data } = await axiosInstance.get<GetNearCrewListResponse>('/crews', {
10+
params,
11+
});
12+
13+
return data;
14+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
2+
3+
import { getNearCrewList } from '@api/crews/getNearCrewList';
4+
5+
import { GetNearCrewListRequest } from '@type/api/crews';
6+
7+
const FETCH_SIZE = 20;
8+
9+
export const useNearCrewListQuery = ({
10+
addressDepth1,
11+
addressDepth2,
12+
}: Pick<GetNearCrewListRequest, 'addressDepth1' | 'addressDepth2'>) => {
13+
const { data, ...query } = useSuspenseInfiniteQuery({
14+
queryKey: ['near-crews', addressDepth1, addressDepth2],
15+
queryFn: ({ pageParam }) =>
16+
getNearCrewList({
17+
addressDepth1,
18+
addressDepth2,
19+
page: pageParam,
20+
size: FETCH_SIZE,
21+
}),
22+
getNextPageParam: (_, pages) => pages.length,
23+
initialPageParam: 0,
24+
});
25+
const nearCrews = data.pages.flat();
26+
27+
return { nearCrews, data, ...query };
28+
};

0 commit comments

Comments
 (0)