Chats: Click chat to open pane
This commit is contained in:
parent
0d7a926fa5
commit
c84ca30197
3 changed files with 18 additions and 21 deletions
|
@ -21,16 +21,13 @@ class ChatList extends ImmutablePureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
dispatch: PropTypes.func.isRequired,
|
dispatch: PropTypes.func.isRequired,
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
|
onClickChat: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.dispatch(fetchChats());
|
this.props.dispatch(fetchChats());
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickChat = () => {
|
|
||||||
// TODO: Open or focus chat panel
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { chats } = this.props;
|
const { chats } = this.props;
|
||||||
|
|
||||||
|
@ -40,8 +37,8 @@ class ChatList extends ImmutablePureComponent {
|
||||||
{chats.toList().map(chat => (
|
{chats.toList().map(chat => (
|
||||||
<div key={chat.get('id')} className='chat-list-item'>
|
<div key={chat.get('id')} className='chat-list-item'>
|
||||||
<ChatListAccount
|
<ChatListAccount
|
||||||
account={chat.get('account')}
|
chat={chat}
|
||||||
onClick={this.handleClickChat}
|
onClick={this.props.onClickChat}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
|
@ -8,17 +8,18 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
export default class ChatListAccount extends ImmutablePureComponent {
|
export default class ChatListAccount extends ImmutablePureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
account: ImmutablePropTypes.map.isRequired,
|
chat: ImmutablePropTypes.map.isRequired,
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
handleClick = () => {
|
handleClick = () => {
|
||||||
this.props.onClick(this.props.account);
|
this.props.onClick(this.props.chat);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { account } = this.props;
|
const { chat } = this.props;
|
||||||
if (!account) return null;
|
if (!chat) return null;
|
||||||
|
const account = chat.get('account');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='account'>
|
<div className='account'>
|
||||||
|
|
|
@ -4,7 +4,7 @@ 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 } from 'soapbox/actions/settings';
|
import { getSettings, changeSetting } 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';
|
||||||
|
@ -24,15 +24,7 @@ const addChatsToPanes = (state, panesData) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
// const panesData = getSettings(state).get('chats');
|
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' },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
panesData: addChatsToPanes(state, panesData),
|
panesData: addChatsToPanes(state, panesData),
|
||||||
|
@ -49,6 +41,13 @@ class ChatPanes extends ImmutablePureComponent {
|
||||||
panesData: ImmutablePropTypes.map,
|
panesData: ImmutablePropTypes.map,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleClickChat = (chat) => {
|
||||||
|
// TODO: Refactor
|
||||||
|
this.props.dispatch(changeSetting(['chats', 'panes'], fromJS([
|
||||||
|
{ chat_id: chat.get('id'), state: 'open' },
|
||||||
|
])));
|
||||||
|
}
|
||||||
|
|
||||||
renderChatPane = (pane, i) => {
|
renderChatPane = (pane, i) => {
|
||||||
const chat = pane.get('chat');
|
const chat = pane.get('chat');
|
||||||
const account = pane.getIn(['chat', 'account']);
|
const account = pane.getIn(['chat', 'account']);
|
||||||
|
@ -88,7 +87,7 @@ class ChatPanes extends ImmutablePureComponent {
|
||||||
<FormattedMessage id='chat_panels.main_window.title' defaultMessage='Chats' />
|
<FormattedMessage id='chat_panels.main_window.title' defaultMessage='Chats' />
|
||||||
</div>
|
</div>
|
||||||
<div className='pane__content'>
|
<div className='pane__content'>
|
||||||
<ChatList />
|
<ChatList onClickChat={this.handleClickChat} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{this.renderChatPanes(panes)}
|
{this.renderChatPanes(panes)}
|
||||||
|
|
Loading…
Reference in a new issue