2023-06-08 06:00:49 -07:00
|
|
|
import React, { useState } from 'react';
|
2022-04-11 12:58:48 -07:00
|
|
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
|
|
|
|
2023-06-08 06:00:49 -07:00
|
|
|
import { useMutes, useGroupMutes } from 'soapbox/api/hooks';
|
2022-11-15 08:00:49 -08:00
|
|
|
import ScrollableList from 'soapbox/components/scrollable-list';
|
2023-06-08 06:00:49 -07:00
|
|
|
import { Column, Stack, Tabs } from 'soapbox/components/ui';
|
|
|
|
import AccountContainer from 'soapbox/containers/account-container';
|
|
|
|
import { useFeatures } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
import GroupListItem from './components/group-list-item';
|
2022-04-11 12:58:48 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2023-06-08 06:00:49 -07:00
|
|
|
heading: { id: 'column.mutes', defaultMessage: 'Mutes' },
|
2022-04-11 12:58:48 -07:00
|
|
|
});
|
|
|
|
|
2023-06-08 06:00:49 -07:00
|
|
|
enum TabItems {
|
|
|
|
ACCOUNTS = 'ACCOUNTS',
|
|
|
|
GROUPS = 'GROUPS'
|
|
|
|
}
|
|
|
|
|
2022-04-11 12:58:48 -07:00
|
|
|
const Mutes: React.FC = () => {
|
|
|
|
const intl = useIntl();
|
2023-06-08 06:00:49 -07:00
|
|
|
const features = useFeatures();
|
2022-04-11 12:58:48 -07:00
|
|
|
|
2023-06-25 15:48:19 -07:00
|
|
|
const {
|
|
|
|
accounts,
|
2023-06-08 06:00:49 -07:00
|
|
|
hasNextPage: hasNextAccountsPage,
|
|
|
|
fetchNextPage: fetchNextAccounts,
|
|
|
|
isLoading: isLoadingAccounts,
|
2023-06-26 09:22:02 -07:00
|
|
|
} = useMutes();
|
2022-04-11 12:58:48 -07:00
|
|
|
|
2023-06-08 06:00:49 -07:00
|
|
|
const {
|
|
|
|
mutes: groupMutes,
|
|
|
|
isLoading: isLoadingGroups,
|
|
|
|
hasNextPage: hasNextGroupsPage,
|
|
|
|
fetchNextPage: fetchNextGroups,
|
|
|
|
fetchEntities: fetchMutedGroups,
|
|
|
|
} = useGroupMutes();
|
2022-04-11 12:58:48 -07:00
|
|
|
|
2023-06-08 06:00:49 -07:00
|
|
|
const [activeItem, setActiveItem] = useState<TabItems>(TabItems.ACCOUNTS);
|
|
|
|
const isAccountsTabSelected = activeItem === TabItems.ACCOUNTS;
|
|
|
|
|
|
|
|
const scrollableListProps = {
|
|
|
|
itemClassName: 'pb-4 last:pb-0',
|
|
|
|
scrollKey: 'mutes',
|
|
|
|
emptyMessageCard: false,
|
|
|
|
};
|
2022-04-11 12:58:48 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Column label={intl.formatMessage(messages.heading)}>
|
2023-06-08 06:00:49 -07:00
|
|
|
<Stack space={4}>
|
|
|
|
{features.groupsMuting && (
|
|
|
|
<Tabs
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
text: 'Users',
|
|
|
|
action: () => setActiveItem(TabItems.ACCOUNTS),
|
|
|
|
name: TabItems.ACCOUNTS,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Groups',
|
|
|
|
action: () => setActiveItem(TabItems.GROUPS),
|
|
|
|
name: TabItems.GROUPS,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
activeItem={activeItem}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{isAccountsTabSelected ? (
|
|
|
|
<ScrollableList
|
|
|
|
{...scrollableListProps}
|
|
|
|
isLoading={isLoadingAccounts}
|
|
|
|
onLoadMore={fetchNextAccounts}
|
|
|
|
hasMore={hasNextAccountsPage}
|
|
|
|
emptyMessage={
|
|
|
|
<FormattedMessage id='empty_column.mutes' defaultMessage="You haven't muted any users yet." />
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{accounts.map((accounts) =>
|
|
|
|
<AccountContainer key={accounts.id} id={accounts.id} actionType='muting' />,
|
|
|
|
)}
|
|
|
|
</ScrollableList>
|
|
|
|
) : (
|
|
|
|
<ScrollableList
|
|
|
|
{...scrollableListProps}
|
|
|
|
isLoading={isLoadingGroups}
|
|
|
|
onLoadMore={fetchNextGroups}
|
|
|
|
hasMore={hasNextGroupsPage}
|
|
|
|
emptyMessage={
|
|
|
|
<FormattedMessage id='mutes.empty.groups' defaultMessage="You haven't muted any groups yet." />
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{groupMutes.map((group) =>(
|
|
|
|
<GroupListItem
|
|
|
|
group={group}
|
|
|
|
onUnmute={fetchMutedGroups}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ScrollableList>
|
|
|
|
)}
|
|
|
|
</Stack>
|
2022-04-11 12:58:48 -07:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Mutes;
|