import React, { CSSProperties, FC, useState } from 'react'; import { useRecoilValue } from 'recoil'; import { Input, Button, Select, Form } from 'antd'; import { MessageType } from '../../../interfaces/socket-events'; import WebsocketService from '../../../services/websocket-service'; import { websocketServiceAtom, currentUserAtom } from '../../stores/ClientConfigStore'; import styles from './NameChangeModal.module.scss'; const { Option } = Select; export type UserColorProps = { color: number; }; const UserColor: FC = ({ color }) => { const style: CSSProperties = { textAlign: 'center', backgroundColor: `var(--theme-color-users-${color})`, width: '100%', height: '100%', }; return
; }; type NameChangeModalProps = { closeModal: () => void; }; export const NameChangeModal: FC = ({ closeModal }) => { const currentUser = useRecoilValue(currentUserAtom); const websocketService = useRecoilValue(websocketServiceAtom); const [newName, setNewName] = useState(currentUser?.displayName); if (!currentUser) { return null; } const { displayName, displayColor } = currentUser; const saveEnabled = () => newName !== displayName && newName !== '' && websocketService?.isConnected(); const handleNameChange = () => { if (!saveEnabled()) return; const nameChange = { type: MessageType.NAME_CHANGE, newName, }; websocketService.send(nameChange); closeModal(); }; const handleColorChange = (color: string) => { const colorChange = { type: MessageType.COLOR_CHANGE, newColor: Number(color), }; websocketService.send(colorChange); }; const maxColor = 8; // 0...n const colorOptions = [...Array(maxColor)].map((_, i) => i); const saveButton = ( ); return (
Your chat display name is what people see when you send chat messages.
setNewName(e.target.value)} placeholder="Your chat display name" aria-label="Your chat display name" maxLength={30} showCount defaultValue={displayName} className={styles.inputGroup} /> You can also authenticate an IndieAuth or Fediverse account via the "Authenticate" menu.
); };