import clsx from 'clsx' import { useRouter } from 'next/router' import { DaoDropdownProps } from '@dao-dao/types/components/DaoDropdown' import { toAccessibleImageUrl } from '@dao-dao/utils' import { useDaoNavHelpers } from '../../hooks' import { Collapsible } from '../Collapsible' import { Tooltip } from '../tooltip/Tooltip' export const DaoDropdown = ({ dao: { coreAddress, imageUrl, name, subDaos }, children, showSubDaos = true, indent = 0, compact = false, LinkWrapper, ...props }: DaoDropdownProps) => { const { asPath } = useRouter() const { getDaoPath } = useDaoNavHelpers() const href = getDaoPath(coreAddress) // Ensure no more alphanumeric characters follow DAO address in URL. This // regex should look something like `^/dao/cosmos\b.*`, to ensure that DAOs // whose addresses are prefixes of other DAO addresses do not match. This // ensures that a chain x/gov DAO does not show as selected when a DAO on that // chain is selected, since a DAO's address prefix may start with the name of // the chain x/gov DAO itself. const selected = new RegExp(`^${href}\\b.*`).test(asPath) // If compact, just show image. return compact ? (
) : ( {!!((showSubDaos && subDaos?.length) || children) && ( <> {children} {showSubDaos && subDaos?.map((dao, index) => ( ))} )} ) }