2021-06-10 14:48:44 +02:00
|
|
|
import React, { useCallback } from 'react';
|
2023-04-13 15:49:34 +03:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-04-09 10:44:17 +03:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2023-04-03 13:49:19 +03:00
|
|
|
import Icon from '../../../base/icons/components/Icon';
|
|
|
|
|
import { IconCloseLarge } from '../../../base/icons/svg';
|
2025-06-04 17:17:18 +02:00
|
|
|
import { isFileSharingEnabled } from '../../../file-sharing/functions.any';
|
2021-02-24 14:26:00 +02:00
|
|
|
import { toggleChat } from '../../actions.web';
|
2025-04-09 10:44:17 +03:00
|
|
|
import { ChatTabs } from '../../constants';
|
2025-10-29 18:18:00 -05:00
|
|
|
import { getFocusedTab, isChatDisabled } from '../../functions';
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2023-04-13 15:49:34 +03:00
|
|
|
interface IProps {
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2021-01-14 17:12:08 +01:00
|
|
|
/**
|
|
|
|
|
* An optional class name.
|
|
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
className: string;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
2025-02-28 09:52:09 -06:00
|
|
|
/**
|
|
|
|
|
* Whether CC tab is enabled or not.
|
|
|
|
|
*/
|
|
|
|
|
isCCTabEnabled: boolean;
|
|
|
|
|
|
2021-09-10 21:57:36 +03:00
|
|
|
/**
|
|
|
|
|
* Whether the polls feature is enabled or not.
|
|
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
isPollsEnabled: boolean;
|
2021-09-10 21:57:36 +03:00
|
|
|
|
2021-06-10 14:48:44 +02:00
|
|
|
/**
|
2023-04-13 15:49:34 +03:00
|
|
|
* Function to be called when pressing the close button.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
onCancel: Function;
|
|
|
|
|
}
|
2021-01-12 15:24:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom header of the {@code ChatDialog}.
|
|
|
|
|
*
|
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
|
*/
|
2025-04-09 10:44:17 +03:00
|
|
|
function ChatHeader({ className, isCCTabEnabled, isPollsEnabled }: IProps) {
|
2023-04-13 15:49:34 +03:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const { t } = useTranslation();
|
2025-10-29 18:18:00 -05:00
|
|
|
const _isChatDisabled = useSelector(isChatDisabled);
|
|
|
|
|
const focusedTab = useSelector(getFocusedTab);
|
2025-04-09 10:44:17 +03:00
|
|
|
const fileSharingTabEnabled = useSelector(isFileSharingEnabled);
|
2023-04-13 15:49:34 +03:00
|
|
|
|
|
|
|
|
const onCancel = useCallback(() => {
|
|
|
|
|
dispatch(toggleChat());
|
|
|
|
|
}, []);
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
const onKeyPressHandler = useCallback(e => {
|
|
|
|
|
if (onCancel && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onCancel();
|
|
|
|
|
}
|
2023-04-13 15:49:34 +03:00
|
|
|
}, []);
|
2021-06-10 14:48:44 +02:00
|
|
|
|
2025-02-28 09:52:09 -06:00
|
|
|
let title = 'chat.title';
|
|
|
|
|
|
2025-10-29 18:18:00 -05:00
|
|
|
if (!_isChatDisabled && focusedTab === ChatTabs.CHAT) {
|
2025-04-09 10:44:17 +03:00
|
|
|
title = 'chat.tabs.chat';
|
|
|
|
|
} else if (isPollsEnabled && focusedTab === ChatTabs.POLLS) {
|
|
|
|
|
title = 'chat.tabs.polls';
|
|
|
|
|
} else if (isCCTabEnabled && focusedTab === ChatTabs.CLOSED_CAPTIONS) {
|
|
|
|
|
title = 'chat.tabs.closedCaptions';
|
|
|
|
|
} else if (fileSharingTabEnabled && focusedTab === ChatTabs.FILE_SHARING) {
|
|
|
|
|
title = 'chat.tabs.fileSharing';
|
2025-10-29 18:18:00 -05:00
|
|
|
} else {
|
|
|
|
|
// If the focused tab is not enabled, don't render the header.
|
|
|
|
|
// This should not happen in normal circumstances since Chat.tsx already checks
|
|
|
|
|
// if any tabs are available before rendering.
|
|
|
|
|
return null;
|
2025-02-28 09:52:09 -06:00
|
|
|
}
|
|
|
|
|
|
2021-01-12 15:24:55 +02:00
|
|
|
return (
|
|
|
|
|
<div
|
2023-02-28 15:52:06 +01:00
|
|
|
className = { className || 'chat-dialog-header' }>
|
|
|
|
|
<span
|
|
|
|
|
aria-level = { 1 }
|
|
|
|
|
role = 'heading'>
|
2025-02-28 09:52:09 -06:00
|
|
|
{ t(title) }
|
2023-02-28 15:52:06 +01:00
|
|
|
</span>
|
2021-01-12 15:24:55 +02:00
|
|
|
<Icon
|
2021-06-10 14:48:44 +02:00
|
|
|
ariaLabel = { t('toolbar.closeChat') }
|
2021-01-12 15:24:55 +02:00
|
|
|
onClick = { onCancel }
|
2021-06-10 14:48:44 +02:00
|
|
|
onKeyPress = { onKeyPressHandler }
|
|
|
|
|
role = 'button'
|
2022-11-08 12:24:32 +02:00
|
|
|
src = { IconCloseLarge }
|
2021-06-10 14:48:44 +02:00
|
|
|
tabIndex = { 0 } />
|
2021-01-12 15:24:55 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 15:49:34 +03:00
|
|
|
export default ChatHeader;
|