import clsx from 'clsx'; import React, { useCallback, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui'; import { useGroupSearch } from 'soapbox/queries/groups/search'; import { Group } from 'soapbox/types/entities'; import { shortNumberFormat } from 'soapbox/utils/numbers'; import GroupComp from '../group'; interface Props { groupSearchResult: ReturnType } enum Layout { LIST = 'LIST', GRID = 'GRID' } const GridList: Components['List'] = React.forwardRef((props, ref) => { const { context, ...rest } = props; return
; }); export default (props: Props) => { const { groupSearchResult } = props; const [layout, setLayout] = useState(Layout.LIST); const { groups, hasNextPage, isFetching, fetchNextPage } = groupSearchResult; const handleLoadMore = () => { if (hasNextPage && !isFetching) { fetchNextPage(); } }; const renderGroupList = useCallback((group: Group, index: number) => ( {group.locked ? ( ) : ( )} {typeof group.members_count !== 'undefined' && ( <> {shortNumberFormat(group.members_count)} {' '} )} ), []); const renderGroupGrid = useCallback((group: Group, index: number) => (
), []); return ( {layout === Layout.LIST ? ( renderGroupList(group, index)} endReached={handleLoadMore} /> ) : ( renderGroupGrid(group, index)} components={{ Item: (props) => (
), List: GridList, }} endReached={handleLoadMore} /> )} ); };