2022-04-12 09:52:56 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
|
2022-04-15 13:19:34 -07:00
|
|
|
import { launchChat } from 'soapbox/actions/chats';
|
2022-04-12 09:52:56 -07:00
|
|
|
import AccountSearch from 'soapbox/components/account_search';
|
|
|
|
|
2022-08-31 10:05:01 -07:00
|
|
|
import { Card, CardTitle, Stack } from '../../components/ui';
|
2022-04-12 09:52:56 -07:00
|
|
|
|
2022-06-17 15:40:43 -07:00
|
|
|
import ChatList from './components/chat-list';
|
2022-04-12 09:52:56 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2022-08-30 11:08:04 -07:00
|
|
|
title: { id: 'column.chats', defaultMessage: 'Messages' },
|
2022-04-12 09:52:56 -07:00
|
|
|
searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Start a chat with…' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const ChatIndex: React.FC = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const handleSuggestion = (accountId: string) => {
|
|
|
|
dispatch(launchChat(accountId, history, true));
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickChat = (chat: { id: string }) => {
|
|
|
|
history.push(`/chats/${chat.id}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-08-31 10:05:01 -07:00
|
|
|
<Card className='p-0' variant='rounded'>
|
2022-08-30 11:34:21 -07:00
|
|
|
<div className='grid grid-cols-9'>
|
2022-08-31 10:05:01 -07:00
|
|
|
<Stack className='col-span-3 p-6 bg-gradient-to-r from-white to-gray-100' space={6}>
|
|
|
|
<CardTitle title={intl.formatMessage(messages.title)} />
|
2022-08-30 11:34:21 -07:00
|
|
|
|
|
|
|
<AccountSearch
|
|
|
|
placeholder={intl.formatMessage(messages.searchPlaceholder)}
|
|
|
|
onSelected={handleSuggestion}
|
|
|
|
/>
|
|
|
|
|
2022-08-31 10:05:01 -07:00
|
|
|
<div className='-mx-3'>
|
|
|
|
<ChatList
|
|
|
|
onClickChat={handleClickChat}
|
|
|
|
useWindowScroll
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-30 11:34:21 -07:00
|
|
|
</Stack>
|
|
|
|
<Stack className='col-span-6'>Message area</Stack>
|
2022-04-12 09:52:56 -07:00
|
|
|
</div>
|
2022-08-31 10:05:01 -07:00
|
|
|
</Card>
|
2022-04-12 09:52:56 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChatIndex;
|