pleroma/app/soapbox/features/conversations/components/conversation.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
2022-03-17 18:17:28 -07:00
import { withRouter } from 'react-router-dom';
2020-03-27 13:59:38 -07:00
import StatusContainer from '../../../containers/status_container';
2022-03-17 18:17:28 -07:00
export default @withRouter
class Conversation extends ImmutablePureComponent {
2020-03-27 13:59:38 -07:00
static propTypes = {
conversationId: PropTypes.string.isRequired,
accounts: ImmutablePropTypes.list.isRequired,
lastStatusId: PropTypes.string,
unread: PropTypes.bool.isRequired,
2020-03-27 13:59:38 -07:00
onMoveUp: PropTypes.func,
onMoveDown: PropTypes.func,
markRead: PropTypes.func.isRequired,
2022-03-17 18:17:28 -07:00
history: PropTypes.object,
2020-03-27 13:59:38 -07:00
};
handleClick = () => {
2022-03-17 18:17:28 -07:00
if (!this.props.history) {
2020-03-27 13:59:38 -07:00
return;
}
const { lastStatusId, unread, markRead } = this.props;
if (unread) {
markRead();
}
2022-03-17 18:17:28 -07:00
this.props.history.push(`/statuses/${lastStatusId}`);
2020-03-27 13:59:38 -07:00
}
handleHotkeyMoveUp = () => {
this.props.onMoveUp(this.props.conversationId);
}
handleHotkeyMoveDown = () => {
this.props.onMoveDown(this.props.conversationId);
}
render() {
2020-03-27 13:59:38 -07:00
const { accounts, lastStatusId, unread } = this.props;
if (lastStatusId === null) {
return null;
}
return (
<StatusContainer
id={lastStatusId}
unread={unread}
otherAccounts={accounts}
onMoveUp={this.handleHotkeyMoveUp}
onMoveDown={this.handleHotkeyMoveDown}
onClick={this.handleClick}
/>
);
}
}