diff --git a/src/App.tsx b/src/App.tsx index e1d6e7b9..8711fdc0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,6 @@ import './App.css'; import { RecoilRoot } from 'recoil'; import { Routes, Route, BrowserRouter } from 'react-router-dom'; -import Home from 'pages/home/Home'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import DetailPetPage from 'pages/detailPet/DetailPetPage'; import ProfileListPage from 'pages/profileList/ProfileListPage'; @@ -13,6 +12,7 @@ import ShelterInfoPage from 'pages/shelterInfo/ShelterInfoPage'; import SignupPage from 'pages/signUp/SignupPage'; import UrgentListPage from 'pages/profileList/urgentList/UrgentListPage'; import UpdatePage from 'pages/update/UpdatePage'; +import HomePage from 'pages/home/HomePage'; const queryClient = new QueryClient({ defaultOptions: { @@ -26,10 +26,10 @@ function App() { - } /> + } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/src/pages/home/Home.tsx b/src/pages/home/Home.tsx index 5a2e2e0a..5ef932f0 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -1,12 +1,66 @@ -import GNB from 'layouts/GNB'; - -const HomePage = () => { - return ( -
- -

Home

-
- ); +import { useQuery } from '@tanstack/react-query'; +import { useEffect, useState } from 'react'; +import VHome, { HomeProps } from './VHome'; + +const Home = () => { + 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 HomePage; +export default Home; diff --git a/src/pages/home/HomePage.tsx b/src/pages/home/HomePage.tsx new file mode 100644 index 00000000..be2b7194 --- /dev/null +++ b/src/pages/home/HomePage.tsx @@ -0,0 +1,13 @@ +import GNB from 'layouts/GNB'; +import Home from './Home'; + +const HomePage = () => { + return ( +
+ + +
+ ); +}; + +export default HomePage; diff --git a/src/pages/home/VHome.tsx b/src/pages/home/VHome.tsx new file mode 100644 index 00000000..edec0518 --- /dev/null +++ b/src/pages/home/VHome.tsx @@ -0,0 +1,57 @@ +import ProfileCard from 'pages/profileList/ProfileCard'; + +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 VHome = (homeProps: HomeProps) => ( + +); + +export default VHome;