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

90 lines
2.1 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';
import { isValidServerName } from 'state/servers';
2019-01-25 02:57:58 +00:00
import { isChannel } from 'utils';
2015-12-28 23:34:32 +00:00
const ChatTitle = ({
status,
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
let serverError = null;
if (!tab.name && status.error) {
serverError = (
<span className="chat-topic error">Error: {status.error}</span>
);
}
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>
<div className="chat-topic-wrap">
2019-01-25 02:57:58 +00:00
{channel && channel.topic && (
<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>
)}
{serverError}
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 />
{channel && channel.users.length}
</div>
</div>
);
};
export default memo(ChatTitle);