import SideNav from './SideNav' import { ReactNode, useCallback, useEffect } from 'react' import { ChevronRightIcon } from '@heroicons/react/20/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' import useLocalStorageState from '../hooks/useLocalStorageState' import { SIDEBAR_COLLAPSE_KEY } from '../utils/constants' import { useWallet } from '@solana/wallet-adapter-react' import SwapSuccessParticles from './swap/SwapSuccessParticles' import { tsParticles } from 'tsparticles-engine' import { loadFull } from 'tsparticles' const sideBarAnimationDuration = 500 const Layout = ({ children }: { children: ReactNode }) => { const { connected } = useWallet() const loadingMangoAccount = mangoStore((s) => s.mangoAccount.initialLoad) const [isCollapsed, setIsCollapsed] = useLocalStorageState( SIDEBAR_COLLAPSE_KEY, false ) const { width } = useViewport() useEffect(() => { if (width < breakpoints.lg) { setIsCollapsed(true) } }, [width]) useEffect(() => { const animationFrames = 15 for (let x = 1; x <= animationFrames; x++) { setTimeout(() => { window.dispatchEvent(new Event('resize')) }, (sideBarAnimationDuration / animationFrames) * x) } }, [isCollapsed]) const handleToggleSidebar = () => { setIsCollapsed(!isCollapsed) } const particlesInit = useCallback(async () => { await loadFull(tsParticles) }, []) useEffect(() => { particlesInit() }, []) return ( <>
{connected && loadingMangoAccount ? (
) : null}
{children}
) } export default Layout