Chats: Click chat to open pane

loading-indicator-on-tls^2
Alex Gleason 2020-08-25 17:24:47 -05:00
rodzic 0d7a926fa5
commit c84ca30197
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 18 dodań i 21 usunięć

Wyświetl plik

@ -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 => (
<div key={chat.get('id')} className='chat-list-item'>
<ChatListAccount
account={chat.get('account')}
onClick={this.handleClickChat}
chat={chat}
onClick={this.props.onClickChat}
/>
</div>
))}

Wyświetl plik

@ -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 (
<div className='account'>

Wyświetl plik

@ -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 {
<FormattedMessage id='chat_panels.main_window.title' defaultMessage='Chats' />
</div>
<div className='pane__content'>
<ChatList />
<ChatList onClickChat={this.handleClickChat} />
</div>
</div>
{this.renderChatPanes(panes)}