Remove UserSettingsUIEvent

This commit is contained in:
Bill 2022-04-03 15:15:20 -04:00
parent 77cb36be44
commit fd77cf7bf0
6 changed files with 37 additions and 39 deletions

View File

@ -2,8 +2,7 @@ import { ActivityPointNotificationMessageEvent, FriendlyTime, HabboClubLevelEnum
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { CreateLinkEvent, GetConfiguration, LocalizeText, PlaySound, SendMessageComposer, SoundNames } from '../../api';
import { Column, Flex, Grid, LayoutCurrencyIcon, Text } from '../../common';
import { UserSettingsUIEvent } from '../../events';
import { DispatchUiEvent, UseMessageEventHook } from '../../hooks';
import { UseMessageEventHook } from '../../hooks';
import { IPurse } from './common/IPurse';
import { Purse } from './common/Purse';
import { PurseContextProvider } from './PurseContext';
@ -187,7 +186,7 @@ export const PurseView: FC<{}> = props =>
<Flex center pointer fullHeight className="nitro-purse-button p-1 rounded" onClick={ event => CreateLinkEvent('help/show') }>
<i className="icon icon-help"/>
</Flex>
<Flex center pointer fullHeight className="nitro-purse-button p-1 rounded" onClick={ event => DispatchUiEvent(new UserSettingsUIEvent(UserSettingsUIEvent.TOGGLE_USER_SETTINGS)) } >
<Flex center pointer fullHeight className="nitro-purse-button p-1 rounded" onClick={ event => CreateLinkEvent('user-settings/toggle') } >
<i className="icon icon-cog"/>
</Flex>
</Column>

View File

@ -2,7 +2,7 @@ import { MouseEventType, RoomObjectCategory } from '@nitrots/nitro-renderer';
import { Dispatch, FC, SetStateAction, useEffect, useRef } from 'react';
import { CreateLinkEvent, GetRoomEngine, GetRoomSession, GetSessionDataManager, GetUserProfile } from '../../api';
import { Base, Flex, LayoutItemCountView } from '../../common';
import { GuideToolEvent, UserSettingsUIEvent } from '../../events';
import { GuideToolEvent } from '../../events';
import { DispatchUiEvent } from '../../hooks';
interface ToolbarMeViewProps
@ -46,7 +46,7 @@ export const ToolbarMeView: FC<ToolbarMeViewProps> = props =>
<Base pointer className="navigation-item icon icon-me-profile" onClick={ event => GetUserProfile(GetSessionDataManager().userId) } />
<Base pointer className="navigation-item icon icon-me-rooms" onClick={ event => CreateLinkEvent('navigator/search/myworld_view')} />
<Base pointer className="navigation-item icon icon-me-clothing" onClick={ event => CreateLinkEvent('avatar-editor/toggle') } />
<Base pointer className="navigation-item icon icon-me-settings" onClick={ event => DispatchUiEvent(new UserSettingsUIEvent(UserSettingsUIEvent.TOGGLE_USER_SETTINGS)) } />
<Base pointer className="navigation-item icon icon-me-settings" onClick={ event => CreateLinkEvent('user-settings/toggle') } />
{ children }
</Flex>
);

View File

@ -1,36 +1,15 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { NitroSettingsEvent, UserSettingsCameraFollowComposer, UserSettingsEvent, UserSettingsOldChatComposer, UserSettingsRoomInvitesComposer, UserSettingsSoundComposer } from '@nitrots/nitro-renderer';
import { ILinkEventTracker, NitroSettingsEvent, UserSettingsCameraFollowComposer, UserSettingsEvent, UserSettingsOldChatComposer, UserSettingsRoomInvitesComposer, UserSettingsSoundComposer } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react';
import { LocalizeText, SendMessageComposer } from '../../api';
import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api';
import { Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common';
import { UserSettingsUIEvent } from '../../events';
import { DispatchMainEvent, DispatchUiEvent, UseMessageEventHook, UseUiEvent } from '../../hooks';
import { DispatchMainEvent, DispatchUiEvent, UseMessageEventHook } from '../../hooks';
export const UserSettingsView: FC<{}> = props =>
{
const [ isVisible, setIsVisible ] = useState(false);
const [ userSettings, setUserSettings ] = useState<NitroSettingsEvent>(null);
const onUserSettingsUIEvent = useCallback((event: UserSettingsUIEvent) =>
{
switch(event.type)
{
case UserSettingsUIEvent.SHOW_USER_SETTINGS:
setIsVisible(true);
return;
case UserSettingsUIEvent.HIDE_USER_SETTINGS:
setIsVisible(false);
return;
case UserSettingsUIEvent.TOGGLE_USER_SETTINGS:
setIsVisible(value => !value);
return;
}
}, []);
UseUiEvent(UserSettingsUIEvent.SHOW_USER_SETTINGS, onUserSettingsUIEvent);
UseUiEvent(UserSettingsUIEvent.HIDE_USER_SETTINGS, onUserSettingsUIEvent);
UseUiEvent(UserSettingsUIEvent.TOGGLE_USER_SETTINGS, onUserSettingsUIEvent);
const onUserSettingsEvent = useCallback((event: UserSettingsEvent) =>
{
const parser = event.getParser();
@ -106,6 +85,36 @@ export const UserSettingsView: FC<{}> = props =>
}
}, [ userSettings ]);
useEffect(() =>
{
const linkTracker: ILinkEventTracker = {
linkReceived: (url: string) =>
{
const parts = url.split('/');
if(parts.length < 2) return;
switch(parts[1])
{
case 'show':
setIsVisible(true);
return;
case 'hide':
setIsVisible(false);
return;
case 'toggle':
setIsVisible(prevValue => !prevValue);
return;
}
},
eventUrlPrefix: 'user-settings/'
};
AddEventLinkTracker(linkTracker);
return () => RemoveLinkEventTracker(linkTracker);
}, []);
useEffect(() =>
{
if(!userSettings) return;

View File

@ -6,5 +6,4 @@ export * from './mod-tools';
export * from './notification-center';
export * from './room-widgets';
export * from './room-widgets/thumbnail';
export * from './user-settings';
export * from './wired';

View File

@ -1,8 +0,0 @@
import { NitroEvent } from '@nitrots/nitro-renderer';
export class UserSettingsUIEvent extends NitroEvent
{
public static SHOW_USER_SETTINGS: string = 'NE_SHOW_USER_SETTINGS';
public static HIDE_USER_SETTINGS: string = 'NE_HIDE_USER_SETTINGS';
public static TOGGLE_USER_SETTINGS: string = 'NE_TOGGLE_USER_SETTINGS';
}

View File

@ -1 +0,0 @@
export * from './UserSettingsUIEvent';