owncast/web/components/common/UserDropdown/UserDropdown.tsx

80 lines
2.3 KiB
TypeScript
Raw Normal View History

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';
import { useRecoilState, useRecoilValue } from 'recoil';
2022-05-14 01:07:49 +03:00
import { useState } from 'react';
import Modal from '../../ui/Modal/Modal';
import { chatVisibilityAtom, chatDisplayNameAtom } from '../../stores/ClientConfigStore';
import { ChatState, ChatVisibilityState } from '../../../interfaces/application-state';
import s from './UserDropdown.module.scss';
2022-05-14 01:07:49 +03:00
import NameChangeModal from '../../modals/NameChangeModal';
interface Props {
username?: string;
2022-05-12 09:31:31 +03:00
chatState: ChatState;
}
export default function UserDropdown({ username: defaultUsername, chatState }: Props) {
const [chatVisibility, setChatVisibility] =
useRecoilState<ChatVisibilityState>(chatVisibilityAtom);
const username = defaultUsername || useRecoilValue(chatDisplayNameAtom);
2022-05-14 01:07:49 +03:00
const [showNameChangeModal, setShowNameChangeModal] = useState<boolean>(false);
const toggleChatVisibility = () => {
if (chatVisibility === ChatVisibilityState.Hidden) {
setChatVisibility(ChatVisibilityState.Visible);
} else {
setChatVisibility(ChatVisibilityState.Hidden);
}
};
2022-05-14 01:07:49 +03:00
const handleChangeName = () => {
setShowNameChangeModal(true);
};
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-05-22 15:20:11 +03:00
<Menu.Item key="1" icon={<LockOutlined />}>
Authenticate
</Menu.Item>
{chatState === ChatState.Available && (
2022-05-22 15:20:11 +03:00
<Menu.Item key="3" icon={<MessageOutlined />} onClick={() => toggleChatVisibility()}>
Toggle chat
</Menu.Item>
)}
</Menu>
);
return (
<div className={`${s.root}`}>
<Dropdown overlay={menu} trigger={['click']}>
<Button icon={<UserOutlined style={{ marginRight: '.5rem' }} />}>
<Space>
{username}
<CaretDownOutlined />
</Space>
</Button>
</Dropdown>
2022-05-14 01:07:49 +03:00
<Modal
title="Change Chat Display Name"
visible={showNameChangeModal}
handleCancel={() => setShowNameChangeModal(false)}
>
<NameChangeModal />
</Modal>
</div>
);
}
UserDropdown.defaultProps = {
username: undefined,
};