2022-05-08 10:41:47 +03:00
|
|
|
import { Menu, Dropdown, Button, Space } from 'antd';
|
2022-05-22 15:20:11 +03:00
|
|
|
import {
|
|
|
|
CaretDownOutlined,
|
|
|
|
EditOutlined,
|
|
|
|
LockOutlined,
|
|
|
|
MessageOutlined,
|
|
|
|
UserOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2022-05-14 00:44:16 +03:00
|
|
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC, useState } from 'react';
|
2022-06-25 09:27:17 +03:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { Modal } from '../../ui/Modal/Modal';
|
2022-05-26 06:38:40 +03:00
|
|
|
import {
|
|
|
|
chatVisibleToggleAtom,
|
|
|
|
chatDisplayNameAtom,
|
|
|
|
appStateAtom,
|
|
|
|
} from '../../stores/ClientConfigStore';
|
2022-09-07 10:00:28 +03:00
|
|
|
import styles from './UserDropdown.module.scss';
|
|
|
|
import { NameChangeModal } from '../../modals/NameChangeModal/NameChangeModal';
|
2022-05-26 06:38:40 +03:00
|
|
|
import { AppStateOptions } from '../../stores/application-state';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { AuthModal } from '../../modals/AuthModal/AuthModal';
|
2022-04-30 01:09:53 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type UserDropdownProps = {
|
2022-05-14 00:44:16 +03:00
|
|
|
username?: string;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2022-04-28 09:19:20 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const UserDropdown: FC<UserDropdownProps> = ({ username: defaultUsername = undefined }) => {
|
2022-05-14 00:44:16 +03:00
|
|
|
const username = defaultUsername || useRecoilValue(chatDisplayNameAtom);
|
2022-05-14 01:07:49 +03:00
|
|
|
const [showNameChangeModal, setShowNameChangeModal] = useState<boolean>(false);
|
2022-08-21 02:13:31 +03:00
|
|
|
const [showAuthModal, setShowAuthModal] = useState<boolean>(false);
|
2022-05-26 06:38:40 +03:00
|
|
|
const [chatToggleVisible, setChatToggleVisible] = useRecoilState(chatVisibleToggleAtom);
|
|
|
|
const appState = useRecoilValue<AppStateOptions>(appStateAtom);
|
2022-04-30 01:09:53 +03:00
|
|
|
|
|
|
|
const toggleChatVisibility = () => {
|
2022-06-25 09:27:17 +03:00
|
|
|
setChatToggleVisible(!chatToggleVisible);
|
2022-04-30 01:09:53 +03:00
|
|
|
};
|
|
|
|
|
2022-05-14 01:07:49 +03:00
|
|
|
const handleChangeName = () => {
|
|
|
|
setShowNameChangeModal(true);
|
|
|
|
};
|
|
|
|
|
2022-06-25 09:27:17 +03:00
|
|
|
// Register keyboard shortcut for the space bar to toggle playback
|
|
|
|
useHotkeys(
|
|
|
|
'c',
|
|
|
|
toggleChatVisibility,
|
|
|
|
{
|
|
|
|
enableOnContentEditable: false,
|
|
|
|
},
|
|
|
|
[chatToggleVisible],
|
|
|
|
);
|
|
|
|
|
2022-04-30 01:09:53 +03:00
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2022-05-22 15:20:11 +03:00
|
|
|
<Menu.Item key="0" icon={<EditOutlined />} onClick={() => handleChangeName()}>
|
2022-05-14 01:07:49 +03:00
|
|
|
Change name
|
|
|
|
</Menu.Item>
|
2022-08-21 02:13:31 +03:00
|
|
|
<Menu.Item key="1" icon={<LockOutlined />} onClick={() => setShowAuthModal(true)}>
|
2022-05-22 15:20:11 +03:00
|
|
|
Authenticate
|
|
|
|
</Menu.Item>
|
2022-05-26 06:38:40 +03:00
|
|
|
{appState.chatAvailable && (
|
2022-05-22 15:20:11 +03:00
|
|
|
<Menu.Item key="3" icon={<MessageOutlined />} onClick={() => toggleChatVisibility()}>
|
2022-04-30 01:09:53 +03:00
|
|
|
Toggle chat
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2022-09-07 10:00:28 +03:00
|
|
|
<div className={`${styles.root}`}>
|
2022-05-08 10:41:47 +03:00
|
|
|
<Dropdown overlay={menu} trigger={['click']}>
|
2022-08-30 09:17:12 +03:00
|
|
|
<Button type="primary" icon={<UserOutlined style={{ marginRight: '.5rem' }} />}>
|
2022-05-08 10:41:47 +03:00
|
|
|
<Space>
|
|
|
|
{username}
|
2022-05-22 09:36:52 +03:00
|
|
|
<CaretDownOutlined />
|
2022-05-08 10:41:47 +03:00
|
|
|
</Space>
|
|
|
|
</Button>
|
|
|
|
</Dropdown>
|
2022-05-14 01:07:49 +03:00
|
|
|
<Modal
|
|
|
|
title="Change Chat Display Name"
|
|
|
|
visible={showNameChangeModal}
|
|
|
|
handleCancel={() => setShowNameChangeModal(false)}
|
|
|
|
>
|
|
|
|
<NameChangeModal />
|
|
|
|
</Modal>
|
2022-08-21 02:13:31 +03:00
|
|
|
<Modal
|
|
|
|
title="Authenticate"
|
|
|
|
visible={showAuthModal}
|
|
|
|
handleCancel={() => setShowAuthModal(false)}
|
|
|
|
>
|
|
|
|
<AuthModal />
|
|
|
|
</Modal>
|
2022-05-08 10:41:47 +03:00
|
|
|
</div>
|
2022-04-30 01:09:53 +03:00
|
|
|
);
|
2022-05-14 00:44:16 +03:00
|
|
|
};
|