import React, { useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; import GroupCard from 'soapbox/components/group-card'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Input, Stack, Text } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector, useDebounce, useFeatures } from 'soapbox/hooks'; import { useGroups } from 'soapbox/hooks/api'; import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions'; import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card'; import PendingGroupsRow from './components/pending-groups-row'; import TabBar, { TabItems } from './components/tab-bar'; const messages = defineMessages({ placeholder: { id: 'groups.search.placeholder', defaultMessage: 'Search My Groups' }, }); const Groups: React.FC = () => { const debounce = useDebounce; const dispatch = useAppDispatch(); const features = useFeatures(); const intl = useIntl(); const canCreateGroup = useAppSelector((state) => hasPermission(state, PERMISSION_CREATE_GROUPS)); const [searchValue, setSearchValue] = useState(''); const debouncedValue = debounce(searchValue, 300); const { groups, isLoading } = useGroups(debouncedValue); const createGroup = () => { dispatch(openModal('CREATE_GROUP')); }; const renderBlankslate = () => ( {canCreateGroup && ( )} ); return ( {features.groupsDiscovery && ( )} {canCreateGroup && ( )} {features.groupsSearch ? ( setSearchValue(event.target.value)} placeholder={intl.formatMessage(messages.placeholder)} theme='search' value={searchValue} /> ) : null} {groups.map((group) => ( ))} ); }; export default Groups;