0

89 lines
2.6 KiB
TypeScript
Raw Normal View History

import React, { CSSProperties, useState } from 'react';
2022-05-13 15:07:49 -07:00
import { useRecoilValue } from 'recoil';
import { Input, Button, Select } from 'antd';
refactor(stories): co-locate stories with components (#2078) * refactor: move ActionButton component * refactor: move BanUserButton component * refactor: move ChatActionMessage component * refactor: move ChatContainer component * refactor: move AuthModal component * refactor: move BrowserNotifyModal component * refactor: move ChatUserMessage component * refactor: move ChatJoinMessage component * refactor: move ChatTextField component * refactor: move ChatUserBadge component * refactor: move FollowerCollection and SingleFollower components * fix: bad import path * refactor: move FollowModal component * refactor: move Modal component * refactor: move ContentHeader component * refactor: move ChatSystemMessage component * refactor: move Header component * refactor: move Footer component * refactor: move StatusBar component * refactor: move OfflineBanner component * refactor: move OwncastPlayer component * refactor: move IndieAuthModal component * refactor: move SocialLinks component * refactor: move VideoPoster component * refactor: move FollowModal component * refactor: move FediAuthModal.tsx component * refactor: move UserDropdown component * refactor: move ChatSocialMessage component * refactor: move Logo component * refactor: move NotifyReminderPopup component * refactor: move NameChangeModal component * refactor: move FatalErrorStateModal component * refactor: move ChatModeratorNotification component * refactor: move ChatModerationActionMenu and ChatModerationDetailsModal components * refactor: move CustomPageContent component * refactor: move storybook Introduction file * refactor: update storybook story import path * refactor: move storybook preview styles * refactor: move storybook doc pages * refactor: move Color and ImageAsset components * fix: bad import path * fix: bad import path in story file
2022-09-03 20:38:52 +02:00
import { MessageType } from '../../../interfaces/socket-events';
import WebsocketService from '../../../services/websocket-service';
import {
websocketServiceAtom,
chatDisplayNameAtom,
chatDisplayColorAtom,
refactor(stories): co-locate stories with components (#2078) * refactor: move ActionButton component * refactor: move BanUserButton component * refactor: move ChatActionMessage component * refactor: move ChatContainer component * refactor: move AuthModal component * refactor: move BrowserNotifyModal component * refactor: move ChatUserMessage component * refactor: move ChatJoinMessage component * refactor: move ChatTextField component * refactor: move ChatUserBadge component * refactor: move FollowerCollection and SingleFollower components * fix: bad import path * refactor: move FollowModal component * refactor: move Modal component * refactor: move ContentHeader component * refactor: move ChatSystemMessage component * refactor: move Header component * refactor: move Footer component * refactor: move StatusBar component * refactor: move OfflineBanner component * refactor: move OwncastPlayer component * refactor: move IndieAuthModal component * refactor: move SocialLinks component * refactor: move VideoPoster component * refactor: move FollowModal component * refactor: move FediAuthModal.tsx component * refactor: move UserDropdown component * refactor: move ChatSocialMessage component * refactor: move Logo component * refactor: move NotifyReminderPopup component * refactor: move NameChangeModal component * refactor: move FatalErrorStateModal component * refactor: move ChatModeratorNotification component * refactor: move ChatModerationActionMenu and ChatModerationDetailsModal components * refactor: move CustomPageContent component * refactor: move storybook Introduction file * refactor: update storybook story import path * refactor: move storybook preview styles * refactor: move storybook doc pages * refactor: move Color and ImageAsset components * fix: bad import path * fix: bad import path in story file
2022-09-03 20:38:52 +02:00
} from '../../stores/ClientConfigStore';
const { Option } = Select;
2022-05-13 15:07:49 -07:00
/* eslint-disable @typescript-eslint/no-unused-vars */
interface Props {}
function UserColor(props: { color: number }): React.ReactElement {
const { color } = props;
const style: CSSProperties = {
textAlign: 'center',
backgroundColor: `var(--theme-color-users-${color})`,
width: '100%',
height: '100%',
};
return <div style={style} />;
}
2022-05-13 15:07:49 -07:00
export default function NameChangeModal(props: Props) {
const websocketService = useRecoilValue<WebsocketService>(websocketServiceAtom);
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
const chatDisplayColor = useRecoilValue<number>(chatDisplayColorAtom) || 0;
const [newName, setNewName] = useState<any>(chatDisplayName);
2022-05-13 15:07:49 -07:00
const handleNameChange = () => {
const nameChange = {
type: MessageType.NAME_CHANGE,
newName,
};
websocketService.send(nameChange);
};
2022-05-13 15:07:49 -07:00
const saveEnabled =
newName !== chatDisplayName && newName !== '' && websocketService?.isConnected();
2022-05-13 15:07:49 -07:00
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((e, i) => i);
return (
<div>
Your chat display name is what people see when you send chat messages. Other information can
go here to mention auth, and stuff.
<Input
value={newName}
onChange={e => setNewName(e.target.value)}
placeholder="Your chat display name"
maxLength={30}
showCount
defaultValue={chatDisplayName}
/>
<Button disabled={!saveEnabled} onClick={handleNameChange}>
Change name
</Button>
<div>
Your Color
<Select
style={{ width: 120 }}
onChange={handleColorChange}
defaultValue={chatDisplayColor.toString()}
getPopupContainer={triggerNode => triggerNode.parentElement}
>
{colorOptions.map(e => (
<Option key={e.toString()} title={e}>
<UserColor color={e} />
</Option>
))}
</Select>
</div>
</div>
);
2022-05-13 15:07:49 -07:00
}