-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ : #492 - 발자취 조회 무한 스크롤 적용 위해 임시로 getAllPlans API 사용
- Loading branch information
Showing
5 changed files
with
157 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DOMAIN } from '@/constants/api'; | ||
import { | ||
GetAllPlansRequestQuery, | ||
GetAllPlansResponse, | ||
} from '@/types/apis/plan/GetAllPlans'; | ||
import { axiosInstanceClient } from '../axiosInstanceClient'; | ||
|
||
export const getMyFootPrints = async (query: GetAllPlansRequestQuery) => { | ||
const { data } = await axiosInstanceClient.get<GetAllPlansResponse>( | ||
DOMAIN.GET_PLANS_ALL, | ||
{ | ||
authorization: false, | ||
params: { | ||
...query, | ||
}, | ||
}, | ||
); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use client'; | ||
|
||
import { getMyFootPrints } from '@/apis/client/getMyFootPrints'; | ||
import { QUERY_KEY } from '@/constants/queryKey'; | ||
import { GetAllPlansRequestQuery } from '@/types/apis/plan/GetAllPlans'; | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||
|
||
// TODO: 수정 필요 | ||
export const useMyFootPrintsQuery = (query: GetAllPlansRequestQuery) => { | ||
const { | ||
data, | ||
fetchNextPage, | ||
hasNextPage, | ||
isLoading, | ||
isFetchingNextPage, | ||
isError, | ||
} = useSuspenseInfiniteQuery({ | ||
queryKey: [QUERY_KEY.MY_FOOTPRINTS, query.sort, query.current], // sort와 current를 쿼리 키에 넣는 게 맞을까? | ||
queryFn: async ({ pageParam = {} }) => { | ||
let params = { | ||
sort: query.sort, | ||
current: query.current, | ||
}; | ||
|
||
if (pageParam) { | ||
// start, ajaja가 들어있을 것임 | ||
params = { ...params, ...pageParam }; | ||
} | ||
|
||
const result = await getMyFootPrints(params); | ||
return result?.data; | ||
}, | ||
initialPageParam: {}, // 초기 pageParam => 빈 객체 | ||
getNextPageParam: (lastPage) => { | ||
// 더 불러올 data가 있는 지 확인하는 함수 | ||
if (lastPage.length === 0) { | ||
// 빈 배열이라면 | ||
return undefined; | ||
} | ||
|
||
const lastItem = lastPage[lastPage.length - 1]; // 가장 최근 받아온 3개 data 중 마지막 ite | ||
return query.sort === 'ajaja' | ||
? { start: lastItem.id, ajaja: lastItem.ajajas } // 인기순이면 start, ajaja 모두 params에 넣어주기 위해 | ||
: { start: lastItem.id }; // 인기순이면 start를 params에 넣어주기 위해 | ||
}, | ||
staleTime: 10000, | ||
}); | ||
return { | ||
tempFootPrintList: data?.pages.flat() || [], // TODO: flat() 없애기 | ||
fetchNextPage, | ||
hasNextPage, | ||
isLoading, | ||
isFetchingNextPage, | ||
isError, | ||
}; | ||
}; |