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

82 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
2022-01-10 14:01:24 -08:00
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { directComposeById } from 'soapbox/actions/compose';
import AccountSearch from 'soapbox/components/account_search';
import StatusListContainer from '../ui/containers/status_list_container';
2020-03-27 13:59:38 -07:00
import Column from '../../components/column';
import ColumnHeader from '../../components/column_header';
import { expandDirectTimeline } from '../../actions/timelines';
2020-03-27 13:59:38 -07:00
import { connectDirectStream } from '../../actions/streaming';
const messages = defineMessages({
title: { id: 'column.direct', defaultMessage: 'Direct messages' },
searchPlaceholder: { id: 'direct.search_placeholder', defaultMessage: 'Send a message to…' },
2020-03-27 13:59:38 -07:00
});
const mapStateToProps = state => ({
hasUnread: state.getIn(['timelines', 'direct', 'unread']) > 0,
});
export default @connect(mapStateToProps)
2020-03-27 13:59:38 -07:00
@injectIntl
class DirectTimeline extends React.PureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
hasUnread: PropTypes.bool,
};
componentDidMount() {
2020-03-27 13:59:38 -07:00
const { dispatch } = this.props;
dispatch(expandDirectTimeline());
2020-03-27 13:59:38 -07:00
this.disconnect = dispatch(connectDirectStream());
}
componentWillUnmount() {
2020-03-27 13:59:38 -07:00
if (this.disconnect) {
this.disconnect();
this.disconnect = null;
}
}
handleSuggestion = accountId => {
this.props.dispatch(directComposeById(accountId));
}
2020-03-27 13:59:38 -07:00
handleLoadMore = maxId => {
this.props.dispatch(expandDirectTimeline({ maxId }));
2020-03-27 13:59:38 -07:00
}
render() {
2020-03-27 13:59:38 -07:00
const { intl, hasUnread } = this.props;
return (
<Column label={intl.formatMessage(messages.title)} transparent>
<ColumnHeader
icon='envelope'
active={hasUnread}
title={intl.formatMessage(messages.title)}
onPin={this.handlePin}
/>
2020-03-27 13:59:38 -07:00
<AccountSearch
placeholder={intl.formatMessage(messages.searchPlaceholder)}
onSelected={this.handleSuggestion}
/>
<StatusListContainer
2020-03-27 13:59:38 -07:00
scrollKey='direct_timeline'
timelineId='direct'
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.direct' defaultMessage="You don't have any direct messages yet. When you send or receive one, it will show up here." />}
/>
</Column>
);
}
}