From c2ddd60ff05b373ad82a6c9396eb381e3c59c8c8 Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 19 Mar 2022 00:26:57 -0400 Subject: [PATCH 1/2] Navigator updates --- package.json | 1 - public/index.html | 5 +- .../widgets/CatalogPurchaseWidgetView.tsx | 2 +- src/components/navigator/NavigatorContext.tsx | 31 +- .../navigator/NavigatorMessageHandler.tsx | 262 +++++++++++----- src/components/navigator/NavigatorView.tsx | 205 ++++++------- .../navigator/common/NavigatorData.ts | 15 + .../navigator/common/RoomSettingsData.ts | 4 +- .../navigator/common/RoomSettingsUtils.ts | 9 +- .../navigator/reducers/NavigatorReducer.tsx | 115 ------- .../creator/NavigatorRoomCreatorView.tsx | 5 +- .../views/room-info/NavigatorRoomInfoView.tsx | 71 ++--- .../views/room-link/NavigatorRoomLinkView.tsx | 47 +-- .../NavigatorRoomSettingsView.tsx | 111 ++++--- .../NavigatorRoomSettingsBasicTabView.tsx | 16 +- .../views/NavigatorRoomSettingsModTabView.tsx | 8 +- .../views/search/NavigatorSearchView.tsx | 30 +- .../high-score/FurnitureHighScoreView.tsx | 14 +- .../room-tools/RoomToolsWidgetView.tsx | 7 +- src/components/toolbar/ToolbarView.tsx | 4 +- src/events/navigator/NavigatorEvent.ts | 33 -- src/events/navigator/index.ts | 1 - yarn.lock | 283 ------------------ 23 files changed, 482 insertions(+), 797 deletions(-) create mode 100644 src/components/navigator/common/NavigatorData.ts delete mode 100644 src/components/navigator/reducers/NavigatorReducer.tsx delete mode 100644 src/events/navigator/NavigatorEvent.ts diff --git a/package.json b/package.json index c03ac7f7..3823a8d9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "@fortawesome/fontawesome-svg-core": "^6.1.0", "@fortawesome/free-solid-svg-icons": "^6.1.0", "@fortawesome/react-fontawesome": "^0.1.17", - "@nitrots/nitro-renderer": "^1.1.13", "animate.css": "^4.1.1", "classnames": "^2.3.1", "cross-env": "^7.0.3", diff --git a/public/index.html b/public/index.html index 04f4d7b3..d4019e89 100644 --- a/public/index.html +++ b/public/index.html @@ -23,7 +23,10 @@ diff --git a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx index 1fd376b1..4691b8a2 100644 --- a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx +++ b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx @@ -171,7 +171,7 @@ export const CatalogPurchaseWidgetView: FC = pro switch(purchaseState) { case CatalogPurchaseState.CONFIRM: - return ; + return ; case CatalogPurchaseState.PURCHASE: return ; case CatalogPurchaseState.FAILED: diff --git a/src/components/navigator/NavigatorContext.tsx b/src/components/navigator/NavigatorContext.tsx index 99fe9267..6455317d 100644 --- a/src/components/navigator/NavigatorContext.tsx +++ b/src/components/navigator/NavigatorContext.tsx @@ -1,15 +1,34 @@ -import { createContext, Dispatch, FC, ProviderProps, useContext } from 'react'; -import { INavigatorAction, INavigatorState } from './reducers/NavigatorReducer'; +import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext } from '@nitrots/nitro-renderer'; +import { createContext, Dispatch, FC, MutableRefObject, ProviderProps, SetStateAction, useContext } from 'react'; +import { NavigatorData } from './common/NavigatorData'; interface INavigatorContext { - navigatorState: INavigatorState; - dispatchNavigatorState: Dispatch; + categories: NavigatorCategoryDataParser[]; + setCategories: Dispatch>; + topLevelContext: NavigatorTopLevelContext; + setTopLevelContext: Dispatch>; + topLevelContexts: NavigatorTopLevelContext[]; + setTopLevelContexts: Dispatch>; + navigatorData: NavigatorData; + setNavigatorData: Dispatch>; + searchResult: NavigatorSearchResultSet; + setSearchResult: Dispatch>; + lastSearchValue: MutableRefObject; } const NavigatorContext = createContext({ - navigatorState: null, - dispatchNavigatorState: null + categories: null, + setCategories: null, + topLevelContext: null, + setTopLevelContext: null, + topLevelContexts: null, + setTopLevelContexts: null, + navigatorData: null, + setNavigatorData: null, + searchResult: null, + setSearchResult: null, + lastSearchValue: null }); export const NavigatorContextProvider: FC> = props => diff --git a/src/components/navigator/NavigatorMessageHandler.tsx b/src/components/navigator/NavigatorMessageHandler.tsx index b50810d5..4647ff9d 100644 --- a/src/components/navigator/NavigatorMessageHandler.tsx +++ b/src/components/navigator/NavigatorMessageHandler.tsx @@ -1,14 +1,38 @@ -import { CantConnectMessageParser, GenericErrorEvent, GetGuestRoomResultEvent, LegacyExternalInterface, NavigatorCategoriesComposer, NavigatorCategoriesEvent, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, NavigatorSettingsComposer, RoomCreatedEvent, RoomDataParser, RoomDoorbellAcceptedEvent, RoomDoorbellEvent, RoomDoorbellRejectedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomInfoComposer, RoomScoreEvent, RoomSettingsUpdatedEvent, UserInfoEvent } from '@nitrots/nitro-renderer'; +import { CantConnectMessageParser, FollowFriendMessageComposer, GenericErrorEvent, GetGuestRoomResultEvent, HabboWebTools, LegacyExternalInterface, NavigatorCategoriesComposer, NavigatorCategoriesEvent, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, NavigatorSettingsComposer, RoomCreatedEvent, RoomDataParser, RoomDoorbellAcceptedEvent, RoomDoorbellEvent, RoomDoorbellRejectedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomInfoComposer, RoomScoreEvent, RoomSettingsUpdatedEvent, SecurityLevel, UserInfoEvent, UserPermissionsEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; -import { CreateRoomSession, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, VisitDesktop } from '../../api'; -import { NavigatorEvent, UpdateDoorStateEvent } from '../../events'; -import { DispatchUiEvent, UseMessageEventHook } from '../../hooks'; +import { CreateLinkEvent, CreateRoomSession, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api'; +import { UpdateDoorStateEvent } from '../../events'; +import { BatchUpdates, DispatchUiEvent, UseMessageEventHook } from '../../hooks'; import { useNavigatorContext } from './NavigatorContext'; -import { NavigatorActions } from './reducers/NavigatorReducer'; export const NavigatorMessageHandler: FC<{}> = props => { - const { navigatorState = null, dispatchNavigatorState = null } = useNavigatorContext(); + const { setCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setSearchResult = null } = useNavigatorContext(); + + const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) => + { + const parser = event.getParser(); + + SendMessageComposer(new RoomInfoComposer(parser.roomId, false, false)); + }, []); + + UseMessageEventHook(RoomSettingsUpdatedEvent, onRoomSettingsUpdatedEvent); + + // const onCanCreateRoomEventEvent = useCallback((event: CanCreateRoomEventEvent) => + // { + // const parser = event.getParser(); + + // if(parser.canCreate) + // { + // // show room event cvreate + + // return; + // } + + // NotificationUtilities.simpleAlert(LocalizeText(`navigator.cannotcreateevent.error.${ parser.errorCode }`), null, null, null, LocalizeText('navigator.cannotcreateevent.title')); + // }, []); + + // UseMessageEventHook(CanCreateRoomEventEvent, onCanCreateRoomEventEvent); const onUserInfoEvent = useCallback((event: UserInfoEvent) => { @@ -16,32 +40,51 @@ export const NavigatorMessageHandler: FC<{}> = props => SendMessageComposer(new NavigatorSettingsComposer()); }, []); + const onUserPermissionsEvent = useCallback((event: UserPermissionsEvent) => + { + const parser = event.getParser(); + + setNavigatorData(prevValue => + { + const newValue = { ...prevValue }; + + newValue.eventMod = (parser.securityLevel >= SecurityLevel.MODERATOR); + newValue.roomPicker = (parser.securityLevel >= SecurityLevel.COMMUNITY); + + return newValue; + }); + }, [ setNavigatorData ]); + const onRoomForwardEvent = useCallback((event: RoomForwardEvent) => { const parser = event.getParser(); - SendMessageComposer(new RoomInfoComposer(parser.roomId, false, true)); + TryVisitRoom(parser.roomId); }, []); const onRoomEntryInfoMessageEvent = useCallback((event: RoomEntryInfoMessageEvent) => { const parser = event.getParser(); - const roomInfoData = navigatorState.roomInfoData; - roomInfoData.currentRoomOwner = parser.isOwner; - roomInfoData.currentRoomId = parser.roomId; + setNavigatorData(prevValue => + { + const newValue = { ...prevValue }; - dispatchNavigatorState({ - type: NavigatorActions.SET_ROOM_INFO_DATA, - payload: { - roomInfoData: roomInfoData - } - }); + newValue.enteredGuestRoom = null; + newValue.currentRoomOwner = parser.isOwner; + newValue.currentRoomId = parser.roomId; + + return newValue; + }); + + // close room info + // close room settings + // close room filter SendMessageComposer(new RoomInfoComposer(parser.roomId, true, false)); if(LegacyExternalInterface.available) LegacyExternalInterface.call('legacyTrack', 'navigator', 'private', [ parser.roomId ]); - }, [ navigatorState, dispatchNavigatorState ]); + }, [ setNavigatorData ]); const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) => { @@ -49,15 +92,29 @@ export const NavigatorMessageHandler: FC<{}> = props => if(parser.roomEnter) { - const roomInfoData = navigatorState.roomInfoData; - roomInfoData.enteredGuestRoom = parser.data; + setNavigatorData(prevValue => + { + const newValue = { ...prevValue }; - dispatchNavigatorState({ - type: NavigatorActions.SET_ROOM_INFO_DATA, - payload: { - roomInfoData: roomInfoData - } - }); + newValue.enteredGuestRoom = parser.data; + //newValue.currentRoomIsStaffPick = parser.staffPick; + + const isCreated = (newValue.createdFlatId === parser.data.roomId); + + if(!isCreated && parser.data.displayRoomEntryAd) + { + if(GetConfiguration('roomenterad.habblet.enabled', false)) HabboWebTools.openRoomEnterAd(); + } + + newValue.createdFlatId = 0; + + if(newValue.enteredGuestRoom && (newValue.enteredGuestRoom.habboGroupId > 0)) + { + // close event info + } + + return newValue; + }); } else if(parser.roomForward) { @@ -74,21 +131,23 @@ export const NavigatorMessageHandler: FC<{}> = props => } } + // if((parser.data.doorMode === RoomDataParser.NOOB_STATE) && !GetSessionDataManager().isAmbassador && !GetSessionDataManager().isRealNoob && !GetSessionDataManager().isModerator) return; + CreateRoomSession(parser.data.roomId); } else { - const roomInfoData = navigatorState.roomInfoData; - roomInfoData.enteredGuestRoom = parser.data; + setNavigatorData(prevValue => + { + const newValue = { ...prevValue }; - dispatchNavigatorState({ - type: NavigatorActions.SET_ROOM_INFO_DATA, - payload: { - roomInfoData: roomInfoData - } - }); + newValue.enteredGuestRoom = parser.data; + //newValue.currentRoomIsStaffPick = parser.staffPick; + + return newValue; + }); } - }, [ dispatchNavigatorState, navigatorState ]); + }, [ setNavigatorData ]); const onRoomScoreEvent = useCallback((event: RoomScoreEvent) => { @@ -141,37 +200,57 @@ export const NavigatorMessageHandler: FC<{}> = props => { const parser = event.getParser(); - dispatchNavigatorState({ - type: NavigatorActions.SET_TOP_LEVEL_CONTEXTS, - payload: { - topLevelContexts: parser.topLevelContexts - } + BatchUpdates(() => + { + setTopLevelContexts(parser.topLevelContexts); + setTopLevelContext(parser.topLevelContexts.length ? parser.topLevelContexts[0] : null); }); - }, [ dispatchNavigatorState ]); + }, [ setTopLevelContexts, setTopLevelContext ]); const onNavigatorSearchEvent = useCallback((event: NavigatorSearchEvent) => { const parser = event.getParser(); - dispatchNavigatorState({ - type: NavigatorActions.SET_SEARCH_RESULT, - payload: { - searchResult: parser.result - } + BatchUpdates(() => + { + setTopLevelContext(prevValue => + { + let newValue = prevValue; + + if(!newValue) newValue = ((topLevelContexts && topLevelContexts.length && topLevelContexts[0]) || null); + + if(!newValue) return null; + + if((parser.result.code !== newValue.code) && topLevelContexts && topLevelContexts.length) + { + for(const context of topLevelContexts) + { + if(context.code !== parser.result.code) continue; + + newValue = context; + } + } + + for(const context of topLevelContexts) + { + if(context.code !== parser.result.code) continue; + + newValue = context; + } + + return newValue; + }); + + setSearchResult(parser.result); }); - }, [ dispatchNavigatorState ]); + }, [ topLevelContexts, setTopLevelContext, setSearchResult ]); const onNavigatorCategoriesEvent = useCallback((event: NavigatorCategoriesEvent) => { const parser = event.getParser(); - dispatchNavigatorState({ - type: NavigatorActions.SET_CATEGORIES, - payload: { - categories: parser.categories - } - }); - }, [ dispatchNavigatorState ]); + setCategories(parser.categories); + }, [ setCategories ]); const onRoomCreatedEvent = useCallback((event: RoomCreatedEvent) => { @@ -184,20 +263,63 @@ export const NavigatorMessageHandler: FC<{}> = props => { const parser = event.getParser(); - dispatchNavigatorState({ - type: NavigatorActions.SET_HOME_ROOM_ID, - payload: { - homeRoomId: parser.homeRoomId + let prevSettingsReceived = false; + + setNavigatorData(prevValue => + { + prevSettingsReceived = prevValue.settingsReceived; + + const newValue = { ...prevValue }; + + newValue.homeRoomId = parser.homeRoomId; + newValue.settingsReceived = true; + + return newValue; + }); + + if(prevSettingsReceived) + { + // refresh room info window + return; + } + + let forwardType = -1; + let forwardId = -1; + + if(GetConfiguration('friend.id') !== undefined) + { + forwardType = 0; + SendMessageComposer(new FollowFriendMessageComposer(parseInt(GetConfiguration('friend.id')))); + } + + if((GetConfiguration('forward.type') !== undefined) && (GetConfiguration('forward.id') !== undefined)) + { + forwardType = parseInt(GetConfiguration('forward.type')); + forwardId = parseInt(GetConfiguration('forward.id')) + } + + if(forwardType === 2) + { + TryVisitRoom(forwardId); + } + + else if((forwardType === -1) && (parser.roomIdToEnter > 0)) + { + CreateLinkEvent('navigator/close'); + CreateRoomSession(parser.roomIdToEnter); + + if(parser.roomIdToEnter !== parser.homeRoomId) + { + CreateLinkEvent('navigator/close'); + CreateRoomSession(parser.roomIdToEnter); } - }); - }, [ dispatchNavigatorState ]); - - const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) => - { - const parser = event.getParser(); - - SendMessageComposer(new RoomInfoComposer(parser.roomId, false, false)); - }, []); + else + { + CreateLinkEvent('navigator/close'); + CreateRoomSession(parser.homeRoomId); + } + } + }, [ setNavigatorData ]); const onRoomEnterErrorEvent = useCallback((event: RoomEnterErrorEvent) => { @@ -226,12 +348,13 @@ export const NavigatorMessageHandler: FC<{}> = props => VisitDesktop(); }, []); - const onRoomCreatorEvent = useCallback((event: RoomEnterErrorEvent) => + const onRoomCreatorEvent = useCallback((event: NavigatorOpenRoomCreatorEvent) => { - DispatchUiEvent(new NavigatorEvent(NavigatorEvent.SHOW_ROOM_CREATOR)); - },[]); + CreateLinkEvent('navigator/show'); + }, []); UseMessageEventHook(UserInfoEvent, onUserInfoEvent); + UseMessageEventHook(UserPermissionsEvent, onUserPermissionsEvent); UseMessageEventHook(RoomForwardEvent, onRoomForwardEvent); UseMessageEventHook(RoomEntryInfoMessageEvent, onRoomEntryInfoMessageEvent); UseMessageEventHook(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); @@ -245,7 +368,6 @@ export const NavigatorMessageHandler: FC<{}> = props => UseMessageEventHook(NavigatorCategoriesEvent, onNavigatorCategoriesEvent); UseMessageEventHook(RoomCreatedEvent, onRoomCreatedEvent); UseMessageEventHook(NavigatorHomeRoomEvent, onNavigatorHomeRoomEvent); - UseMessageEventHook(RoomSettingsUpdatedEvent, onRoomSettingsUpdatedEvent); UseMessageEventHook(RoomEnterErrorEvent, onRoomEnterErrorEvent); UseMessageEventHook(NavigatorOpenRoomCreatorEvent, onRoomCreatorEvent); diff --git a/src/components/navigator/NavigatorView.tsx b/src/components/navigator/NavigatorView.tsx index 2a40f9ba..fced83ed 100644 --- a/src/components/navigator/NavigatorView.tsx +++ b/src/components/navigator/NavigatorView.tsx @@ -1,13 +1,13 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorInitComposer, NavigatorSearchComposer, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useReducer, useState } from 'react'; -import { AddEventLinkTracker, CreateLinkEvent, GoToDesktop, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; +import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorInitComposer, NavigatorSearchComposer, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { AddEventLinkTracker, GoToDesktop, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; import { Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; -import { NavigatorEvent, UpdateDoorStateEvent } from '../../events'; -import { BatchUpdates, UseMountEffect, UseRoomSessionManagerEvent, UseUiEvent } from '../../hooks'; +import { UpdateDoorStateEvent } from '../../events'; +import { BatchUpdates, UseRoomSessionManagerEvent, UseUiEvent } from '../../hooks'; +import { NavigatorData } from './common/NavigatorData'; import { NavigatorContextProvider } from './NavigatorContext'; import { NavigatorMessageHandler } from './NavigatorMessageHandler'; -import { initialNavigator, NavigatorActions, NavigatorReducer } from './reducers/NavigatorReducer'; import { NavigatorRoomCreatorView } from './views/creator/NavigatorRoomCreatorView'; import { NavigatorRoomDoorbellView } from './views/room-doorbell/NavigatorRoomDoorbellView'; import { NavigatorRoomInfoView } from './views/room-info/NavigatorRoomInfoView'; @@ -15,7 +15,7 @@ import { NavigatorRoomLinkView } from './views/room-link/NavigatorRoomLinkView'; import { NavigatorRoomPasswordView } from './views/room-password/NavigatorRoomPasswordView'; import { NavigatorRoomSettingsView } from './views/room-settings/NavigatorRoomSettingsView'; import { NavigatorSearchResultView } from './views/search-result/NavigatorSearchResultView'; -import { LAST_SEARCH, NavigatorSearchView } from './views/search/NavigatorSearchView'; +import { NavigatorSearchView } from './views/search/NavigatorSearchView'; export const NavigatorView: FC<{}> = props => { @@ -23,42 +23,25 @@ export const NavigatorView: FC<{}> = props => const [ isCreatorOpen, setCreatorOpen ] = useState(false); const [ isRoomInfoOpen, setRoomInfoOpen ] = useState(false); const [ isRoomLinkOpen, setRoomLinkOpen ] = useState(false); + const [ needsUpdate, setNeedsUpdate ] = useState(true); + const [ categories, setCategories ] = useState(null); + const [ topLevelContext, setTopLevelContext ] = useState(null); + const [ topLevelContexts, setTopLevelContexts ] = useState(null); + const [ navigatorData, setNavigatorData ] = useState({ + settingsReceived: false, + homeRoomId: 0, + enteredGuestRoom: null, + currentRoomOwner: false, + currentRoomId: 0, + currentRoomIsStaffPick: false, + createdFlatId: 0, + avatarId: 0, + roomPicker: false, + eventMod: false + }); + const [ searchResult, setSearchResult ] = useState(null); const [ pendingDoorState, setPendingDoorState ] = useState<{ roomData: RoomDataParser, state: string }>(null); - const [ navigatorState, dispatchNavigatorState ] = useReducer(NavigatorReducer, initialNavigator); - const { needsNavigatorUpdate = true, topLevelContext = null, topLevelContexts = null, homeRoomId } = navigatorState; - - const onNavigatorEvent = useCallback((event: NavigatorEvent) => - { - switch(event.type) - { - case NavigatorEvent.SHOW_NAVIGATOR: - setIsVisible(true); - return; - case NavigatorEvent.HIDE_NAVIGATOR: - setIsVisible(false); - return; - case NavigatorEvent.TOGGLE_NAVIGATOR: - setIsVisible(value => !value); - return; - case NavigatorEvent.TOGGLE_ROOM_INFO: - setRoomInfoOpen(value => !value); - return; - case NavigatorEvent.TOGGLE_ROOM_LINK: - setRoomLinkOpen(value => !value); - return; - case NavigatorEvent.SHOW_ROOM_CREATOR: - setIsVisible(true); - setCreatorOpen(true); - return; - } - }, []); - - UseUiEvent(NavigatorEvent.SHOW_NAVIGATOR, onNavigatorEvent); - UseUiEvent(NavigatorEvent.HIDE_NAVIGATOR, onNavigatorEvent); - UseUiEvent(NavigatorEvent.TOGGLE_NAVIGATOR, onNavigatorEvent); - UseUiEvent(NavigatorEvent.TOGGLE_ROOM_INFO, onNavigatorEvent); - UseUiEvent(NavigatorEvent.TOGGLE_ROOM_LINK, onNavigatorEvent); - UseUiEvent(NavigatorEvent.SHOW_ROOM_CREATOR, onNavigatorEvent); + const lastSearchValue = useRef(); const onUpdateDoorStateEvent = useCallback((event: UpdateDoorStateEvent) => { @@ -108,8 +91,11 @@ export const NavigatorView: FC<{}> = props => switch(event.type) { case RoomSessionEvent.CREATED: - setIsVisible(false); - setCreatorOpen(false); + BatchUpdates(() => + { + setIsVisible(false); + setCreatorOpen(false); + }); return; } }, []); @@ -119,15 +105,21 @@ export const NavigatorView: FC<{}> = props => const sendSearch = useCallback((searchValue: string, contextCode: string) => { setCreatorOpen(false); + SendMessageComposer(new NavigatorSearchComposer(contextCode, searchValue)); }, []); - const goToHomeRoom = useCallback(() => + const closePendingDoorState = useCallback((state: string) => { - if(homeRoomId <= 0) return; - - TryVisitRoom(homeRoomId); - }, [ homeRoomId ]); + if(state !== null) + { + setPendingDoorState(prevValue => + { + return { roomData: prevValue.roomData, state }; + }); + } + else setPendingDoorState(null); + }, []); const linkReceived = useCallback((url: string) => { @@ -137,19 +129,35 @@ export const NavigatorView: FC<{}> = props => switch(parts[1]) { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + case 'toggle-room-info': + setRoomInfoOpen(value => !value); + return; + case 'toggle-room-link': + setRoomLinkOpen(value => !value); + return; case 'goto': - if(parts.length > 2) - { - switch(parts[2]) - { - case 'home': - goToHomeRoom(); - break; - default: { - const roomId = parseInt(parts[2]); + if(parts.length <= 2) return; - TryVisitRoom(roomId); - } + switch(parts[2]) + { + case 'home': + if(navigatorData.homeRoomId <= 0) return; + + TryVisitRoom(navigatorData.homeRoomId); + break; + default: { + const roomId = parseInt(parts[2]); + + TryVisitRoom(roomId); } } return; @@ -174,19 +182,7 @@ export const NavigatorView: FC<{}> = props => } return; } - }, [ goToHomeRoom, sendSearch ]); - - const closePendingDoorState = useCallback((state: string) => - { - if(state !== null) - { - setPendingDoorState(prevValue => - { - return { roomData: prevValue.roomData, state }; - }); - } - else setPendingDoorState(null); - }, []); + }, [ navigatorData.homeRoomId, sendSearch ]); useEffect(() => { @@ -198,52 +194,49 @@ export const NavigatorView: FC<{}> = props => AddEventLinkTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); - }, [ linkReceived]); + }, [ linkReceived ]); - const enterRoomWebRequest = useCallback((k: string, _arg_2:boolean=false, _arg_3:string=null) => - { - SendMessageComposer(new ConvertGlobalRoomIdMessageComposer(k)); - }, []); + // useEffect(() => + // { + // if(!isVisible) return; - UseMountEffect(() => - { - LegacyExternalInterface.addCallback(HabboWebTools.OPENROOM, enterRoomWebRequest); - }); + // sendSearch(lastSearch) + // }, [ isVisible ]); useEffect(() => { - if(!needsNavigatorUpdate) return; - - dispatchNavigatorState({ - type: NavigatorActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); + if(!needsUpdate) return; SendMessageComposer(new NavigatorInitComposer()); - }, [ needsNavigatorUpdate ]); + + setNeedsUpdate(false); + }, [ needsUpdate ]); useEffect(() => { - if(!isVisible || !topLevelContext) return; + LegacyExternalInterface.addCallback(HabboWebTools.OPENROOM, (k: string, _arg_2: boolean = false, _arg_3: string = null) => SendMessageComposer(new ConvertGlobalRoomIdMessageComposer(k))); + }, []); - sendSearch('', topLevelContext.code); - }, [isVisible, sendSearch, topLevelContext]) + // useEffect(() => + // { + // if(!isVisible || !topLevelContext) return; - useEffect(() => - { - if(!topLevelContexts || !topLevelContexts.length) return; + // sendSearch('', topLevelContext.code); + // }, [ isVisible, sendSearch, topLevelContext ]) - sendSearch('', topLevelContexts[0].code); - }, [ topLevelContexts, sendSearch ]); + // useEffect(() => + // { + // if(!topLevelContexts || !topLevelContexts.length) return; - useEffect(() => - { - if(!isVisible || !LAST_SEARCH || !LAST_SEARCH.length) return; + // sendSearch('', topLevelContexts[0].code); + // }, [ topLevelContexts, sendSearch ]); - CreateLinkEvent(`navigator/search/${ LAST_SEARCH }`); - }, [ isVisible ]); + // useEffect(() => + // { + // if(!isVisible || !LAST_SEARCH || !LAST_SEARCH.length) return; + + // CreateLinkEvent(`navigator/search/${ LAST_SEARCH }`); + // }, [ isVisible ]); const getRoomDoorState = useMemo(() => { @@ -264,7 +257,7 @@ export const NavigatorView: FC<{}> = props => }, [ pendingDoorState, closePendingDoorState ]); return ( - + { getRoomDoorState } { isVisible && @@ -288,7 +281,7 @@ export const NavigatorView: FC<{}> = props => <> - { (navigatorState.searchResult && navigatorState.searchResult.results.map((result, index) => )) } + { (searchResult && searchResult.results.map((result, index) => )) } } { isCreatorOpen && } diff --git a/src/components/navigator/common/NavigatorData.ts b/src/components/navigator/common/NavigatorData.ts new file mode 100644 index 00000000..9637969c --- /dev/null +++ b/src/components/navigator/common/NavigatorData.ts @@ -0,0 +1,15 @@ +import { RoomDataParser } from '@nitrots/nitro-renderer'; + +export interface NavigatorData +{ + homeRoomId: number; + settingsReceived: boolean; + enteredGuestRoom: RoomDataParser; + currentRoomOwner: boolean; + currentRoomId: number; + currentRoomIsStaffPick: boolean; + createdFlatId: number; + avatarId: number; + roomPicker: boolean; + eventMod: boolean; +} diff --git a/src/components/navigator/common/RoomSettingsData.ts b/src/components/navigator/common/RoomSettingsData.ts index 7144458f..0a039baa 100644 --- a/src/components/navigator/common/RoomSettingsData.ts +++ b/src/components/navigator/common/RoomSettingsData.ts @@ -33,7 +33,7 @@ export default class RoomSettingsData public muteState: number; public kickState: number; public banState: number; - public bannedUsers: Map; + public bannedUsers: any[]; public selectedUserToUnban: number; constructor(parser: RoomSettingsParser) @@ -71,6 +71,6 @@ export default class RoomSettingsData this.muteState = parser.moderationSettings.allowMute; this.kickState = parser.moderationSettings.allowKick; this.banState = parser.moderationSettings.allowBan; - this.bannedUsers = new Map(); + this.bannedUsers = []; } } diff --git a/src/components/navigator/common/RoomSettingsUtils.ts b/src/components/navigator/common/RoomSettingsUtils.ts index 567c54fe..bc611dad 100644 --- a/src/components/navigator/common/RoomSettingsUtils.ts +++ b/src/components/navigator/common/RoomSettingsUtils.ts @@ -1,11 +1,10 @@ -export function GetMaxVisitorsList(): number[] +const BuildMaxVisitorsList = () => { const list: number[] = []; - for(let i = 10; i <= 100; i = i + 10) - { - list.push(i); - } + for(let i = 10; i <= 100; i = i + 10) list.push(i); return list; } + +export const GetMaxVisitorsList = BuildMaxVisitorsList(); diff --git a/src/components/navigator/reducers/NavigatorReducer.tsx b/src/components/navigator/reducers/NavigatorReducer.tsx deleted file mode 100644 index df1f10c8..00000000 --- a/src/components/navigator/reducers/NavigatorReducer.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; -import { RoomInfoData } from '../common/RoomInfoData'; - -export interface INavigatorState -{ - needsNavigatorUpdate: boolean; - topLevelContext: NavigatorTopLevelContext; - topLevelContexts: NavigatorTopLevelContext[]; - searchResult: NavigatorSearchResultSet; - categories: NavigatorCategoryDataParser[]; - roomInfoData: RoomInfoData; - homeRoomId: number; -} - -export interface INavigatorAction -{ - type: string; - payload: { - flag?: boolean; - topLevelContext?: NavigatorTopLevelContext; - topLevelContexts?: NavigatorTopLevelContext[]; - searchResult?: NavigatorSearchResultSet; - categories?: NavigatorCategoryDataParser[]; - roomInfoData?: RoomInfoData; - homeRoomId?: number; - } -} - -export class NavigatorActions -{ - public static SET_NEEDS_UPDATE: string = 'NA_SET_NEEDS_UPDATE'; - public static SET_TOP_LEVEL_CONTEXT: string = 'NA_SET_TOP_LEVEL_CONTEXT'; - public static SET_TOP_LEVEL_CONTEXTS: string = 'NA_SET_TOP_LEVEL_CONTEXTS'; - public static SET_SEARCH_RESULT: string = 'NA_SET_SEARCH_RESULT'; - public static SET_CATEGORIES: string = 'NA_SET_CATEGORIES'; - public static SET_ROOM_INFO_DATA: string = 'NA_SET_ROOM_INFO_DATA'; - public static SET_HOME_ROOM_ID: string = 'NA_SET_HOME_ROOM_ID'; -} - -export const initialNavigator: INavigatorState = { - needsNavigatorUpdate: true, - topLevelContext: null, - topLevelContexts: null, - searchResult: null, - categories: null, - roomInfoData: new RoomInfoData(), - homeRoomId: null -} - -export const NavigatorReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case NavigatorActions.SET_NEEDS_UPDATE: - return { ...state, needsNavigatorUpdate: (action.payload.flag || false) }; - case NavigatorActions.SET_TOP_LEVEL_CONTEXT: { - let topLevelContext = (action.payload.topLevelContext || state.topLevelContext || null); - - let index = 0; - - if(topLevelContext) - { - const foundIndex = state.topLevelContexts.indexOf(topLevelContext); - - if(foundIndex > -1) index = foundIndex; - } - - topLevelContext = (state.topLevelContexts[index] || null); - - return { ...state, topLevelContext }; - } - case NavigatorActions.SET_TOP_LEVEL_CONTEXTS: { - const topLevelContexts = (action.payload.topLevelContexts || state.topLevelContexts || null); - const topLevelContext = topLevelContexts[0]; - - return { ...state, topLevelContext, topLevelContexts }; - } - case NavigatorActions.SET_SEARCH_RESULT: { - const searchResult = (action.payload.searchResult || state.searchResult || null); - const searchCode = searchResult.code; - - let topLevelContext = state.topLevelContext; - - if(searchCode !== topLevelContext.code) - { - for(const existingContext of state.topLevelContexts) - { - if(existingContext.code !== searchCode) continue; - - topLevelContext = existingContext; - } - } - - return { ...state, topLevelContext, searchResult }; - } - case NavigatorActions.SET_CATEGORIES: { - const categories = (action.payload.categories || state.categories || null); - - return { ...state, categories }; - } - case NavigatorActions.SET_ROOM_INFO_DATA: { - const roomInfoData = (action.payload.roomInfoData || state.roomInfoData || null); - - return { ...state, roomInfoData }; - } - case NavigatorActions.SET_HOME_ROOM_ID: { - const homeRoomId = (action.payload.homeRoomId || state.homeRoomId || null); - - return { ...state, homeRoomId }; - } - default: - return state; - } -} diff --git a/src/components/navigator/views/creator/NavigatorRoomCreatorView.tsx b/src/components/navigator/views/creator/NavigatorRoomCreatorView.tsx index 4158d1da..c5a62c72 100644 --- a/src/components/navigator/views/creator/NavigatorRoomCreatorView.tsx +++ b/src/components/navigator/views/creator/NavigatorRoomCreatorView.tsx @@ -16,8 +16,7 @@ export const NavigatorRoomCreatorView: FC<{}> = props => const [ visitorsCount, setVisitorsCount ] = useState(null); const [ tradesSetting, setTradesSetting ] = useState(0); const [ selectedModelName, setSelectedModelName ] = useState(RoomModels[0].name); - const { navigatorState = null } = useNavigatorContext(); - const { categories = null } = navigatorState; + const { categories = null } = useNavigatorContext(); const getRoomModelImage = (name: string) => GetConfiguration('images.url') + `/navigator/models/model_${ name }.png`; @@ -64,7 +63,7 @@ export const NavigatorRoomCreatorView: FC<{}> = props => { LocalizeText('navigator.createroom.roomdescinfo') } -