From f4dc2a6d11d2da9f4a6b4f0ca08f8acd6a04e320 Mon Sep 17 00:00:00 2001 From: Seunghwan Date: Sat, 10 Dec 2022 19:32:48 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20=EB=AC=B4=ED=95=9C?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A1=A4=20cursorId=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=9C=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/pages/Main.js | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/client/src/components/pages/Main.js b/client/src/components/pages/Main.js index 250fe00f..7a9e7340 100644 --- a/client/src/components/pages/Main.js +++ b/client/src/components/pages/Main.js @@ -24,7 +24,8 @@ const Main = () => { const [infoData, setInfoData] = useState({}); const [count, setCount] = useState(1); const [hasNext, setHasNext] = useState(true); - const SIZE = 10; + const [cursorId, setCurosrId] = useState(2000000000); + const SIZE = 5; const [isDrawer, setIsDrawer] = useState(false); const observerRef = useRef(); const preventRef = useRef(true); @@ -33,19 +34,16 @@ const Main = () => { const menuHandler = () => { setIsDrawer(!isDrawer); }; - const getUserData = async () => { const response = await client.get( - `/exercises?address-id=${address}&category=${category}&gender-type=${gender}&cursorId=2000000000&size=${ - count * SIZE - }`, + `/exercises?address-id=${address}&category=${category}&gender-type=${gender}&cursorId=${cursorId}&size=${SIZE}`, ); setHasNext(response.data.hasNext); - setUserData(response.data.data); + setUserData([...userData, ...response.data.data]); + setCurosrId(response.data.nextCursorId); preventRef.current = true; visited.current = true; }; - const getUserInfoData = async () => { await client.get('/members/info').then(res => { localStorage.setItem('memberId', res.data.memberId); @@ -79,11 +77,25 @@ const Main = () => { }; }; + const resetData = () => { + setCount(5); + setUserData([]); + setCurosrId(2000000000); + }; + useEffect(() => { getUserData(); - getUserInfoData(); observerSet(); - }, [address, category, gender, count]); + }, [count]); + + useEffect(() => { + getUserInfoData(); + }, []); + + useEffect(() => { + resetData(); + getUserData(); + }, [address, category, gender]); const genderToggleClick = () => { if (gender === 'ALL') { From f9c52071d8cfa4d92797e5377b7171275ffb5d42 Mon Sep 17 00:00:00 2001 From: Seunghwan Date: Sat, 10 Dec 2022 20:03:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#319=20=E2=9C=A8=20feat:=20=EB=AC=B4?= =?UTF-8?q?=ED=95=9C=EC=8A=A4=ED=81=AC=EB=A1=A4=20cursorId=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B0=9C=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/pages/Main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/components/pages/Main.js b/client/src/components/pages/Main.js index 7a9e7340..f6050028 100644 --- a/client/src/components/pages/Main.js +++ b/client/src/components/pages/Main.js @@ -70,6 +70,7 @@ const Main = () => { }; const observerSet = () => { + console.log('작동'); const observer = new IntersectionObserver(obsHandler, { threshold: 1 }); if (observerRef.current) observer.observe(observerRef.current); return () => { @@ -78,6 +79,7 @@ const Main = () => { }; const resetData = () => { + setHasNext(true); setCount(5); setUserData([]); setCurosrId(2000000000); @@ -94,7 +96,6 @@ const Main = () => { useEffect(() => { resetData(); - getUserData(); }, [address, category, gender]); const genderToggleClick = () => { From 328845e11390660a911b89e1bc3ba1ec3213e8a9 Mon Sep 17 00:00:00 2001 From: Seunghwan Date: Sat, 10 Dec 2022 20:04:53 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#319=20=F0=9F=94=A5=20remove:=20console.log?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/pages/Main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/components/pages/Main.js b/client/src/components/pages/Main.js index f6050028..8d8071ac 100644 --- a/client/src/components/pages/Main.js +++ b/client/src/components/pages/Main.js @@ -70,7 +70,6 @@ const Main = () => { }; const observerSet = () => { - console.log('작동'); const observer = new IntersectionObserver(obsHandler, { threshold: 1 }); if (observerRef.current) observer.observe(observerRef.current); return () => {