import { AddRounded, ArrowOutwardRounded, KeyboardDoubleArrowLeft, KeyboardDoubleArrowRight, TagRounded, } from '@mui/icons-material' import clsx from 'clsx' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { DaoPageMode, DaoTabId } from '@dao-dao/types' import { SdaNavigationProps } from '@dao-dao/types/components/SdaNavigation' import { MAINNET, getDaoPath as baseGetDaoPath } from '@dao-dao/utils' import { useDao } from '../../contexts' import { useDaoNavHelpers } from '../../hooks' import { DaoImage } from '../dao/DaoImage' import { IconButton, ThemeToggle } from '../icon_buttons' import { Tooltip } from '../tooltip/Tooltip' import { useAppContext } from './AppContext' import { Footer } from './Footer' import { PageHeader } from './PageHeader' import { Row } from './Row' // Width of `lg` tailwind selector. Don't change this without changing the // compact button media query class that shows the compact toggle at the very // bottom, so the user can toggle between compact and not compact mode when it // is not forced. const FORCE_COMPACT_NAVIGATION_AT_WIDTH = 1024 // Width of `md` tailwind selector. Don't change this without changing all of // the `md:` tailwind class media queries since they are set based on when it is // in responsive mobile mode. const FORCE_MOBILE_NAVIGATION_AT_WIDTH = 768 // Force off when in responsive mobile mode since it displays full width when // open and we can show all details. Force on when larger than mobile but still // not very wide since it takes up a lot of space. const getForceCompact = () => window.innerWidth < FORCE_MOBILE_NAVIGATION_AT_WIDTH ? false : window.innerWidth < FORCE_COMPACT_NAVIGATION_AT_WIDTH ? true : undefined const DAPP_URL_PREFIX = `https://${MAINNET ? '' : 'testnet.'}daodao.zone` export const SdaNavigation = ({ tabs, compact, setCompact, mountedInBrowser, LinkWrapper, SidebarWallet, }: SdaNavigationProps) => { const daoInfo = useDao() const { t } = useTranslation() const { getDaoPath, getDaoProposalPath, router: { asPath }, } = useDaoNavHelpers() const { responsiveNavigation: { enabled: responsiveEnabled, toggle: toggleResponsive, }, } = useAppContext() // Get the path to the DAO page on main DAO DAO. const daoDaoPath = asPath.startsWith(getDaoPath('')) ? asPath.replace(getDaoPath(''), baseGetDaoPath(DaoPageMode.Dapp, '')) : undefined // Use screen resize to determine when compact should be forced on or off. const [forceCompact, setForceCompact] = useState( // Initialize not compact to prevent hydration errors (since it takes at // least 1 render to update this). false ) useEffect(() => { // Only run in browser. if (typeof window === 'undefined' || !mountedInBrowser) { return } const updateForceCompact = () => setForceCompact(getForceCompact()) // Update on initialization. updateForceCompact() window.addEventListener('resize', updateForceCompact) // Clean up on umount return () => window.removeEventListener('resize', updateForceCompact) }, [mountedInBrowser]) // If forceCompact is set to a boolean, override compact. if (forceCompact !== undefined) { compact = forceCompact } return ( <> {/* Layer underneath that allows closing the responsive navigation by tapping on visible parts of the page. */} {responsiveEnabled && (
responsiveEnabled && toggleResponsive()} >
)} ) }