From c84ca30197cd02893dd98caa608e9fc74ae3bff2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 25 Aug 2020 17:24:47 -0500 Subject: [PATCH] Chats: Click chat to open pane --- .../features/chats/components/chat_list.js | 9 +++----- .../chats/components/chat_list_account.js | 9 ++++---- .../features/chats/components/chat_panes.js | 21 +++++++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/soapbox/features/chats/components/chat_list.js b/app/soapbox/features/chats/components/chat_list.js index 5ba86ad18..ca5349b20 100644 --- a/app/soapbox/features/chats/components/chat_list.js +++ b/app/soapbox/features/chats/components/chat_list.js @@ -21,16 +21,13 @@ class ChatList extends ImmutablePureComponent { static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, + onClickChat: PropTypes.func, }; componentDidMount() { this.props.dispatch(fetchChats()); } - handleClickChat = () => { - // TODO: Open or focus chat panel - } - render() { const { chats } = this.props; @@ -40,8 +37,8 @@ class ChatList extends ImmutablePureComponent { {chats.toList().map(chat => (
))} diff --git a/app/soapbox/features/chats/components/chat_list_account.js b/app/soapbox/features/chats/components/chat_list_account.js index 9864e854e..48a813fa8 100644 --- a/app/soapbox/features/chats/components/chat_list_account.js +++ b/app/soapbox/features/chats/components/chat_list_account.js @@ -8,17 +8,18 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; export default class ChatListAccount extends ImmutablePureComponent { static propTypes = { - account: ImmutablePropTypes.map.isRequired, + chat: ImmutablePropTypes.map.isRequired, onClick: PropTypes.func, }; handleClick = () => { - this.props.onClick(this.props.account); + this.props.onClick(this.props.chat); } render() { - const { account } = this.props; - if (!account) return null; + const { chat } = this.props; + if (!chat) return null; + const account = chat.get('account'); return (
diff --git a/app/soapbox/features/chats/components/chat_panes.js b/app/soapbox/features/chats/components/chat_panes.js index d99a6b371..24509002c 100644 --- a/app/soapbox/features/chats/components/chat_panes.js +++ b/app/soapbox/features/chats/components/chat_panes.js @@ -4,7 +4,7 @@ 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 } from 'soapbox/actions/settings'; +import { getSettings, changeSetting } from 'soapbox/actions/settings'; import ChatList from './chat_list'; import { FormattedMessage } from 'react-intl'; import { makeGetChat } from 'soapbox/selectors'; @@ -24,15 +24,7 @@ const addChatsToPanes = (state, panesData) => { }; const mapStateToProps = state => { - // const panesData = getSettings(state).get('chats'); - - const panesData = fromJS({ - panes: [ - { chat_id: '9ySoi8J7eTY0x78OBc', state: 'open' }, - { chat_id: '9ySoi8J7eTY0x78OBc', state: 'open' }, - { chat_id: '9ySoi8J7eTY0x78OBc', state: 'open' }, - ], - }); + const panesData = getSettings(state).get('chats'); return { panesData: addChatsToPanes(state, panesData), @@ -49,6 +41,13 @@ class ChatPanes extends ImmutablePureComponent { 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']); @@ -88,7 +87,7 @@ class ChatPanes extends ImmutablePureComponent {
- +
{this.renderChatPanes(panes)}