import clsx from 'clsx'; import React, { useCallback, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; import { useSuggestedGroups } from 'soapbox/api/hooks'; import { Column } from 'soapbox/components/ui'; import GroupGridItem from './components/discover/group-grid-item'; import GroupListItem from './components/discover/group-list-item'; import LayoutButtons, { GroupLayout } from './components/discover/layout-buttons'; import type { Group } from 'soapbox/schemas'; const messages = defineMessages({ label: { id: 'groups.suggested.label', defaultMessage: 'Suggested Groups' }, }); const GridList: Components['List'] = React.forwardRef((props, ref) => { const { context, ...rest } = props; return
; }); const Suggested: React.FC = () => { const intl = useIntl(); const [layout, setLayout] = useState(GroupLayout.LIST); const { groups, hasNextPage, fetchNextPage } = useSuggestedGroups(); const handleLoadMore = () => { if (hasNextPage) { fetchNextPage(); } }; const renderGroupList = useCallback((group: Group, index: number) => (
), []); const renderGroupGrid = useCallback((group: Group) => ( ), []); return ( setLayout(selectedLayout)} /> } > {layout === GroupLayout.LIST ? ( renderGroupList(group, index)} endReached={handleLoadMore} /> ) : ( renderGroupGrid(group)} components={{ Item: (props) => (
), List: GridList, }} endReached={handleLoadMore} /> )} ); }; export default Suggested;