import { WarningRounded } from '@mui/icons-material' import Fuse from 'fuse.js' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { FilterFn, LazyDaoCardProps, TypedOption, WalletDaosProps, } from '@dao-dao/types' import { useButtonPopupFilter, useSearchFilter } from '../../hooks' import { DaoCardLoader } from '../dao/DaoCard' import { ErrorPage } from '../error' import { GridCardContainer } from '../GridCardContainer' import { SearchBar } from '../inputs' import { NoContent } from '../NoContent' import { ButtonPopup } from '../popup/ButtonPopup' export const WalletDaos = ({ daos, LazyDaoCard, openSearch, includesFollowing, }: WalletDaosProps) => { const { t } = useTranslation() const allDaos = daos.loading || daos.errored || !daos.data ? [] : daos.data const filterOptions = useMemo( (): TypedOption>[] => [ { label: t('title.following'), value: ({ isFollowed }) => isFollowed, }, { label: t('title.membership'), value: ({ isMember }) => isMember, }, { label: t('title.all'), value: () => true, }, ], [t] ) const { filteredData: filteredDaos, buttonPopupProps: filterDaosButtonProps, } = useButtonPopupFilter({ data: allDaos, options: filterOptions, }) const { searchBarProps, filteredData: searchedDaos } = useSearchFilter({ data: filteredDaos, filterableKeys: FILTERABLE_KEYS, querySyncedParam: 'dq', }) return (
{includesFollowing && ( )}
{daos.loading ? ( {[...Array(6)].map((_, index) => ( ))} ) : daos.errored ? ( ) : searchedDaos.length > 0 ? ( {searchedDaos.map(({ item }) => ( ))} ) : ( )}
) } const FILTERABLE_KEYS: Fuse.FuseOptionKey[] = [ 'info.chainId', 'info.coreAddress', 'info.name', 'info.description', ]