diff --git a/src/pages/home/Home.tsx b/src/pages/home/Home.tsx index 5ef932f0..fd2b5471 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -38,10 +38,17 @@ const Home = () => { }; const shortFormData = data.shortForms; + const handleReachEnd = () => { + if (pageData.hasNext) { + setCurrentPage(currentPage + 1); + console.log('마지막'); + } + }; const homeProps: HomeProps = { pageProps: pageData, shortFormProps: shortFormData, + handleReachEnd, }; setShortForm(homeProps); diff --git a/src/pages/home/HomePage.tsx b/src/pages/home/HomePage.tsx index e4c1c595..dc10fae5 100644 --- a/src/pages/home/HomePage.tsx +++ b/src/pages/home/HomePage.tsx @@ -1,12 +1,12 @@ import GNB from 'layouts/GNB'; import Home from './Home'; -import HomeSwiper from './HomeSwiper'; const HomePage = () => { return (
- + {/* gnb가 감싸게 하기 */} +
); }; diff --git a/src/pages/home/HomeSwiper.tsx b/src/pages/home/HomeSwiper.tsx deleted file mode 100644 index 1740022a..00000000 --- a/src/pages/home/HomeSwiper.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { useQuery } from '@tanstack/react-query'; -import { useEffect, useState } from 'react'; -import VHome, { HomeProps } from './VHomeSwiper'; - -const HomeSwiper = () => { - const [currentPage, setCurrentPage] = useState(1); // 현재 페이지 상태 - const [shortForm, setShortForm] = useState(null); - - const getShortForm = async () => { - const response = await fetch( - `${process.env.REACT_APP_URI}/short-forms/home?page=${currentPage}`, - { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }, - ); - - if (!response.ok) { - throw new Error(`HTTP error! Status: ${response.status}`); - } - - const json = await response.json(); - return json.response; - }; - - const { data, isLoading, isError } = useQuery({ - queryKey: ['home', currentPage], - queryFn: getShortForm, - }); - console.log(data); - - useEffect(() => { - if (!isLoading && !isError && data) { - const pageData = { - hasNext: data.hasNext, - }; - - const shortFormData = data.shortForms; - - const homeProps: HomeProps = { - pageProps: pageData, - shortFormProps: shortFormData, - }; - - setShortForm(homeProps); - } - }, [data, isLoading, isError]); - - if (isLoading) { - return
로딩중
; - } - - if (isError) { - return
Error: {isError}
; - } - - if (shortForm) { - return ; - } - - return null; -}; - -export default HomeSwiper; diff --git a/src/pages/home/VHome.tsx b/src/pages/home/VHome.tsx index 03fc510a..af31eaeb 100644 --- a/src/pages/home/VHome.tsx +++ b/src/pages/home/VHome.tsx @@ -1,4 +1,16 @@ -import ProfileCard from 'pages/profileList/ProfileCard'; +import { + Pagination, + A11y, + Autoplay, + Mousewheel, + Keyboard, +} from 'swiper/modules'; + +import { Swiper, SwiperSlide } from 'swiper/react'; + +// Import Swiper styles +import 'swiper/css'; +import 'swiper/css/pagination'; export interface PageProps { hasNext: boolean; @@ -23,14 +35,68 @@ export interface ShortFormProps { export interface HomeProps { pageProps: PageProps; shortFormProps: ShortFormProps; + handleReachEnd: any; } -const VHome = (homeProps: HomeProps) => ( -
-

-
- {homeProps.shortFormProps.map((shortForm, index) => ( -
+const VHome = (homeProps: HomeProps) => { + return ( +
+

+
+ console.log('스와이프')} + autoHeight={true} + direction={'vertical'} + keyboard={{ enabled: true, pageUpDown: true, onlyInViewport: true }} + onReachEnd={homeProps.handleReachEnd} + > + {homeProps.shortFormProps.map((shortForm, index) => { + return ( + + +
+
+
+
+ {shortForm.name} +
+
+
+ {shortForm.adoptionStatus} +
+
+ {shortForm.shelterName} +
+
+
+
+
+ ); + })} +
+ {/* {homeProps.shortFormProps.map((shortForm, index) => ( + -
-); + ); +}; export default VHome; diff --git a/src/pages/home/VHomeSwiper.tsx b/src/pages/home/VHomeSwiper.tsx deleted file mode 100644 index fda5d382..00000000 --- a/src/pages/home/VHomeSwiper.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import ProfileCard from 'pages/profileList/ProfileCard'; - -import { - Navigation, - Pagination, - Scrollbar, - A11y, - Autoplay, - Mousewheel, - Keyboard, -} from 'swiper/modules'; - -import { Swiper, SwiperSlide } from 'swiper/react'; - -// Import Swiper styles -import 'swiper/css'; -import 'swiper/css/navigation'; -import 'swiper/css/pagination'; -import 'swiper/css/scrollbar'; - -export interface PageProps { - hasNext: boolean; -} - -export interface ShortFormProps { - map( - arg0: ( - shortForm: any, - index: any, - ) => import('react/jsx-runtime').JSX.Element, - ): import('react').ReactNode; - petId: number; - name: string; - age: string; - shelterId: number; - shelterName: string; - profileShortFormUrl: string; - adoptionStatus: string; -} - -export interface HomeProps { - pageProps: PageProps; - shortFormProps: ShortFormProps; -} - -const VHomeSwiper = (homeProps: HomeProps) => { - return ( -
-

-
- console.log('스와이프')} - autoHeight={true} - direction={'vertical'} - keyboard={{ enabled: true, pageUpDown: true, onlyInViewport: true }} - > - {homeProps.shortFormProps.map((shortForm, index) => { - return ( - -
-
-
-
- {shortForm.name} -
-
- - {shortForm.adoptionStatus}{' '} - - - {' '} - {shortForm.shelterName}{' '} - -
-
-
- ); - })} -
- {/* {homeProps.shortFormProps.map((shortForm, index) => ( - - ))} */} -
-
- ); -}; - -export default VHomeSwiper;