Skip to content

Commit

Permalink
fix: 무한스크롤 sort 적용 안되는 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
maylh committed Aug 16, 2024
1 parent 14ffdb5 commit ad6e1e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const UserWkHistoryPage = () => {
pageable: {
page: 1,
size: 10,
sort: param.order,
sort: selectedOrder,
},
});

Expand Down
15 changes: 11 additions & 4 deletions src/app/_hooks/user/useGetMyWktHistoryQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const useGetMyWktHistoryQuery = ({
pageable: {
page: number;
size: number;
sort?: string;
sort: string;
};
}) => {
return useInfiniteQuery({
Expand All @@ -28,22 +28,29 @@ export const useGetMyWktHistoryQuery = ({
pageable,
],
queryFn: async ({ pageParam = pageable }) => {
const { page, size, sort } = pageable;
const res = await api.get(`/api/apply/my`, {
params: {
startDate,
endDate,
statuses,
...pageParam,
page,
size,
sort,
},
});
return userApplyListSchema.parse(res.data.data);
},
initialPageParam: { page: 1, size: 10 },
initialPageParam: { page: 1, size: 10, sort: 'createdAt,DESC' },
getNextPageParam: (lastPage) => {
return lastPage.pageInfo.totalElements === 0 ||
lastPage.pageInfo.totalPages - 1 === lastPage.pageInfo.pageNum
? undefined
: { page: lastPage.pageInfo.pageNum + 2, size: pageable.size };
: {
page: lastPage.pageInfo.pageNum + 2,
size: pageable.size,
sort: pageable.sort,
};
},
});
};

0 comments on commit ad6e1e5

Please sign in to comment.