From 6e0bac3d43f5727e98372cc57c5a2a102c0093da Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 25 Aug 2020 16:00:27 -0500 Subject: [PATCH] Chats: Get chats from paneData --- .../features/chats/components/chat_list.js | 2 +- .../features/chats/components/chat_panes.js | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/chats/components/chat_list.js b/app/soapbox/features/chats/components/chat_list.js index a11617d19..5ba86ad18 100644 --- a/app/soapbox/features/chats/components/chat_list.js +++ b/app/soapbox/features/chats/components/chat_list.js @@ -1,7 +1,7 @@ import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; -import { injectIntl, FormattedMessage } from 'react-intl'; +import { injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { fetchChats } from 'soapbox/actions/chats'; import ChatListAccount from './chat_list_account'; diff --git a/app/soapbox/features/chats/components/chat_panes.js b/app/soapbox/features/chats/components/chat_panes.js index cf1515152..a6b8bd36b 100644 --- a/app/soapbox/features/chats/components/chat_panes.js +++ b/app/soapbox/features/chats/components/chat_panes.js @@ -7,10 +7,33 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import { getSettings } from 'soapbox/actions/settings'; import ChatList from './chat_list'; import { FormattedMessage } from 'react-intl'; +import { makeGetChat } from 'soapbox/selectors'; +// import { fromJS } from 'immutable'; -const mapStateToProps = state => ({ - panesData: getSettings(state).get('chats'), -}); +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'); + + // const panesData = fromJS({ + // panes: [ + // { chat_id: '9ySohyWw0Gecd3WHKK', state: 'open' }, + // ], + // }); + + return { + panesData: addChatsToPanes(state, panesData), + }; +}; export default @connect(mapStateToProps) @injectIntl @@ -23,11 +46,13 @@ class ChatPanes extends ImmutablePureComponent { } renderChatPane = (pane, i) => { - // const chat = getChat(pane.get('chat_id')) + const chat = pane.get('chat'); + if (!chat) return null; + return (
- // {chat.getIn(['account', 'acct'])} + {chat.getIn(['account', 'acct'])}
// TODO: Show the chat messages