diff --git a/client/src/api/collect-api.ts b/client/src/api/collect-api.ts index e29384b..6b20f01 100644 --- a/client/src/api/collect-api.ts +++ b/client/src/api/collect-api.ts @@ -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'; @@ -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 }; }; diff --git a/client/src/app/collect/CollectArray.tsx b/client/src/app/collect/CollectArray.tsx index 504d56f..a8f6901 100644 --- a/client/src/app/collect/CollectArray.tsx +++ b/client/src/app/collect/CollectArray.tsx @@ -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 (