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

76 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import Navicon from 'containers/Navicon';
import Editable from 'components/ui/Editable';
import { isValidServerName } from 'state/servers';
2018-04-25 03:36:27 +00:00
import { isChannel, linkify } from 'utils';
2015-12-28 23:34:32 +00:00
export default class ChatTitle extends PureComponent {
2015-12-28 23:34:32 +00:00
render() {
2018-04-05 23:46:22 +00:00
const {
status,
title,
tab,
channel,
onTitleChange,
onToggleSearch,
onToggleUserList,
onCloseClick
} = this.props;
2015-12-28 23:34:32 +00:00
let closeTitle;
2018-04-25 03:36:27 +00:00
if (isChannel(tab)) {
closeTitle = 'Leave';
} else if (tab.name) {
closeTitle = 'Close';
2015-12-28 23:34:32 +00:00
} else {
closeTitle = 'Disconnect';
2015-12-28 23:34:32 +00:00
}
let serverError = null;
if (!tab.name && status.error) {
2018-04-05 23:46:22 +00:00
serverError = (
2018-08-12 21:19:17 +00:00
<span className="chat-topic error">
Error:
{status.error}
</span>
2018-04-05 23:46:22 +00:00
);
}
2015-12-28 23:34:32 +00:00
return (
<div>
<div className="chat-title-bar">
<Navicon />
<Editable
className="chat-title"
editable={!tab.name}
value={title}
validate={isValidServerName}
onChange={onTitleChange}
>
<span className="chat-title">{title}</span>
</Editable>
2015-12-28 23:34:32 +00:00
<div className="chat-topic-wrap">
2018-04-05 23:46:22 +00:00
<span className="chat-topic">
2018-04-25 03:36:27 +00:00
{channel && linkify(channel.topic)}
2018-04-05 23:46:22 +00:00
</span>
{serverError}
2015-12-28 23:34:32 +00:00
</div>
<i className="icon-search" title="Search" onClick={onToggleSearch} />
2015-12-28 23:34:32 +00:00
<i
2017-05-16 06:38:43 +00:00
className="icon-cancel button-leave"
title={closeTitle}
onClick={onCloseClick}
2015-12-28 23:34:32 +00:00
/>
<i className="icon-user button-userlist" onClick={onToggleUserList} />
2015-12-28 23:34:32 +00:00
</div>
<div className="userlist-bar">
<i className="icon-user" />
2018-04-05 23:46:22 +00:00
<span className="chat-usercount">
2018-04-25 03:36:27 +00:00
{channel && channel.users.length}
2018-04-05 23:46:22 +00:00
</span>
2015-12-28 23:34:32 +00:00
</div>
</div>
);
}
}