Chats: Click chat to open pane

This commit is contained in:
Alex Gleason 2020-08-25 17:54:10 -05:00
parent c84ca30197
commit f87f33fb94
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 20 additions and 6 deletions

View file

@ -1,5 +1,7 @@
import api from '../api'; import api from '../api';
import { importFetchedChats } from 'soapbox/actions/importer'; import { importFetchedChats } from 'soapbox/actions/importer';
import { getSettings, changeSetting } from 'soapbox/actions/settings';
import { Map as ImmutableMap } from 'immutable';
export const CHATS_FETCH_REQUEST = 'CHATS_FETCH_REQUEST'; export const CHATS_FETCH_REQUEST = 'CHATS_FETCH_REQUEST';
export const CHATS_FETCH_SUCCESS = 'CHATS_FETCH_SUCCESS'; export const CHATS_FETCH_SUCCESS = 'CHATS_FETCH_SUCCESS';
@ -16,3 +18,17 @@ export function fetchChats() {
}); });
}; };
} }
export function openChat(chatId) {
return (dispatch, getState) => {
const panes = getSettings(getState()).getIn(['chats', 'panes']);
const idx = panes.findIndex(pane => pane.get('chat_id') === chatId);
if (idx > -1) {
return dispatch(changeSetting(['chats', 'panes', idx, 'state'], 'open'));
} else {
const newPane = ImmutableMap({ chat_id: chatId, state: 'open' });
return dispatch(changeSetting(['chats', 'panes'], panes.push(newPane)));
}
};
}

View file

@ -4,13 +4,13 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { getSettings, changeSetting } from 'soapbox/actions/settings'; import { getSettings } from 'soapbox/actions/settings';
import ChatList from './chat_list'; import ChatList from './chat_list';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { makeGetChat } from 'soapbox/selectors'; import { makeGetChat } from 'soapbox/selectors';
import { fromJS } from 'immutable';
import Avatar from 'soapbox/components/avatar'; import Avatar from 'soapbox/components/avatar';
import { acctFull } from 'soapbox/utils/accounts'; import { acctFull } from 'soapbox/utils/accounts';
import { openChat } from 'soapbox/actions/chats';
const addChatsToPanes = (state, panesData) => { const addChatsToPanes = (state, panesData) => {
const getChat = makeGetChat(); const getChat = makeGetChat();
@ -42,10 +42,8 @@ class ChatPanes extends ImmutablePureComponent {
} }
handleClickChat = (chat) => { handleClickChat = (chat) => {
// TODO: Refactor this.props.dispatch(openChat(chat.get('id')));
this.props.dispatch(changeSetting(['chats', 'panes'], fromJS([ // TODO: Focus chat input
{ chat_id: chat.get('id'), state: 'open' },
])));
} }
renderChatPane = (pane, i) => { renderChatPane = (pane, i) => {