import { Menu, Dropdown, Button } from 'antd'; import { CaretDownOutlined, EditOutlined, LockOutlined, MessageOutlined, UserOutlined, } from '@ant-design/icons'; import { useRecoilState, useRecoilValue } from 'recoil'; import { FC, useState } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import dynamic from 'next/dynamic'; import { chatVisibleToggleAtom, currentUserAtom, appStateAtom, } from '../../stores/ClientConfigStore'; import styles from './UserDropdown.module.scss'; import { AppStateOptions } from '../../stores/application-state'; // Lazy loaded components const Modal = dynamic(() => import('../../ui/Modal/Modal').then(mod => mod.Modal), { ssr: false, }); const NameChangeModal = dynamic( () => import('../../modals/NameChangeModal/NameChangeModal').then(mod => mod.NameChangeModal), { ssr: false, }, ); const AuthModal = dynamic( () => import('../../modals/AuthModal/AuthModal').then(mod => mod.AuthModal), { ssr: false, }, ); export type UserDropdownProps = { username?: string; }; export const UserDropdown: FC = ({ username: defaultUsername = undefined }) => { const [showNameChangeModal, setShowNameChangeModal] = useState(false); const [showAuthModal, setShowAuthModal] = useState(false); const [chatToggleVisible, setChatToggleVisible] = useRecoilState(chatVisibleToggleAtom); const appState = useRecoilValue(appStateAtom); const toggleChatVisibility = () => { setChatToggleVisible(!chatToggleVisible); }; const handleChangeName = () => { setShowNameChangeModal(true); }; // Register keyboard shortcut for the space bar to toggle playback useHotkeys( 'c', toggleChatVisibility, { enableOnContentEditable: false, }, [chatToggleVisible], ); const currentUser = useRecoilValue(currentUserAtom); if (!currentUser) { return null; } const { displayName } = currentUser; const username = defaultUsername || displayName; const menu = ( } onClick={() => handleChangeName()}> Change name } onClick={() => setShowAuthModal(true)}> Authenticate {appState.chatAvailable && ( } onClick={() => toggleChatVisibility()}> {chatToggleVisible ? 'Hide Chat' : 'Show Chat'} )} ); return (
setShowNameChangeModal(false)} > setShowAuthModal(false)}>
); };