import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { getSettings, changeSetting } from 'soapbox/actions/settings'; import ChatList from './chat_list'; import { FormattedMessage } from 'react-intl'; import { makeGetChat } from 'soapbox/selectors'; import { fromJS } from 'immutable'; import Avatar from 'soapbox/components/avatar'; import { acctFull } from 'soapbox/utils/accounts'; const addChatsToPanes = (state, panesData) => { const getChat = makeGetChat(); const newPanes = panesData.get('panes').map(pane => { const chat = getChat(state, { id: pane.get('chat_id') }); return pane.set('chat', chat); }); return panesData.set('panes', newPanes); }; const mapStateToProps = state => { const panesData = getSettings(state).get('chats'); return { panesData: addChatsToPanes(state, panesData), }; }; export default @connect(mapStateToProps) @injectIntl class ChatPanes extends ImmutablePureComponent { static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, panesData: ImmutablePropTypes.map, } handleClickChat = (chat) => { // TODO: Refactor this.props.dispatch(changeSetting(['chats', 'panes'], fromJS([ { chat_id: chat.get('id'), state: 'open' }, ]))); } renderChatPane = (pane, i) => { const chat = pane.get('chat'); const account = pane.getIn(['chat', 'account']); if (!chat || !account) return null; const right = (285 * (i + 1)) + 20; return (
@{acctFull(account)}
TODO: Show the chat messages
); } renderChatPanes = (panes) => ( panes.map((pane, i) => this.renderChatPane(pane, i) ) ) render() { const panes = this.props.panesData.get('panes'); return (
{this.renderChatPanes(panes)}
); } }