diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 6830745bc..bc2d5c77f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -7,6 +7,7 @@ import { ChainAbstraction } from '@/components/home/ChainAbstraction'; import { Contracts } from '@/components/home/Contracts'; import { Data } from '@/components/home/Data'; import { DecentralizedApps } from '@/components/home/DecentralizedApps'; +import { useNavigationStore } from '@/components/sidebar-navigation/store'; import useDeviceType from '@/hooks/useDeviceType'; import { useDefaultLayout } from '@/hooks/useLayout'; import type { NextPageWithLayout } from '@/utils/types'; @@ -37,7 +38,7 @@ const StyledCard = ({ href, title, description }: { href: string; title: string; ); }; -const NewsletterBanner = styled.div` +const NewsletterBanner = styled.div<{ isSidebarExpanded: boolean }>` background-color: #0072ce; color: white; padding: 8px; @@ -45,7 +46,8 @@ const NewsletterBanner = styled.div` font-size: 14px; position: absolute; top: 0; - left: 0; + left: ${(p) => (p.isSidebarExpanded ? 'var(--sidebar-width-expanded)' : 'var(--sidebar-width-collapsed)')}; + transition: all var(--sidebar-expand-transition-speed); right: 0; @media (max-width: 1240px) { @@ -53,6 +55,18 @@ const NewsletterBanner = styled.div` } `; +const CloseButton = styled.button` + background: none; + border: none; + color: white; + font-size: 16px; + cursor: pointer; + position: absolute; + right: 10px; + top: 50%; + transform: translateY(-50%); +`; + const HomePage: NextPageWithLayout = () => { const [selectedTab, setTab] = useState('contracts'); const [avgBlockTime, setAvgBlockTime] = useState('1.30'); @@ -60,6 +74,15 @@ const HomePage: NextPageWithLayout = () => { const [totalTx, setTotalTx] = useState('2,33'); const [nearStats, setNearStats] = useState(); const deviceType = useDeviceType(); + const [visible, setVisible] = useState(false); + const isSidebarExpanded = useNavigationStore((store) => store.isSidebarExpanded && !store.expandedDrawer); + + useEffect(() => { + const isClosed = localStorage.getItem('newsletterBannerClosed'); + if (!isClosed) { + setVisible(true); + } + }, []); useEffect(() => { fetch('https://api.nearblocks.io/v1/stats') @@ -86,14 +109,25 @@ const HomePage: NextPageWithLayout = () => { getAvrTx(); }, [nearStats]); + const handleClose = () => { + setVisible(false); + localStorage.setItem('newsletterBannerClosed', 'true'); + }; + return (
- - Stay updated!{' '} - - Sign up for our newsletter → - - + {visible && ( + + Stay updated!{' '} + + Sign up for our newsletter → + + × + + )}