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