2022-08-02 19:15:17 -07:00
|
|
|
import SideNav from './SideNav'
|
2022-08-05 15:11:07 -07:00
|
|
|
import { ReactNode, useCallback, useEffect, useState } from 'react'
|
|
|
|
import { ArrowRightIcon, ChevronRightIcon } from '@heroicons/react/solid'
|
2022-07-26 19:45:27 -07:00
|
|
|
import { useViewport } from '../hooks/useViewport'
|
|
|
|
import { breakpoints } from '../utils/theme'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import mangoStore from '../store/state'
|
|
|
|
import BottomBar from './mobile/BottomBar'
|
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
|
|
|
import UserSetupModal from './modals/UserSetupModal'
|
|
|
|
import { ConnectWalletButton } from './wallet/ConnectWalletButton'
|
2022-07-26 21:40:17 -07:00
|
|
|
import ConnectedMenu from './wallet/ConnectedMenu'
|
2022-07-26 23:06:30 -07:00
|
|
|
import WalletIcon from './icons/WalletIcon'
|
2022-07-28 04:41:55 -07:00
|
|
|
import BounceLoader from './shared/BounceLoader'
|
2022-08-05 15:11:07 -07:00
|
|
|
import MangoAccountsList from './MangoAccountsList'
|
2022-07-26 19:45:27 -07:00
|
|
|
|
|
|
|
export const IS_ONBOARDED_KEY = 'isOnboarded'
|
|
|
|
|
|
|
|
const Layout = ({ children }: { children: ReactNode }) => {
|
2022-07-27 23:35:18 -07:00
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
2022-07-28 04:41:55 -07:00
|
|
|
const loadingMangoAccount = mangoStore((s) => s.mangoAccount.loading)
|
2022-07-26 19:45:27 -07:00
|
|
|
const { t } = useTranslation('common')
|
|
|
|
const [isCollapsed, setIsCollapsed] = useState(false)
|
|
|
|
const { width } = useViewport()
|
|
|
|
const isMobile = width ? width < breakpoints.md : false
|
|
|
|
const [isOnboarded] = useLocalStorageState(IS_ONBOARDED_KEY)
|
|
|
|
const [showUserSetupModal, setShowUserSetupModal] = useState(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const collapsed = width ? width < breakpoints.xl : false
|
|
|
|
setIsCollapsed(collapsed)
|
|
|
|
}, [width])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (width < breakpoints.lg) {
|
|
|
|
setIsCollapsed(true)
|
|
|
|
}
|
|
|
|
}, [width])
|
|
|
|
|
|
|
|
const handleCloseModal = useCallback(() => {
|
|
|
|
setShowUserSetupModal(false)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const handleShowModal = useCallback(() => {
|
|
|
|
setShowUserSetupModal(true)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const handleToggleSidebar = () => {
|
|
|
|
setIsCollapsed(!isCollapsed)
|
|
|
|
setTimeout(() => {
|
|
|
|
window.dispatchEvent(new Event('resize'))
|
|
|
|
}, 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-07-28 04:41:55 -07:00
|
|
|
<>
|
|
|
|
{loadingMangoAccount && isOnboarded ? (
|
|
|
|
<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">
|
|
|
|
{isMobile ? (
|
|
|
|
<div className="fixed bottom-0 left-0 z-20 w-full md:hidden">
|
|
|
|
<BottomBar />
|
2022-07-26 19:45:27 -07:00
|
|
|
</div>
|
2022-07-28 04:41:55 -07:00
|
|
|
) : (
|
|
|
|
<div className={`fixed z-20 h-screen`}>
|
|
|
|
<button
|
|
|
|
className="absolute -right-4 top-1/2 z-20 hidden h-10 w-4 -translate-y-1/2 transform rounded-none rounded-r bg-th-bkg-4 focus:outline-none lg:block"
|
|
|
|
onClick={handleToggleSidebar}
|
|
|
|
>
|
|
|
|
<ChevronRightIcon
|
|
|
|
className={`default-transition 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 ${
|
2022-08-11 03:49:16 -07:00
|
|
|
isMobile ? '' : isCollapsed ? 'pl-[64px]' : 'pl-44 lg:pl-56'
|
2022-07-28 04:41:55 -07:00
|
|
|
}`}
|
|
|
|
>
|
2022-08-03 04:16:30 -07:00
|
|
|
<div className="flex h-16 items-center justify-between border-b border-th-bkg-3 bg-th-bkg-1 px-6 md:px-8">
|
2022-07-28 04:41:55 -07:00
|
|
|
<div className="flex items-center text-th-fgd-3">
|
2022-08-03 04:16:30 -07:00
|
|
|
{isMobile ? (
|
|
|
|
<img
|
|
|
|
className={`mr-4 h-8 w-auto`}
|
|
|
|
src="/logos/logo-mark.svg"
|
|
|
|
alt="next"
|
|
|
|
/>
|
|
|
|
) : null}
|
2022-07-28 04:41:55 -07:00
|
|
|
<span className="mb-0 mr-2">
|
|
|
|
{mangoAccount ? (
|
2022-08-01 18:08:08 -07:00
|
|
|
<MangoAccountsList mangoAccount={mangoAccount} />
|
2022-08-03 04:16:30 -07:00
|
|
|
) : !isMobile ? (
|
2022-07-28 04:41:55 -07:00
|
|
|
<span className="flex items-center">
|
|
|
|
🔗<span className="ml-2">{t('connect-helper')}</span>
|
|
|
|
<ArrowRightIcon className="sideways-bounce ml-2 h-5 w-5 text-th-fgd-1" />
|
|
|
|
</span>
|
2022-08-03 04:16:30 -07:00
|
|
|
) : null}
|
2022-07-28 04:41:55 -07:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-4">
|
2022-07-26 19:45:27 -07:00
|
|
|
{mangoAccount ? (
|
2022-07-28 04:41:55 -07:00
|
|
|
<ConnectedMenu />
|
|
|
|
) : isOnboarded ? (
|
|
|
|
<ConnectWalletButton />
|
2022-07-26 19:45:27 -07:00
|
|
|
) : (
|
2022-07-28 04:41:55 -07:00
|
|
|
<button
|
|
|
|
className="relative flex h-16 items-center justify-center rounded-none bg-gradient-to-bl from-mango-theme-yellow to-mango-theme-red-dark px-6 text-base font-bold text-white before:absolute before:inset-0 before:bg-gradient-to-r before:from-transparent before:via-[rgba(255,255,255,0.25)] before:to-transparent before:opacity-0 hover:cursor-pointer hover:overflow-hidden hover:before:-translate-x-full hover:before:animate-[shimmer_0.75s_normal] hover:before:opacity-100"
|
|
|
|
onClick={handleShowModal}
|
|
|
|
>
|
|
|
|
<WalletIcon className="mr-2 h-5 w-5 flex-shrink-0" />
|
|
|
|
{t('connect')}
|
|
|
|
</button>
|
2022-07-26 19:45:27 -07:00
|
|
|
)}
|
2022-07-28 04:41:55 -07:00
|
|
|
</div>
|
2022-07-26 19:45:27 -07:00
|
|
|
</div>
|
2022-08-03 04:16:30 -07:00
|
|
|
<div className={`min-h-screen ${isMobile ? 'p-6 pb-20' : 'p-8'}`}>
|
2022-07-28 04:41:55 -07:00
|
|
|
{children}
|
2022-07-26 19:45:27 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{showUserSetupModal ? (
|
|
|
|
<UserSetupModal
|
|
|
|
isOpen={showUserSetupModal}
|
|
|
|
onClose={handleCloseModal}
|
|
|
|
/>
|
|
|
|
) : null}
|
2022-07-28 04:41:55 -07:00
|
|
|
</>
|
2022-07-26 19:45:27 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Layout
|