bigbuffet-rw/app/soapbox/features/chats/components/chat-settings.tsx

133 lines
5.1 KiB
TypeScript
Raw Normal View History

2022-08-17 06:58:46 -07:00
import React from 'react';
2022-09-13 13:33:34 -07:00
import { defineMessages, useIntl } from 'react-intl';
2022-08-17 06:58:46 -07:00
import { blockAccount } from 'soapbox/actions/accounts';
import { openModal } from 'soapbox/actions/modals';
import { initReport } from 'soapbox/actions/reports';
import List, { ListItem } from 'soapbox/components/list';
import { Avatar, Divider, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui';
import { useChatContext } from 'soapbox/contexts/chat-context';
import { useAppDispatch } from 'soapbox/hooks';
2022-09-16 05:57:09 -07:00
import { useChat, useChatSilence } from 'soapbox/queries/chats';
2022-08-17 06:58:46 -07:00
import ChatPaneHeader from './chat-pane-header';
2022-09-13 13:33:34 -07:00
const messages = defineMessages({
blockMessage: { id: 'chat_settings.block.message', defaultMessage: 'Blocking will prevent this profile from direct messaging you and viewing your content. You can unblock later.' },
blockHeading: { id: 'chat_settings.block.heading', defaultMessage: 'Block @{acct}' },
blockConfirm: { id: 'chat_settings.block.confirm', defaultMessage: 'Block' },
leaveMessage: { id: 'chat_settings.leave.message', defaultMessage: 'Are you sure you want to leave this chat? This conversation will be removed from your inbox.' },
leaveHeading: { id: 'chat_settings.leave.heading', defaultMessage: 'Leave Chat' },
leaveConfirm: { id: 'chat_settings.leave.confirm', defaultMessage: 'Leave Chat' },
title: { id: 'chat_settings.title', defaultMessage: 'Chat Details' },
blockUser: { id: 'chat_settings.options.block_user', defaultMessage: 'Block @{acct}' },
reportUser: { id: 'chat_settings.options.report_user', defaultMessage: 'Report @{acct}' },
leaveChat: { id: 'chat_settings.options.leave_chat', defaultMessage: 'Leave Chat' },
});
2022-08-17 06:58:46 -07:00
const ChatSettings = () => {
const dispatch = useAppDispatch();
2022-09-13 13:33:34 -07:00
const intl = useIntl();
2022-08-17 06:58:46 -07:00
const { chat, setEditing, toggleChatPane } = useChatContext();
2022-09-16 05:57:09 -07:00
const { isSilenced, handleSilence } = useChatSilence(chat);
2022-08-17 06:58:46 -07:00
const { deleteChat } = useChat(chat?.id as string);
const closeSettings = () => setEditing(false);
const minimizeChatPane = () => {
closeSettings();
toggleChatPane();
};
const handleBlockUser = () => {
dispatch(openModal('CONFIRM', {
2022-09-13 13:33:34 -07:00
heading: intl.formatMessage(messages.blockHeading, { acct: chat?.account.acct }),
message: intl.formatMessage(messages.blockMessage),
confirm: intl.formatMessage(messages.blockConfirm),
2022-08-17 06:58:46 -07:00
confirmationTheme: 'primary',
2022-09-08 09:47:19 -07:00
onConfirm: () => dispatch(blockAccount(chat?.account.id as string)),
2022-08-17 06:58:46 -07:00
}));
};
const handleLeaveChat = () => {
dispatch(openModal('CONFIRM', {
2022-09-13 13:33:34 -07:00
heading: intl.formatMessage(messages.leaveHeading),
message: intl.formatMessage(messages.leaveMessage),
confirm: intl.formatMessage(messages.leaveConfirm),
2022-08-17 06:58:46 -07:00
confirmationTheme: 'primary',
2022-09-13 13:33:34 -07:00
onConfirm: () => deleteChat.mutate(),
2022-08-17 06:58:46 -07:00
}));
};
2022-09-13 13:33:34 -07:00
const handleReportChat = () => dispatch(initReport(chat?.account as any));
2022-08-17 06:58:46 -07:00
if (!chat) {
return null;
}
return (
<>
<ChatPaneHeader
isOpen
isToggleable={false}
onToggle={minimizeChatPane}
title={
<HStack alignItems='center' space={2}>
<button onClick={closeSettings}>
<Icon
src={require('@tabler/icons/arrow-left.svg')}
className='h-6 w-6 text-gray-600 dark:text-gray-400'
/>
</button>
<Text weight='semibold'>
2022-09-13 13:33:34 -07:00
{intl.formatMessage(messages.title)}
2022-08-17 06:58:46 -07:00
</Text>
</HStack>
}
/>
<Stack space={4} className='w-5/6 mx-auto'>
<Stack alignItems='center' space={2}>
<Avatar src={chat.account.avatar_static} size={75} />
<Stack>
<Text size='lg' weight='semibold' align='center'>{chat.account.display_name}</Text>
<Text theme='primary' align='center'>@{chat.account.acct}</Text>
</Stack>
</Stack>
<Divider />
<List>
2022-08-29 12:05:16 -07:00
<ListItem label='Silence notifications'>
<Toggle checked={isSilenced} onChange={handleSilence} />
2022-08-17 06:58:46 -07:00
</ListItem>
</List>
<Divider />
<Stack space={5}>
<button onClick={handleBlockUser} className='w-full flex items-center space-x-2 font-bold text-sm text-gray-700'>
<Icon src={require('@tabler/icons/ban.svg')} className='w-5 h-5 text-gray-600' />
2022-09-13 13:33:34 -07:00
<span>{intl.formatMessage(messages.blockUser, { acct: chat.account.acct })}</span>
2022-08-17 06:58:46 -07:00
</button>
<button onClick={handleReportChat} className='w-full flex items-center space-x-2 font-bold text-sm text-gray-700'>
<Icon src={require('@tabler/icons/flag.svg')} className='w-5 h-5 text-gray-600' />
2022-09-13 13:33:34 -07:00
<span>{intl.formatMessage(messages.reportUser, { acct: chat.account.acct })}</span>
2022-08-17 06:58:46 -07:00
</button>
<button onClick={handleLeaveChat} className='w-full flex items-center space-x-2 font-bold text-sm text-danger-600'>
<Icon src={require('@tabler/icons/logout.svg')} className='w-5 h-5 text-danger-600' />
2022-09-13 13:33:34 -07:00
<span>{intl.formatMessage(messages.leaveChat)}</span>
2022-08-17 06:58:46 -07:00
</button>
</Stack>
</Stack>
</>
);
};
export default ChatSettings;