2023-02-27 05:25:59 -08:00
|
|
|
import React from 'react';
|
2022-12-15 14:51:30 -08:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2022-12-14 08:41:16 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
2022-12-18 09:03:41 -08:00
|
|
|
import { openModal } from 'soapbox/actions/modals';
|
2022-12-15 14:51:30 -08:00
|
|
|
import GroupCard from 'soapbox/components/group-card';
|
2022-12-14 08:41:16 -08:00
|
|
|
import ScrollableList from 'soapbox/components/scrollable-list';
|
2023-02-27 05:25:59 -08:00
|
|
|
import { Button, Stack, Text } from 'soapbox/components/ui';
|
2023-03-09 09:21:27 -08:00
|
|
|
import { useAppDispatch, useAppSelector, useGroups, useFeatures } from 'soapbox/hooks';
|
2022-12-18 09:18:26 -08:00
|
|
|
import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions';
|
2022-12-14 08:41:16 -08:00
|
|
|
|
2022-12-17 05:31:23 -08:00
|
|
|
import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card';
|
|
|
|
|
2023-03-08 10:22:10 -08:00
|
|
|
import PendingGroupsRow from './components/pending-groups-row';
|
2023-02-27 05:25:59 -08:00
|
|
|
import TabBar, { TabItems } from './components/tab-bar';
|
|
|
|
|
2022-12-15 14:51:30 -08:00
|
|
|
import type { Group as GroupEntity } from 'soapbox/types/entities';
|
2022-12-14 08:41:16 -08:00
|
|
|
|
2022-12-16 15:33:07 -08:00
|
|
|
const Groups: React.FC = () => {
|
2023-01-27 14:04:42 -08:00
|
|
|
const dispatch = useAppDispatch();
|
2023-02-27 05:25:59 -08:00
|
|
|
const features = useFeatures();
|
2022-12-14 08:41:16 -08:00
|
|
|
|
2022-12-19 05:10:13 -08:00
|
|
|
const canCreateGroup = useAppSelector((state) => hasPermission(state, PERMISSION_CREATE_GROUPS));
|
2022-12-14 08:41:16 -08:00
|
|
|
|
2023-02-27 05:25:59 -08:00
|
|
|
const { groups, isLoading } = useGroups();
|
2022-12-14 08:41:16 -08:00
|
|
|
|
2022-12-18 09:03:41 -08:00
|
|
|
const createGroup = () => {
|
|
|
|
dispatch(openModal('MANAGE_GROUP'));
|
|
|
|
};
|
|
|
|
|
2023-03-07 09:05:24 -08:00
|
|
|
const renderBlankslate = () => (
|
|
|
|
<Stack space={4} alignItems='center' justifyContent='center' className='py-6'>
|
|
|
|
<Stack space={2} className='max-w-sm'>
|
|
|
|
<Text size='2xl' weight='bold' tag='h2' align='center'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='groups.empty.title'
|
|
|
|
defaultMessage='No Groups yet'
|
|
|
|
/>
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<Text size='sm' theme='muted' align='center'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='groups.empty.subtitle'
|
|
|
|
defaultMessage='Start discovering groups to join or create your own.'
|
|
|
|
/>
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
{canCreateGroup && (
|
|
|
|
<Button
|
|
|
|
className='self-center'
|
|
|
|
onClick={createGroup}
|
|
|
|
theme='secondary'
|
|
|
|
>
|
|
|
|
<FormattedMessage id='new_group_panel.action' defaultMessage='Create Group' />
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
|
2022-12-14 08:41:16 -08:00
|
|
|
return (
|
2023-02-27 05:25:59 -08:00
|
|
|
<Stack space={4}>
|
2022-12-19 05:10:13 -08:00
|
|
|
{canCreateGroup && (
|
2022-12-18 09:18:26 -08:00
|
|
|
<Button
|
|
|
|
className='sm:w-fit sm:self-end xl:hidden'
|
|
|
|
icon={require('@tabler/icons/circles.svg')}
|
|
|
|
onClick={createGroup}
|
|
|
|
theme='secondary'
|
|
|
|
block
|
|
|
|
>
|
2023-02-27 05:25:59 -08:00
|
|
|
<FormattedMessage id='new_group_panel.action' defaultMessage='Create Group' />
|
2022-12-18 09:18:26 -08:00
|
|
|
</Button>
|
|
|
|
)}
|
2023-02-27 05:25:59 -08:00
|
|
|
|
|
|
|
{features.groupsDiscovery && (
|
|
|
|
<TabBar activeTab={TabItems.MY_GROUPS} />
|
|
|
|
)}
|
|
|
|
|
2023-03-08 10:22:10 -08:00
|
|
|
<PendingGroupsRow />
|
|
|
|
|
2022-12-18 09:03:41 -08:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='groups'
|
2023-03-07 09:05:24 -08:00
|
|
|
emptyMessage={renderBlankslate()}
|
|
|
|
emptyMessageCard={false}
|
2023-03-08 10:22:10 -08:00
|
|
|
itemClassName='pb-4 last:pb-0'
|
2022-12-18 09:03:41 -08:00
|
|
|
isLoading={isLoading}
|
2023-02-27 05:25:59 -08:00
|
|
|
showLoading={isLoading && groups.length === 0}
|
2022-12-18 09:03:41 -08:00
|
|
|
placeholderComponent={PlaceholderGroupCard}
|
|
|
|
placeholderCount={3}
|
|
|
|
>
|
|
|
|
{groups.map((group) => (
|
|
|
|
<Link key={group.id} to={`/groups/${group.id}`}>
|
|
|
|
<GroupCard group={group as GroupEntity} />
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</ScrollableList>
|
|
|
|
</Stack>
|
2022-12-14 08:41:16 -08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-16 15:33:07 -08:00
|
|
|
export default Groups;
|