pleroma/app/soapbox/features/chats/components/chat_panes.js

99 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-08-25 12:58:35 -07:00
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-08-25 15:24:47 -07:00
import { getSettings, changeSetting } from 'soapbox/actions/settings';
2020-08-25 12:58:35 -07:00
import ChatList from './chat_list';
import { FormattedMessage } from 'react-intl';
2020-08-25 14:00:27 -07:00
import { makeGetChat } from 'soapbox/selectors';
2020-08-25 15:07:07 -07:00
import { fromJS } from 'immutable';
import Avatar from 'soapbox/components/avatar';
import { acctFull } from 'soapbox/utils/accounts';
2020-08-25 12:58:35 -07:00
2020-08-25 14:00:27 -07:00
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 => {
2020-08-25 15:24:47 -07:00
const panesData = getSettings(state).get('chats');
2020-08-25 14:00:27 -07:00
return {
panesData: addChatsToPanes(state, panesData),
};
};
2020-08-25 12:58:35 -07:00
export default @connect(mapStateToProps)
@injectIntl
class ChatPanes extends ImmutablePureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
panesData: ImmutablePropTypes.map,
}
2020-08-25 15:24:47 -07:00
handleClickChat = (chat) => {
// TODO: Refactor
this.props.dispatch(changeSetting(['chats', 'panes'], fromJS([
{ chat_id: chat.get('id'), state: 'open' },
])));
}
2020-08-25 12:58:35 -07:00
renderChatPane = (pane, i) => {
2020-08-25 14:00:27 -07:00
const chat = pane.get('chat');
2020-08-25 15:07:07 -07:00
const account = pane.getIn(['chat', 'account']);
if (!chat || !account) return null;
const right = (285 * (i + 1)) + 20;
2020-08-25 14:00:27 -07:00
2020-08-25 12:58:35 -07:00
return (
2020-08-25 15:07:07 -07:00
<div key={i} className='pane' style={{ right: `${right}px` }}>
2020-08-25 12:58:35 -07:00
<div className='pane__header'>
2020-08-25 15:07:07 -07:00
<Avatar account={account} size={18} />
<div className='display-name__account'>@{acctFull(account)}</div>
2020-08-25 12:58:35 -07:00
</div>
<div className='pane__content'>
2020-08-25 15:07:07 -07:00
<div style={{ padding: '10px' }}>TODO: Show the chat messages</div>
2020-08-25 12:58:35 -07:00
<div className='pane__actions'>
2020-08-25 15:07:07 -07:00
<input type='text' placeholder='Send a message...' />
2020-08-25 12:58:35 -07:00
</div>
</div>
</div>
);
}
renderChatPanes = (panes) => (
panes.map((pane, i) =>
this.renderChatPane(pane, i)
)
)
render() {
const panes = this.props.panesData.get('panes');
return (
<div className='chat-panes'>
<div className='pane pane--main'>
<div className='pane__header'>
<FormattedMessage id='chat_panels.main_window.title' defaultMessage='Chats' />
</div>
<div className='pane__content'>
2020-08-25 15:24:47 -07:00
<ChatList onClickChat={this.handleClickChat} />
2020-08-25 12:58:35 -07:00
</div>
</div>
{this.renderChatPanes(panes)}
</div>
);
}
}