dispatch/client/js/components/pages/Chat/Chat.js

127 lines
3.1 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2018-04-25 03:36:27 +00:00
import { isChannel } from 'utils';
import ChatTitle from './ChatTitle';
import Search from './Search';
import MessageBox from './MessageBox';
import MessageInput from './MessageInput';
import UserList from './UserList';
export default class Chat extends Component {
handleCloseClick = () => {
const { tab, part, closePrivateChat, disconnect } = this.props;
2018-04-25 03:36:27 +00:00
if (isChannel(tab)) {
part([tab.name], tab.server);
} else if (tab.name) {
closePrivateChat(tab.server, tab.name);
} else {
disconnect(tab.server);
}
};
handleSearch = phrase => {
const { tab, searchMessages } = this.props;
2018-04-25 03:36:27 +00:00
if (isChannel(tab)) {
searchMessages(tab.server, tab.name, phrase);
}
};
handleNickClick = nick => {
const { tab, openPrivateChat, select } = this.props;
openPrivateChat(tab.server, nick);
select(tab.server, nick);
};
handleTitleChange = title => {
const { setServerName, tab } = this.props;
setServerName(title, tab.server);
};
handleNickChange = nick => {
const { setNick, tab } = this.props;
setNick(nick, tab.server, true);
};
handleNickEditDone = nick => {
const { setNick, tab } = this.props;
setNick(nick, tab.server);
};
render() {
const {
channel,
2018-10-15 06:56:17 +00:00
coloredNicks,
currentInputHistoryEntry,
hasMoreMessages,
messages,
nick,
search,
showUserList,
status,
tab,
title,
users,
addFetchedMessages,
fetchMessages,
inputActions,
2019-01-25 02:57:58 +00:00
openModal,
runCommand,
sendMessage,
toggleSearch,
toggleUserList
} = this.props;
let chatClass;
2018-04-25 03:36:27 +00:00
if (isChannel(tab)) {
chatClass = 'chat-channel';
} else if (tab.name) {
chatClass = 'chat-private';
} else {
chatClass = 'chat-server';
}
return (
<div className={chatClass}>
<ChatTitle
channel={channel}
status={status}
tab={tab}
title={title}
2019-01-25 02:57:58 +00:00
openModal={openModal}
onCloseClick={this.handleCloseClick}
onTitleChange={this.handleTitleChange}
onToggleSearch={toggleSearch}
onToggleUserList={toggleUserList}
/>
2018-04-05 23:46:22 +00:00
<Search search={search} onSearch={this.handleSearch} />
<MessageBox
2018-10-15 06:56:17 +00:00
coloredNicks={coloredNicks}
hasMoreMessages={hasMoreMessages}
messages={messages}
tab={tab}
2018-12-14 13:24:23 +00:00
hideTopDate={search.show}
onAddMore={addFetchedMessages}
onFetchMore={fetchMessages}
onNickClick={this.handleNickClick}
/>
<MessageInput
currentHistoryEntry={currentInputHistoryEntry}
nick={nick}
tab={tab}
onCommand={runCommand}
onMessage={sendMessage}
onNickChange={this.handleNickChange}
onNickEditDone={this.handleNickEditDone}
{...inputActions}
/>
<UserList
2018-10-15 06:56:17 +00:00
coloredNicks={coloredNicks}
showUserList={showUserList}
users={users}
onNickClick={this.handleNickClick}
/>
</div>
);
}
}