2022-08-02 19:15:17 -07:00
|
|
|
import SideNav from './SideNav'
|
2023-03-26 17:42:50 -07:00
|
|
|
import {
|
|
|
|
Fragment,
|
|
|
|
ReactNode,
|
|
|
|
useCallback,
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
|
|
|
useState,
|
|
|
|
} from 'react'
|
2023-03-06 03:48:24 -08:00
|
|
|
import { ArrowPathIcon, ChevronRightIcon } from '@heroicons/react/20/solid'
|
2022-07-26 19:45:27 -07:00
|
|
|
import { useViewport } from '../hooks/useViewport'
|
|
|
|
import { breakpoints } from '../utils/theme'
|
|
|
|
import BottomBar from './mobile/BottomBar'
|
2022-08-26 12:15:50 -07:00
|
|
|
import TopBar from './TopBar'
|
2022-09-01 11:51:15 -07:00
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
2023-03-21 17:52:17 -07:00
|
|
|
import { ACCEPT_TERMS_KEY, SIDEBAR_COLLAPSE_KEY } from '../utils/constants'
|
2022-11-15 20:12:51 -08:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2023-01-02 04:19:30 -08:00
|
|
|
import SuccessParticles from './shared/SuccessParticles'
|
2022-11-21 19:23:54 -08:00
|
|
|
import { tsParticles } from 'tsparticles-engine'
|
|
|
|
import { loadFull } from 'tsparticles'
|
2023-03-06 03:48:24 -08:00
|
|
|
import useInterval from './shared/useInterval'
|
|
|
|
import { Transition } from '@headlessui/react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-03-21 17:52:17 -07:00
|
|
|
import TermsOfUseModal from './modals/TermsOfUseModal'
|
2023-06-07 19:30:56 -07:00
|
|
|
import { ttCommons, ttCommonsExpanded, ttCommonsMono } from 'utils/fonts'
|
2023-06-12 22:33:15 -07:00
|
|
|
import PromoBanner from './rewards/PromoBanner'
|
|
|
|
import { useRouter } from 'next/router'
|
2022-07-26 19:45:27 -07:00
|
|
|
|
2023-06-06 05:47:42 -07:00
|
|
|
export const sideBarAnimationDuration = 300
|
2023-03-21 17:52:17 -07:00
|
|
|
const termsLastUpdated = 1679441610978
|
2022-09-21 18:23:29 -07:00
|
|
|
|
2022-07-26 19:45:27 -07:00
|
|
|
const Layout = ({ children }: { children: ReactNode }) => {
|
2022-09-01 11:51:15 -07:00
|
|
|
const [isCollapsed, setIsCollapsed] = useLocalStorageState(
|
|
|
|
SIDEBAR_COLLAPSE_KEY,
|
|
|
|
false
|
|
|
|
)
|
2023-07-16 22:18:00 -07:00
|
|
|
|
2022-07-26 19:45:27 -07:00
|
|
|
const { width } = useViewport()
|
2023-06-12 22:33:15 -07:00
|
|
|
const { asPath } = useRouter()
|
2022-08-13 04:29:48 -07:00
|
|
|
|
2022-07-26 19:45:27 -07:00
|
|
|
useEffect(() => {
|
2023-06-13 19:19:09 -07:00
|
|
|
if (width < breakpoints.xl) {
|
2022-07-26 19:45:27 -07:00
|
|
|
setIsCollapsed(true)
|
|
|
|
}
|
|
|
|
}, [width])
|
|
|
|
|
2022-09-21 18:23:29 -07:00
|
|
|
useEffect(() => {
|
2022-09-29 21:21:23 -07:00
|
|
|
const animationFrames = 15
|
2022-09-21 18:23:29 -07:00
|
|
|
|
|
|
|
for (let x = 1; x <= animationFrames; x++) {
|
|
|
|
setTimeout(() => {
|
|
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
}, (sideBarAnimationDuration / animationFrames) * x)
|
|
|
|
}
|
|
|
|
}, [isCollapsed])
|
|
|
|
|
2022-07-26 19:45:27 -07:00
|
|
|
const handleToggleSidebar = () => {
|
|
|
|
setIsCollapsed(!isCollapsed)
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:23:54 -08:00
|
|
|
const particlesInit = useCallback(async () => {
|
|
|
|
await loadFull(tsParticles)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
particlesInit()
|
|
|
|
}, [])
|
|
|
|
|
2022-07-26 19:45:27 -07:00
|
|
|
return (
|
2023-06-07 19:30:56 -07:00
|
|
|
<main
|
|
|
|
className={`${ttCommons.variable} ${ttCommonsExpanded.variable} ${ttCommonsMono.variable} font-sans`}
|
|
|
|
>
|
2022-11-21 19:23:54 -08:00
|
|
|
<div className="fixed z-30">
|
2023-01-02 04:19:30 -08:00
|
|
|
<SuccessParticles />
|
2022-11-21 19:23:54 -08:00
|
|
|
</div>
|
2022-09-29 21:21:23 -07:00
|
|
|
<div className="flex-grow bg-th-bkg-1 text-th-fgd-2 transition-all">
|
2022-12-19 23:00:54 -08:00
|
|
|
<div className="fixed bottom-0 left-0 z-20 w-full md:hidden">
|
|
|
|
<BottomBar />
|
|
|
|
</div>
|
2022-08-22 10:10:35 -07:00
|
|
|
|
2023-01-11 20:45:04 -08:00
|
|
|
<div className="fixed z-20 hidden h-screen md:block">
|
2022-12-19 23:00:54 -08:00
|
|
|
<button
|
2023-06-13 19:19:09 -07:00
|
|
|
className="absolute right-0 top-1/2 z-20 hidden h-8 w-3 -translate-y-1/2 rounded-none rounded-l bg-th-bkg-3 hover:bg-th-bkg-4 focus:outline-none focus-visible:bg-th-bkg-4 xl:block"
|
2022-12-19 23:00:54 -08:00
|
|
|
onClick={handleToggleSidebar}
|
|
|
|
>
|
|
|
|
<ChevronRightIcon
|
|
|
|
className={`absolute bottom-2 -right-[2px] h-4 w-4 flex-shrink-0 ${
|
|
|
|
!isCollapsed ? 'rotate-180' : 'rotate-360'
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</button>
|
2023-01-03 14:30:44 -08:00
|
|
|
<div
|
|
|
|
className={`thin-scroll h-full ${
|
|
|
|
!isCollapsed ? 'overflow-y-auto' : ''
|
|
|
|
}`}
|
|
|
|
>
|
2022-12-19 23:00:54 -08:00
|
|
|
<SideNav collapsed={isCollapsed} />
|
2022-08-22 10:10:35 -07:00
|
|
|
</div>
|
2022-12-19 23:00:54 -08:00
|
|
|
</div>
|
2022-12-27 01:57:23 -08:00
|
|
|
{/* note: overflow-x-hidden below prevents position sticky from working in activity feed */}
|
2022-12-19 23:00:54 -08:00
|
|
|
<div
|
|
|
|
className={`w-full overflow-x-hidden transition-all duration-${sideBarAnimationDuration} ease-in-out ${
|
|
|
|
isCollapsed ? 'md:pl-[64px]' : 'md:pl-44 lg:pl-48 xl:pl-52'
|
|
|
|
}`}
|
|
|
|
>
|
2023-05-14 21:30:00 -07:00
|
|
|
<TopBar />
|
2023-06-12 22:33:15 -07:00
|
|
|
{asPath !== '/rewards' ? <PromoBanner /> : null}
|
2022-12-19 23:00:54 -08:00
|
|
|
{children}
|
2022-07-26 19:45:27 -07:00
|
|
|
</div>
|
2023-03-06 03:48:24 -08:00
|
|
|
<DeployRefreshManager />
|
2023-07-16 22:18:00 -07:00
|
|
|
<TermsOfUse />
|
2022-07-26 19:45:27 -07:00
|
|
|
</div>
|
2023-07-16 22:18:00 -07:00
|
|
|
</main>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Layout
|
|
|
|
|
|
|
|
const TermsOfUse = () => {
|
|
|
|
const { connected } = useWallet()
|
|
|
|
const [acceptTerms, setAcceptTerms] = useLocalStorageState(
|
|
|
|
ACCEPT_TERMS_KEY,
|
|
|
|
''
|
|
|
|
)
|
|
|
|
|
|
|
|
const showTermsOfUse = useMemo(() => {
|
|
|
|
return (!acceptTerms || acceptTerms < termsLastUpdated) && connected
|
|
|
|
}, [acceptTerms, connected])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-03-21 17:52:17 -07:00
|
|
|
{showTermsOfUse ? (
|
|
|
|
<TermsOfUseModal
|
|
|
|
isOpen={showTermsOfUse}
|
|
|
|
onClose={() => setAcceptTerms(Date.now())}
|
|
|
|
/>
|
|
|
|
) : null}
|
2023-07-16 22:18:00 -07:00
|
|
|
</>
|
2022-07-26 19:45:27 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-03-06 03:48:24 -08:00
|
|
|
function DeployRefreshManager(): JSX.Element | null {
|
|
|
|
const { t } = useTranslation('common')
|
|
|
|
const [newBuildAvailable, setNewBuildAvailable] = useState(false)
|
2023-07-16 22:18:00 -07:00
|
|
|
|
2023-03-06 03:48:24 -08:00
|
|
|
useInterval(async () => {
|
|
|
|
const response = await fetch('/api/build-id')
|
|
|
|
const { buildId } = await response.json()
|
|
|
|
|
|
|
|
if (buildId && process.env.BUILD_ID && buildId !== process.env.BUILD_ID) {
|
|
|
|
// There's a new version deployed that we need to load
|
|
|
|
setNewBuildAvailable(true)
|
|
|
|
}
|
2023-07-16 22:18:00 -07:00
|
|
|
}, 300000)
|
2023-03-06 03:48:24 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Transition
|
|
|
|
appear={true}
|
|
|
|
show={newBuildAvailable}
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-in duration-300"
|
|
|
|
enterFrom="translate-y-0"
|
|
|
|
enterTo="-translate-y-[130px] md:-translate-y-20"
|
|
|
|
leave="transition ease-out"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
|
|
|
<button
|
2023-04-19 18:01:31 -07:00
|
|
|
className="fixed -bottom-[46px] left-1/2 z-50 flex -translate-x-1/2 items-center rounded-full border border-th-bkg-4 bg-th-bkg-3 py-3 px-4 shadow-md focus:outline-none md:hover:bg-th-bkg-4 md:hover:shadow-none"
|
2023-03-06 03:48:24 -08:00
|
|
|
onClick={() => window.location.reload()}
|
|
|
|
>
|
|
|
|
<p className="mr-2 whitespace-nowrap text-th-fgd-1">
|
|
|
|
{t('new-version')}
|
|
|
|
</p>
|
|
|
|
<ArrowPathIcon className="h-5 w-5" />
|
|
|
|
</button>
|
|
|
|
</Transition>
|
|
|
|
)
|
|
|
|
}
|