2018-11-04 06:22:46 +00:00
|
|
|
import React, { memo } from 'react';
|
2020-04-29 01:10:13 +00:00
|
|
|
import { FiUsers, FiSearch, FiX } from 'react-icons/fi';
|
2020-04-30 12:36:30 +00:00
|
|
|
import Navicon from 'components/ui/Navicon';
|
2020-04-29 01:10:13 +00:00
|
|
|
import Button from 'components/ui/Button';
|
2017-06-21 06:40:28 +00:00
|
|
|
import Editable from 'components/ui/Editable';
|
2020-06-15 08:58:51 +00:00
|
|
|
import { isValidNetworkName } from 'state/networks';
|
2019-01-25 02:57:58 +00:00
|
|
|
import { isChannel } from 'utils';
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
const ChatTitle = ({
|
2020-06-15 08:58:51 +00:00
|
|
|
error,
|
2018-11-04 06:22:46 +00:00
|
|
|
title,
|
|
|
|
tab,
|
|
|
|
channel,
|
2019-01-25 02:57:58 +00:00
|
|
|
openModal,
|
2018-11-04 06:22:46 +00:00
|
|
|
onTitleChange,
|
|
|
|
onToggleSearch,
|
|
|
|
onToggleUserList,
|
|
|
|
onCloseClick
|
|
|
|
}) => {
|
|
|
|
let closeTitle;
|
|
|
|
if (isChannel(tab)) {
|
|
|
|
closeTitle = 'Leave';
|
|
|
|
} else if (tab.name) {
|
|
|
|
closeTitle = 'Close';
|
|
|
|
} else {
|
|
|
|
closeTitle = 'Disconnect';
|
|
|
|
}
|
2015-12-28 23:34:32 +00:00
|
|
|
|
2020-06-15 08:58:51 +00:00
|
|
|
let networkError = null;
|
|
|
|
if (!tab.name && error) {
|
|
|
|
networkError = <span className="chat-topic error">Error: {error}</span>;
|
2018-11-04 06:22:46 +00:00
|
|
|
}
|
2017-07-02 01:31:00 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="chat-title-bar">
|
|
|
|
<Navicon />
|
|
|
|
<Editable
|
|
|
|
className="chat-title"
|
|
|
|
editable={!tab.name}
|
|
|
|
value={title}
|
2020-06-15 08:58:51 +00:00
|
|
|
validate={isValidNetworkName}
|
2018-11-04 06:22:46 +00:00
|
|
|
onChange={onTitleChange}
|
|
|
|
>
|
|
|
|
<span className="chat-title">{title}</span>
|
|
|
|
</Editable>
|
|
|
|
<div className="chat-topic-wrap">
|
2020-06-15 08:58:51 +00:00
|
|
|
{channel?.topic && (
|
2019-01-25 02:57:58 +00:00
|
|
|
<span
|
|
|
|
className="chat-topic"
|
2020-05-03 07:05:16 +00:00
|
|
|
onClick={() => openModal('topic', channel.name)}
|
2019-01-25 02:57:58 +00:00
|
|
|
>
|
|
|
|
{channel.topic}
|
|
|
|
</span>
|
|
|
|
)}
|
2020-06-15 08:58:51 +00:00
|
|
|
{networkError}
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
2020-04-29 01:10:13 +00:00
|
|
|
{tab.name && (
|
2020-05-12 05:48:12 +00:00
|
|
|
<Button
|
|
|
|
icon={FiSearch}
|
|
|
|
title="Search"
|
|
|
|
aria-label="Search"
|
|
|
|
onClick={onToggleSearch}
|
|
|
|
/>
|
2020-04-29 01:10:13 +00:00
|
|
|
)}
|
2020-05-12 05:48:12 +00:00
|
|
|
<Button
|
|
|
|
icon={FiX}
|
|
|
|
title={closeTitle}
|
|
|
|
aria-label={closeTitle}
|
|
|
|
onClick={onCloseClick}
|
|
|
|
/>
|
2020-04-29 01:10:13 +00:00
|
|
|
<Button
|
|
|
|
icon={FiUsers}
|
|
|
|
className="button-userlist"
|
2020-05-12 05:48:12 +00:00
|
|
|
aria-label="Users"
|
2020-04-29 01:10:13 +00:00
|
|
|
onClick={onToggleUserList}
|
2018-11-04 06:22:46 +00:00
|
|
|
/>
|
2015-12-28 23:34:32 +00:00
|
|
|
</div>
|
2018-11-04 06:22:46 +00:00
|
|
|
<div className="userlist-bar">
|
2020-04-29 01:10:13 +00:00
|
|
|
<FiUsers />
|
2020-06-15 08:58:51 +00:00
|
|
|
{channel?.users.length}
|
2018-11-04 06:22:46 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default memo(ChatTitle);
|