Chats: Click chat to open pane

loading-indicator-on-tls^2
Alex Gleason 2020-08-25 17:54:10 -05:00
rodzic c84ca30197
commit f87f33fb94
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 20 dodań i 6 usunięć

Wyświetl plik

@ -1,5 +1,7 @@
import api from '../api';
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_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)));
}
};
}

Wyświetl plik

@ -4,13 +4,13 @@ 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 { getSettings } 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';
import { openChat } from 'soapbox/actions/chats';
const addChatsToPanes = (state, panesData) => {
const getChat = makeGetChat();
@ -42,10 +42,8 @@ class ChatPanes extends ImmutablePureComponent {
}
handleClickChat = (chat) => {
// TODO: Refactor
this.props.dispatch(changeSetting(['chats', 'panes'], fromJS([
{ chat_id: chat.get('id'), state: 'open' },
])));
this.props.dispatch(openChat(chat.get('id')));
// TODO: Focus chat input
}
renderChatPane = (pane, i) => {