Skip to content

Commit

Permalink
모아보기 페이지 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaeyeon1 committed Nov 29, 2023
1 parent 447968d commit f61fb95
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
18 changes: 14 additions & 4 deletions client/src/api/collect-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ICollect, ISearchContent, ISearchHashtag, ISearchTitle, ISearchUser } from '@/types/dto';
import {
ICollect,
ICollectContent,
ISearchContent,
ISearchHashtag,
ISearchTitle,
ISearchUser,
} from '@/types/dto';
import { defaultInstance } from '.';
import { useQuery } from '@tanstack/react-query';

Expand All @@ -9,9 +16,12 @@ const GetCollectDataApi = async (params: ICollect) => {
};

export const useGetCollectDataQuery = (params: ICollect) => {
const { isLoading, error, data } = useQuery([`collectData`, params], () =>
GetCollectDataApi(params),
);
const {
isLoading,
error,
data: queryData,
} = useQuery([`collectData`, params], () => GetCollectDataApi(params));
const data: ICollectContent = queryData;
return { data, isLoading, error };
};

Expand Down
10 changes: 9 additions & 1 deletion client/src/app/collect/CollectArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,25 @@ function CollectArray({ kind }: { kind: 'likes' | 'views' | 'recent' }) {
useEffect(() => {
if (!kindArray) {
setKindArray(data);
} else {
setKindArray((prevData) => {
return {
postPreviewDtos: [...(prevData?.postPreviewDtos ?? []), ...(data?.postPreviewDtos ?? [])],
totalPages: prevData.totalPages,
};
});
}
}, [data]);

const newDataButtonClick = () => {
if (page < kindArray.totalPages - 1) {
if (page < Math.max(kindArray.totalPages, kindArray.postPreviewDtos.length / postCount) - 1) {
setPage((prevPage) => prevPage + 1);
setBackendSendPage((prevPage) => prevPage + 1);
} else {
setToastOpen(true);
}
};

return (
<Stack direction="row" justifyContent="left" alignItems="center">
<Toast
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ICollectPost {

// 모아보기 페이지 목록
export interface ICollectContent {
postPreviewDtos?: ICollectPost[];
postPreviewDtos: ICollectPost[];
totalPages: number;
}

Expand Down

0 comments on commit f61fb95

Please sign in to comment.