bigbuffet-rw/app/soapbox/features/chats/index.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
2021-10-14 10:23:51 -07:00
import { connect } from 'react-redux';
import Column from '../../components/column';
import ColumnHeader from '../../components/column_header';
import { fetchChats, launchChat } from 'soapbox/actions/chats';
import { defineMessages, injectIntl } from 'react-intl';
import ChatList from './components/chat_list';
import AudioToggle from 'soapbox/features/chats/components/audio_toggle';
2021-10-14 10:23:51 -07:00
import AccountSearch from 'soapbox/components/account_search';
const messages = defineMessages({
title: { id: 'column.chats', defaultMessage: 'Chats' },
2021-10-14 10:23:51 -07:00
searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Start a chat with…' },
});
2021-10-14 10:23:51 -07:00
export default @connect()
@injectIntl
class ChatIndex extends React.PureComponent {
2021-10-14 10:23:51 -07:00
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
intl: PropTypes.object.isRequired,
2021-10-14 10:23:51 -07:00
dispatch: PropTypes.func.isRequired,
};
2021-10-14 10:23:51 -07:00
handleSuggestion = accountId => {
this.props.dispatch(launchChat(accountId, this.context.router.history, true));
}
handleClickChat = (chat) => {
this.context.router.history.push(`/chats/${chat.get('id')}`);
}
handleRefresh = () => {
const { dispatch } = this.props;
return dispatch(fetchChats());
}
render() {
const { intl } = this.props;
return (
<Column label={intl.formatMessage(messages.title)}>
<ColumnHeader
icon='comment'
title={intl.formatMessage(messages.title)}
/>
2021-10-14 10:23:51 -07:00
<div className='column__switch'>
<AudioToggle />
</div>
<AccountSearch
placeholder={intl.formatMessage(messages.searchPlaceholder)}
onSelected={this.handleSuggestion}
/>
<ChatList
onClickChat={this.handleClickChat}
onRefresh={this.handleRefresh}
/>
</Column>
);
}
}