From f61fb95109210a068e328660f2779906dc78b90f Mon Sep 17 00:00:00 2001 From: Chaeyeon1 <66813821+Chaeyeon1@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:13:55 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AA=A8=EC=95=84=EB=B3=B4=EA=B8=B0=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/api/collect-api.ts | 18 ++++++++++++++---- client/src/app/collect/CollectArray.tsx | 10 +++++++++- client/src/types/dto.ts | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/client/src/api/collect-api.ts b/client/src/api/collect-api.ts index e29384b7..6b20f01a 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 504d56ff..a8f69017 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 (