86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import SideNav from './SideNav'
|
|
import { ReactNode, useEffect, useState } from 'react'
|
|
import { ChevronRightIcon } from '@heroicons/react/solid'
|
|
import { useViewport } from '../hooks/useViewport'
|
|
import { breakpoints } from '../utils/theme'
|
|
import mangoStore from '../store/mangoStore'
|
|
import BottomBar from './mobile/BottomBar'
|
|
import BounceLoader from './shared/BounceLoader'
|
|
import TopBar from './TopBar'
|
|
|
|
const Layout = ({ children }: { children: ReactNode }) => {
|
|
const connected = mangoStore((s) => s.connected)
|
|
const loadingMangoAccount = mangoStore((s) => s.mangoAccount.initialLoad)
|
|
const [isCollapsed, setIsCollapsed] = useState(false)
|
|
const { width } = useViewport()
|
|
|
|
useEffect(() => {
|
|
const collapsed = width ? width < breakpoints.xl : false
|
|
setIsCollapsed(collapsed)
|
|
}, [width])
|
|
|
|
useEffect(() => {
|
|
if (width < breakpoints.lg) {
|
|
setIsCollapsed(true)
|
|
}
|
|
}, [width])
|
|
|
|
const handleToggleSidebar = () => {
|
|
setIsCollapsed(!isCollapsed)
|
|
setTimeout(() => {
|
|
window.dispatchEvent(new Event('resize'))
|
|
}, 100)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{connected && loadingMangoAccount ? (
|
|
<div className="fixed z-30 flex h-screen w-full items-center justify-center bg-[rgba(0,0,0,0.7)]">
|
|
<BounceLoader />
|
|
</div>
|
|
) : null}
|
|
<div className="flex-grow bg-th-bkg-1 text-th-fgd-1 transition-all">
|
|
<div className="flex">
|
|
<div className="fixed bottom-0 left-0 z-20 w-full md:hidden">
|
|
<BottomBar />
|
|
</div>
|
|
|
|
<div className="fixed z-20 hidden h-screen md:block">
|
|
<button
|
|
className="absolute -right-4 top-1/2 z-20 hidden h-10 w-4 -translate-y-1/2 rounded-none rounded-r bg-th-bkg-4 focus:outline-none lg:block"
|
|
onClick={handleToggleSidebar}
|
|
>
|
|
<ChevronRightIcon
|
|
className={`h-full w-full ${
|
|
!isCollapsed ? 'rotate-180' : 'rotate-360'
|
|
}`}
|
|
/>
|
|
</button>
|
|
<div className={`h-full ${!isCollapsed ? 'overflow-y-auto' : ''}`}>
|
|
<SideNav collapsed={isCollapsed} />
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
className={`w-full overflow-hidden transition-all duration-500 ease-in-out ${
|
|
isCollapsed ? 'md:pl-[64px]' : 'md:pl-44 lg:pl-56'
|
|
}`}
|
|
>
|
|
<div className="flex h-16 items-center justify-between border-b border-th-bkg-3 bg-th-bkg-1 px-6 md:px-8">
|
|
<img
|
|
className="mr-4 h-8 w-auto md:hidden"
|
|
src="/logos/logo-mark.svg"
|
|
alt="next"
|
|
/>
|
|
<TopBar />
|
|
</div>
|
|
<div className="min-h-screen p-6 pb-20 md:p-8">{children}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default Layout
|