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

88 lines
2.0 KiB
JavaScript
Raw Normal View History

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';
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
const ChatTitle = ({
2020-06-15 08:58:51 +00:00
error,
title,
tab,
channel,
2019-01-25 02:57:58 +00:00
openModal,
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>;
}
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}
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 && (
<Button
icon={FiSearch}
title="Search"
aria-label="Search"
onClick={onToggleSearch}
/>
2020-04-29 01:10:13 +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"
aria-label="Users"
2020-04-29 01:10:13 +00:00
onClick={onToggleUserList}
/>
2015-12-28 23:34:32 +00:00
</div>
<div className="userlist-bar">
2020-04-29 01:10:13 +00:00
<FiUsers />
2020-06-15 08:58:51 +00:00
{channel?.users.length}
</div>
</div>
);
};
export default memo(ChatTitle);