import { DescriptionOutlined, HowToVote, Link, LockOutlined, PeopleOutlined, Public, Search, WarningRounded, } from '@mui/icons-material' import clsx from 'clsx' import { ComponentType, useState } from 'react' import { useTranslation } from 'react-i18next' import { DaoDaoIndexerAllStats, LazyDaoCardProps, LoadingData, LoadingDataWithError, StatefulDaoCardProps, } from '@dao-dao/types' import { UNDO_PAGE_PADDING_HORIZONTAL_CLASSES, UNDO_PAGE_PADDING_TOP_CLASSES, } from '@dao-dao/utils' import { Button, DaoCardLoader, DaoInfoCards, ErrorPage, GridCardContainer, HorizontalScroller, NoContent, SearchBar, SegmentedControls, } from '../components' import { UseInfiniteScrollReturn } from '../hooks' export type HomeProps = { /** * The stats. */ stats: DaoDaoIndexerAllStats /** * The DAO card to render. */ DaoCard: ComponentType /** * Optionally show chain x/gov DAO cards. */ chainGovDaos?: LoadingData /** * Featured DAO cards to display on the home page. */ featuredDaos: LoadingData /** * DAO search stuff. * * Only defined if search should be shown. */ search?: { /** * The lazy DAO card to render. */ LazyDaoCard: ComponentType /** * DAOs to show in searchable list. */ searchedDaos: LoadingDataWithError /** * Whether or not there are more DAOs to load. */ hasMore: boolean /** * Count of hits found. */ totalHits?: number /** * Search query. * * Only defined if search should be shown. */ query: string /** * Function to set the search query. * * Only defined if search should be shown. */ setQuery: (query: string) => void } & UseInfiniteScrollReturn /** * Function to open the search modal. */ openSearch: () => void } type StatsMode = 'all' | 'month' | 'week' export const Home = ({ stats, DaoCard, chainGovDaos, featuredDaos, search, openSearch, }: HomeProps) => { const { t } = useTranslation() const [statsMode, setStatsMode] = useState('all') return (
className="w-max" onSelect={setStatsMode} selected={statsMode} tabs={[ { label: t('title.all'), value: 'all', }, { label: '30d', value: 'month', }, { label: '7d', value: 'week', }, ]} /> 1 ? [ { Icon: Link, label: t('title.chains'), tooltip: t('info.chainsDeployedTooltip'), value: stats.chains.toLocaleString(), }, ] : []), ] : []), ]} className="-mt-4" valueClassName="text-text-interactive-valid font-semibold font-mono" wrap /> {/* Chain governance DAOs */} {chainGovDaos && (

{t('title.chainGovernance')}

0) && UNDO_PAGE_PADDING_HORIZONTAL_CLASSES )} contentContainerClassName="px-6" itemClassName="w-64" items={chainGovDaos} shadowClassName="w-6" />
)} {/* Featured DAOs */} {(featuredDaos.loading || featuredDaos.data.length > 0) && (

{t('title.featuredDaos')}

0) && UNDO_PAGE_PADDING_HORIZONTAL_CLASSES )} contentContainerClassName="px-6" itemClassName="w-64" items={featuredDaos} shadowClassName="w-6" />
)} {/* DAO search */} {search && (

{t('title.allDaos')}

search.setQuery(e.currentTarget.value)} placeholder={t('info.searchForDao')} value={search.query} /> {search.searchedDaos.errored ? ( ) : search.searchedDaos.loading || search.searchedDaos.data.length > 0 ? ( <> {!!search.totalHits && (

{search.totalHits === 1000 ? t('info.atLeastNumDaosFound', { count: search.totalHits, }) : t('info.numDaosFound', { count: search.totalHits, })}

)} {search.searchedDaos.loading ? ( [...Array(3)].map((_, index) => ) ) : ( <> {search.searchedDaos.data.map((props) => ( ))} {search.hasMore && [...Array(3)].map((_, index) => ( ))} )} ) : ( )}
)}
) }