import { HowToVoteRounded } from '@mui/icons-material' import clsx from 'clsx' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { ProposalListProps } from '@dao-dao/types' import { useInfiniteScroll } from '../../hooks' import { Button } from '../buttons' import { Collapsible } from '../Collapsible' import { ErrorPage } from '../error' import { SearchBar } from '../inputs' import { LineLoaders } from '../LineLoader' import { NoContent } from '../NoContent' import { VetoableProposals } from './VetoableProposals' export const ProposalList = ({ openProposals, daosWithVetoableProposals, sections, error, createNewProposalHref, canLoadMore, loadMore, loadingMore, placeholderLoaders = 20, isMember, daoName, ProposalLine, DiscordNotifierConfigureModal, LinkWrapper, searchBarProps, showingSearchResults, className, hideTitle, hideProposalIds, }: ProposalListProps) => { const { t } = useTranslation() const proposalsExist = openProposals.length > 0 || daosWithVetoableProposals.length > 0 || sections.some((section) => section.proposals.length > 0) // Only show load more and infinite scroll if the last collapsible section is // open (probably history). const [lastCollapsibleSectionOpen, setLastCollapsibleSectionOpen] = useState( sections.length === 0 || !sections[sections.length - 1].defaultCollapsed ) // Infinite scroll by loading more when scrolled near bottom. const { infiniteScrollRef } = useInfiniteScroll({ loadMore, disabled: !lastCollapsibleSectionOpen || !canLoadMore || loadingMore, }) return (
{!hideTitle && (

{t('title.proposals')}

{DiscordNotifierConfigureModal && }
)} {searchBarProps && ( )} {proposalsExist ? (
{openProposals.length > 0 && (
{openProposals.map( (props) => !hideProposalIds?.includes(props.proposalId) && ( ) )}
)} {daosWithVetoableProposals.length > 0 && ( )} {sections.length > 0 && (
{sections.map( ({ title, proposals, total, defaultCollapsed }, index) => proposals.length > 0 && ( {proposals.map( (props) => !hideProposalIds?.includes(props.proposalId) && ( ) )} ) )}
)} {(canLoadMore || loadingMore) && lastCollapsibleSectionOpen && (
)}
) : // If loading but no proposals are loaded yet, show placeholders. loadingMore ? ( ) : error ? ( ) : ( )}
) }