Skip to content

Commit

Permalink
apply end message
Browse files Browse the repository at this point in the history
  • Loading branch information
hanseulhee committed Jun 9, 2024
1 parent df38791 commit daa9093
Showing 1 changed file with 69 additions and 30 deletions.
99 changes: 69 additions & 30 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div css={wrapper}>
<Carousel />

<div css={contentWrapper}>
<ErrorIcon css={exclamationMark} />
<span css={noticeSummary}>
2024.12.01λΆ€λ‘œ μ„œλΉ„μŠ€κ°€ μ’…λ£Œλ  μ˜ˆμ •μž…λ‹ˆλ‹€. κ΄€λ ¨ λ‚΄μš©μ€&nbsp;
<Link href="/End" passHref>
<b>ν•΄λ‹Ή 링크</b>
</Link>
μ—μ„œ ν™•μΈν•˜μ‹€ 수 μžˆμŠ΅λ‹ˆλ‹€.
</span>
</div>

<div css={inWrapper}>
{combinedRestaurants.map((restaurant) => {
return (
Expand All @@ -53,27 +67,27 @@ function Home() {
summary={restaurant.summary}
img={restaurant?.outsideImage.s3Url}
/>
);
)
})}
</div>

<div ref={intersectionTargetRef} css={dataStatus}>
{isLoading ? "λ‘œλ”©μ€‘ πŸ”πŸ•πŸŸπŸŒ­πŸΏπŸ₯žπŸ—" : "데이터λ₯Ό λͺ¨λ‘ ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€."}
{isLoading ? 'λ‘œλ”©μ€‘ πŸ”πŸ•πŸŸπŸŒ­πŸΏπŸ₯žπŸ—' : '데이터λ₯Ό λͺ¨λ‘ ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.'}
</div>

<Footer />
</div>
);
)
}

export default Home;
export default Home

const wrapper = css`
min-height: 100%;
position: relative;
width: 100%;
overflow-x: hidden;
`;
`

const inWrapper = css`
display: flex;
Expand All @@ -82,12 +96,37 @@ const inWrapper = css`
width: 100%;
height: auto;
flex-wrap: wrap;
`;
`

const dataStatus = css`
font-size: 0.7rem;
text-align: center;
margin-bottom: 1.45rem;
color: ${theme.color.grey500};
font-weight: ${theme.fontWeight.bold};
`;
`

const contentWrapper = css`
display: flex;
flex-direction: row;
margin: 0.2rem 0 0.7rem 0rem;
b {
cursor: pointer;
color: #ffa200;
border-bottom: 1px solid #ffc800;
}
`

const noticeSummary = (theme: Theme) => css`
font-weight: ${theme.fontWeight.bold};
font-size: 0.69rem;
color: ${theme.color.grey500};
`

const exclamationMark = (theme: Theme) => css`
color: ${theme.color.yellow};
font-size: 1rem;
margin-bottom: 0.2rem;
margin-right: 0.1rem;
`

0 comments on commit daa9093

Please sign in to comment.