From daa90933bc84c295d156110675a143b3a3ab6c55 Mon Sep 17 00:00:00 2001 From: hanseulhee <3021062@gmail.com> Date: Sun, 9 Jun 2024 14:48:41 +0900 Subject: [PATCH] apply end message --- src/pages/index.tsx | 99 +++++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b1cb878..fa726f3 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,48 +1,62 @@ -import { css } from "@emotion/react"; -import PlaceCard from "components/Card/PlaceCard"; -import Footer from "components/Footer"; -import Carousel from "components/common/Main/Carousel"; -import useGetRestaurant from "hooks/api/useGetRestaurant"; -import useIntersectionObserver from "hooks/useIntersectionObserver"; -import useScrollRestoration from "hooks/useScrollRestoration"; -import { useCallback, useEffect, useState } from "react"; -import theme from "styles/Theme/theme"; +import { Theme, css } from '@emotion/react' +import ErrorIcon from '@mui/icons-material/Error' +import PlaceCard from 'components/Card/PlaceCard' +import Footer from 'components/Footer' +import Carousel from 'components/common/Main/Carousel' +import useGetRestaurant from 'hooks/api/useGetRestaurant' +import useIntersectionObserver from 'hooks/useIntersectionObserver' +import useScrollRestoration from 'hooks/useScrollRestoration' +import Link from 'next/link' +import { useCallback, useEffect, useState } from 'react' +import theme from 'styles/Theme/theme' function Home() { - useScrollRestoration(); - const [pageNumber, setPageNumber] = useState(0); + useScrollRestoration() + const [pageNumber, setPageNumber] = useState(0) const { intersectionTargetRef } = useIntersectionObserver({ callback: useCallback( (entry: IntersectionObserverEntry, observer: IntersectionObserver) => { if (entry[0].isIntersecting) { - setPageNumber((prev) => prev + 1); - observer.unobserve(entry[0].target); + setPageNumber((prev) => prev + 1) + observer.unobserve(entry[0].target) } }, - [] + [], ), - }); + }) - const { restaurants, isLoading } = useGetRestaurant(pageNumber); + const { restaurants, isLoading } = useGetRestaurant(pageNumber) const [combinedRestaurants, setCombinedRestaurants] = useState< IGetRestaurantDataContent[] - >([]); + >([]) useEffect(() => { setCombinedRestaurants((prevCombinedRestaurants) => { const uniqueNewRestaurants = restaurants.filter((newRestaurant) => { return !prevCombinedRestaurants.some( - (prevRestaurant) => prevRestaurant.id === newRestaurant.id - ); - }); - return [...prevCombinedRestaurants, ...uniqueNewRestaurants]; - }); - }, [pageNumber, restaurants]); + (prevRestaurant) => prevRestaurant.id === newRestaurant.id, + ) + }) + return [...prevCombinedRestaurants, ...uniqueNewRestaurants] + }) + }, [pageNumber, restaurants]) return (