diff --git a/src/components/navigator/NavigatorContext.tsx b/src/components/navigator/NavigatorContext.tsx deleted file mode 100644 index 32d83f66..00000000 --- a/src/components/navigator/NavigatorContext.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { NavigatorCategoryDataParser, NavigatorEventCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser } from '@nitrots/nitro-renderer'; -import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react'; -import { INavigatorData } from '../../api'; - -interface INavigatorContext -{ - categories: NavigatorCategoryDataParser[]; - setCategories: Dispatch>; - eventCategories: NavigatorEventCategoryDataParser[]; - setEventCategories: Dispatch>; - topLevelContext: NavigatorTopLevelContext; - setTopLevelContext: Dispatch>; - topLevelContexts: NavigatorTopLevelContext[]; - setTopLevelContexts: Dispatch>; - navigatorData: INavigatorData; - setNavigatorData: Dispatch>; - doorData: { roomInfo: RoomDataParser, state: number }; - setDoorData: Dispatch>; - searchResult: NavigatorSearchResultSet; - setSearchResult: Dispatch>; -} - -const NavigatorContext = createContext({ - categories: null, - setCategories: null, - topLevelContext: null, - setEventCategories: null, - eventCategories: null, - setTopLevelContext: null, - topLevelContexts: null, - setTopLevelContexts: null, - navigatorData: null, - setNavigatorData: null, - doorData: null, - setDoorData: null, - searchResult: null, - setSearchResult: null -}); - -export const NavigatorContextProvider: FC> = props => -{ - return { props.children } -} - -export const useNavigatorContext = () => useContext(NavigatorContext); diff --git a/src/components/navigator/NavigatorView.tsx b/src/components/navigator/NavigatorView.tsx index e5bdff45..9b3ae5eb 100644 --- a/src/components/navigator/NavigatorView.tsx +++ b/src/components/navigator/NavigatorView.tsx @@ -1,11 +1,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorEventCategoryDataParser, NavigatorInitComposer, NavigatorSearchComposer, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer'; +import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorInitComposer, NavigatorSearchComposer, RoomSessionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useRef, useState } from 'react'; -import { AddEventLinkTracker, DoorStateType, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; +import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api'; import { Base, Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; -import { useRoomSessionManagerEvent, useSharedNavigatorData } from '../../hooks'; -import { NavigatorContextProvider } from './NavigatorContext'; -import { NavigatorMessageHandler } from './NavigatorMessageHandler'; +import { useNavigator, useRoomSessionManagerEvent } from '../../hooks'; import { NavigatorDoorStateView } from './views/NavigatorDoorStateView'; import { NavigatorRoomCreatorView } from './views/NavigatorRoomCreatorView'; import { NavigatorRoomInfoView } from './views/NavigatorRoomInfoView'; @@ -24,27 +22,14 @@ export const NavigatorView: FC<{}> = props => const [ isLoading, setIsLoading ] = useState(false); const [ needsInit, setNeedsInit ] = useState(true); const [ needsSearch, setNeedsSearch ] = useState(false); - const [ categories, setCategories ] = useState(null); - const [ eventCategories, setEventCategories ] = useState(null); - const [ topLevelContext, setTopLevelContext ] = useState(null); - const [ topLevelContexts, setTopLevelContexts ] = useState(null); - const [ navigatorData, setNavigatorData ] = useSharedNavigatorData(); - const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE }); - const [ searchResult, setSearchResult ] = useState(null); + const { searchResult = null, topLevelContext = null, topLevelContexts = null, navigatorData = null } = useNavigator(); const pendingSearch = useRef<{ value: string, code: string }>(null); - const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => + useRoomSessionManagerEvent(RoomSessionEvent.CREATED, event => { - switch(event.type) - { - case RoomSessionEvent.CREATED: - setIsVisible(false); - setCreatorOpen(false); - return; - } - }, []); - - useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent); + setIsVisible(false); + setCreatorOpen(false); + }); const sendSearch = useCallback((searchValue: string, contextCode: string) => { @@ -206,8 +191,7 @@ export const NavigatorView: FC<{}> = props => }, []); return ( - - + <> { isVisible && setIsVisible(false) } /> @@ -241,6 +225,6 @@ export const NavigatorView: FC<{}> = props => { isRoomInfoOpen && setRoomInfoOpen(false) } /> } { isRoomLinkOpen && setRoomLinkOpen(false) } /> } - + ); } diff --git a/src/components/navigator/views/NavigatorDoorStateView.tsx b/src/components/navigator/views/NavigatorDoorStateView.tsx index e9ea835d..4c8a3e24 100644 --- a/src/components/navigator/views/NavigatorDoorStateView.tsx +++ b/src/components/navigator/views/NavigatorDoorStateView.tsx @@ -1,7 +1,7 @@ import { FC, useEffect, useState } from 'react'; import { CreateRoomSession, DoorStateType, GoToDesktop, LocalizeText } from '../../../api'; import { Button, Column, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; -import { useNavigatorContext } from '../NavigatorContext'; +import { useNavigator } from '../../../hooks'; const VISIBLE_STATES = [ DoorStateType.START_DOORBELL, DoorStateType.STATE_WAITING, DoorStateType.STATE_NO_ANSWER, DoorStateType.START_PASSWORD, DoorStateType.STATE_WRONG_PASSWORD ]; const DOORBELL_STATES = [ DoorStateType.START_DOORBELL, DoorStateType.STATE_WAITING, DoorStateType.STATE_NO_ANSWER ]; @@ -10,7 +10,7 @@ const PASSWORD_STATES = [ DoorStateType.START_PASSWORD, DoorStateType.STATE_WRON export const NavigatorDoorStateView: FC<{}> = props => { const [ password, setPassword ] = useState(''); - const { doorData = null, setDoorData = null } = useNavigatorContext(); + const { doorData = null, setDoorData = null } = useNavigator(); const onClose = () => { diff --git a/src/components/navigator/views/NavigatorRoomCreatorView.tsx b/src/components/navigator/views/NavigatorRoomCreatorView.tsx index 73f7a8d5..516fd09e 100644 --- a/src/components/navigator/views/NavigatorRoomCreatorView.tsx +++ b/src/components/navigator/views/NavigatorRoomCreatorView.tsx @@ -3,7 +3,7 @@ import { CreateFlatMessageComposer, HabboClubLevelEnum } from '@nitrots/nitro-re import { FC, useEffect, useState } from 'react'; import { GetClubMemberLevel, GetConfiguration, IRoomModel, LocalizeText, SendMessageComposer } from '../../../api'; import { Button, Column, Flex, Grid, LayoutCurrencyIcon, LayoutGridItem, Text } from '../../../common'; -import { useNavigatorContext } from '../NavigatorContext'; +import { useNavigator } from '../../../hooks'; export const NavigatorRoomCreatorView: FC<{}> = props => { @@ -15,7 +15,7 @@ export const NavigatorRoomCreatorView: FC<{}> = props => const [ tradesSetting, setTradesSetting ] = useState(0); const [ roomModels, setRoomModels ] = useState([]); const [ selectedModelName, setSelectedModelName ] = useState(''); - const { categories = null } = useNavigatorContext(); + const { categories = null } = useNavigator(); const hcDisabled = GetConfiguration('hc.disabled', false); diff --git a/src/components/navigator/views/NavigatorRoomInfoView.tsx b/src/components/navigator/views/NavigatorRoomInfoView.tsx index b7ae5bd4..c522b9bb 100644 --- a/src/components/navigator/views/NavigatorRoomInfoView.tsx +++ b/src/components/navigator/views/NavigatorRoomInfoView.tsx @@ -5,7 +5,7 @@ import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, DispatchUiEvent, GetGroupInformation, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../api'; import { Button, Column, Flex, LayoutBadgeImageView, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text, UserProfileIconView } from '../../../common'; import { RoomWidgetThumbnailEvent } from '../../../events'; -import { useNavigatorContext } from '../NavigatorContext'; +import { useNavigator } from '../../../hooks'; export class NavigatorRoomInfoViewProps { @@ -17,8 +17,7 @@ export const NavigatorRoomInfoView: FC = props => const { onCloseClick = null } = props; const [ isRoomPicked, setIsRoomPicked ] = useState(false); const [ isRoomMuted, setIsRoomMuted ] = useState(false); - const { navigatorData = null } = useNavigatorContext(); - + const { navigatorData = null } = useNavigator(); const hasPermission = (permission: string) => { diff --git a/src/components/navigator/views/NavigatorRoomLinkView.tsx b/src/components/navigator/views/NavigatorRoomLinkView.tsx index a09da832..e19399c2 100644 --- a/src/components/navigator/views/NavigatorRoomLinkView.tsx +++ b/src/components/navigator/views/NavigatorRoomLinkView.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { GetConfiguration, LocalizeText } from '../../../api'; import { Column, Flex, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common'; -import { useNavigatorContext } from '../NavigatorContext'; +import { useNavigator } from '../../../hooks'; export class NavigatorRoomLinkViewProps { @@ -11,7 +11,7 @@ export class NavigatorRoomLinkViewProps export const NavigatorRoomLinkView: FC = props => { const { onCloseClick = null } = props; - const { navigatorData = null } = useNavigatorContext(); + const { navigatorData = null } = useNavigator(); if(!navigatorData.enteredGuestRoom) return null; diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx index 26eb4c04..70c51b37 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx @@ -3,8 +3,7 @@ import { RoomDeleteComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, Text } from '../../../../common'; -import { useNotification } from '../../../../hooks'; -import { useNavigatorContext } from '../../NavigatorContext'; +import { useNavigator, useNotification } from '../../../../hooks'; const ROOM_NAME_MIN_LENGTH = 3; const ROOM_NAME_MAX_LENGTH = 60; @@ -24,7 +23,7 @@ export const NavigatorRoomSettingsBasicTabView: FC(''); const [ roomDescription, setRoomDescription ] = useState(''); const { showConfirm = null } = useNotification(); - const { categories = null } = useNavigatorContext(); + const { categories = null } = useNavigator(); const deleteRoom = () => { diff --git a/src/components/navigator/views/search/NavigatorSearchResultItemView.tsx b/src/components/navigator/views/search/NavigatorSearchResultItemView.tsx index 40d4d5a8..9451efdb 100644 --- a/src/components/navigator/views/search/NavigatorSearchResultItemView.tsx +++ b/src/components/navigator/views/search/NavigatorSearchResultItemView.tsx @@ -3,7 +3,7 @@ import { RoomDataParser } from '@nitrots/nitro-renderer'; import { FC, MouseEvent } from 'react'; import { CreateRoomSession, DoorStateType, GetSessionDataManager, TryVisitRoom } from '../../../../api'; import { Column, Flex, LayoutBadgeImageView, LayoutGridItemProps, LayoutRoomThumbnailView, Text } from '../../../../common'; -import { useNavigatorContext } from '../../NavigatorContext'; +import { useNavigator } from '../../../../hooks'; import { NavigatorSearchResultItemInfoView } from './NavigatorSearchResultItemInfoView'; export interface NavigatorSearchResultItemViewProps extends LayoutGridItemProps @@ -15,7 +15,7 @@ export interface NavigatorSearchResultItemViewProps extends LayoutGridItemProps export const NavigatorSearchResultItemView: FC = props => { const { roomData = null, children = null, thumbnail = false, ...rest } = props; - const { setDoorData = null } = useNavigatorContext(); + const { setDoorData = null } = useNavigator(); const getUserCounterColor = () => { diff --git a/src/components/navigator/views/search/NavigatorSearchView.tsx b/src/components/navigator/views/search/NavigatorSearchView.tsx index c81010b5..8c5d275e 100644 --- a/src/components/navigator/views/search/NavigatorSearchView.tsx +++ b/src/components/navigator/views/search/NavigatorSearchView.tsx @@ -1,8 +1,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import React, { FC, KeyboardEvent, useEffect, useState } from 'react'; +import { FC, KeyboardEvent, useEffect, useState } from 'react'; import { INavigatorSearchFilter, LocalizeText, SearchFilterOptions } from '../../../../api'; import { Button, Flex } from '../../../../common'; -import { useNavigatorContext } from '../../NavigatorContext'; +import { useNavigator } from '../../../../hooks'; export interface NavigatorSearchViewProps { @@ -14,7 +14,7 @@ export const NavigatorSearchView: FC = props => const { sendSearch = null } = props; const [ searchFilterIndex, setSearchFilterIndex ] = useState(0); const [ searchValue, setSearchValue ] = useState(''); - const { topLevelContext = null, searchResult = null } = useNavigatorContext(); + const { topLevelContext = null, searchResult = null } = useNavigator(); const processSearch = () => { diff --git a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx index 588b9523..683e1ec0 100644 --- a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx +++ b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, Text, TransitionAnimation, TransitionAnimationTypes } from '../../../../common'; -import { useMessageEvent, useRoom, useSharedNavigatorData } from '../../../../hooks'; +import { useMessageEvent, useNavigator, useRoom } from '../../../../hooks'; export const RoomToolsWidgetView: FC<{}> = props => { @@ -12,7 +12,7 @@ export const RoomToolsWidgetView: FC<{}> = props => const [ roomOwner, setRoomOwner ] = useState(null); const [ roomTags, setRoomTags ] = useState(null); const [ isOpen, setIsOpen ] = useState(false); - const [ navigatorData, setNavigatorData ] = useSharedNavigatorData(); + const { navigatorData = null } = useNavigator(); const { roomSession = null } = useRoom(); const handleToolClick = (action: string) => diff --git a/src/hooks/navigator/index.ts b/src/hooks/navigator/index.ts index 109330b5..1f6f0532 100644 --- a/src/hooks/navigator/index.ts +++ b/src/hooks/navigator/index.ts @@ -1 +1 @@ -export * from './useSharedNavigatorData'; +export * from './useNavigator'; diff --git a/src/components/navigator/NavigatorMessageHandler.tsx b/src/hooks/navigator/useNavigator.ts similarity index 71% rename from src/components/navigator/NavigatorMessageHandler.tsx rename to src/hooks/navigator/useNavigator.ts index 6543b5e7..18d6ebdb 100644 --- a/src/components/navigator/NavigatorMessageHandler.tsx +++ b/src/hooks/navigator/useNavigator.ts @@ -1,24 +1,42 @@ -import { CanCreateRoomEventEvent, CantConnectMessageParser, DoorbellMessageEvent, FlatAccessDeniedMessageEvent, FlatCreatedEvent, FollowFriendMessageComposer, GenericErrorEvent, GetGuestRoomMessageComposer, GetGuestRoomResultEvent, GetUserEventCatsMessageComposer, GetUserFlatCatsMessageComposer, HabboWebTools, LegacyExternalInterface, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, RoomDataParser, RoomDoorbellAcceptedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomScoreEvent, RoomSettingsUpdatedEvent, SecurityLevel, UserEventCatsEvent, UserFlatCatsEvent, UserInfoEvent, UserPermissionsEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api'; -import { useMessageEvent, useNotification } from '../../hooks'; -import { useNavigatorContext } from './NavigatorContext'; +import { CanCreateRoomEventEvent, CantConnectMessageParser, DoorbellMessageEvent, FlatAccessDeniedMessageEvent, FlatCreatedEvent, FollowFriendMessageComposer, GenericErrorEvent, GetGuestRoomMessageComposer, GetGuestRoomResultEvent, GetUserEventCatsMessageComposer, GetUserFlatCatsMessageComposer, HabboWebTools, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorEventCategoryDataParser, NavigatorHomeRoomEvent, NavigatorMetadataEvent, NavigatorOpenRoomCreatorEvent, NavigatorSearchEvent, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomDoorbellAcceptedEvent, RoomEnterErrorEvent, RoomEntryInfoMessageEvent, RoomForwardEvent, RoomScoreEvent, RoomSettingsUpdatedEvent, SecurityLevel, UserEventCatsEvent, UserFlatCatsEvent, UserInfoEvent, UserPermissionsEvent } from '@nitrots/nitro-renderer'; +import { useState } from 'react'; +import { useBetween } from 'use-between'; +import { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, INavigatorData, LocalizeText, NotificationAlertType, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api'; +import { useMessageEvent } from '../events'; +import { useNotification } from '../notification'; -export const NavigatorMessageHandler: FC<{}> = props => +const useNavigatorState = () => { - const { setCategories = null, setEventCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setDoorData = null, setSearchResult = null } = useNavigatorContext(); + const [ categories, setCategories ] = useState(null); + const [ eventCategories, setEventCategories ] = useState(null); + const [ topLevelContext, setTopLevelContext ] = useState(null); + const [ topLevelContexts, setTopLevelContexts ] = useState(null); + const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE }); + const [ searchResult, setSearchResult ] = 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, + currentRoomRating: 0, + canRate: true + }); const { simpleAlert = null } = useNotification(); - const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) => + useMessageEvent(RoomSettingsUpdatedEvent, event => { const parser = event.getParser(); SendMessageComposer(new GetGuestRoomMessageComposer(parser.roomId, false, false)); - }, []); + }); - useMessageEvent(RoomSettingsUpdatedEvent, onRoomSettingsUpdatedEvent); - - const onCanCreateRoomEventEvent = useCallback((event: CanCreateRoomEventEvent) => + useMessageEvent(CanCreateRoomEventEvent, event => { const parser = event.getParser(); @@ -30,17 +48,15 @@ export const NavigatorMessageHandler: FC<{}> = props => } simpleAlert(LocalizeText(`navigator.cannotcreateevent.error.${ parser.errorCode }`), null, null, null, LocalizeText('navigator.cannotcreateevent.title')); - }, [ simpleAlert ]); + }); - useMessageEvent(CanCreateRoomEventEvent, onCanCreateRoomEventEvent); - - const onUserInfoEvent = useCallback((event: UserInfoEvent) => + useMessageEvent(UserInfoEvent, event => { SendMessageComposer(new GetUserFlatCatsMessageComposer()); SendMessageComposer(new GetUserEventCatsMessageComposer()); - }, []); + }); - const onUserPermissionsEvent = useCallback((event: UserPermissionsEvent) => + useMessageEvent(UserPermissionsEvent, event => { const parser = event.getParser(); @@ -53,16 +69,16 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); - }, [ setNavigatorData ]); + }); - const onRoomForwardEvent = useCallback((event: RoomForwardEvent) => + useMessageEvent(RoomForwardEvent, event => { const parser = event.getParser(); TryVisitRoom(parser.roomId); - }, []); + }); - const onRoomEntryInfoMessageEvent = useCallback((event: RoomEntryInfoMessageEvent) => + useMessageEvent(RoomEntryInfoMessageEvent, event => { const parser = event.getParser(); @@ -84,9 +100,9 @@ export const NavigatorMessageHandler: FC<{}> = props => SendMessageComposer(new GetGuestRoomMessageComposer(parser.roomId, true, false)); if(LegacyExternalInterface.available) LegacyExternalInterface.call('legacyTrack', 'navigator', 'private', [ parser.roomId ]); - }, [ setNavigatorData ]); + }); - const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) => + useMessageEvent(GetGuestRoomResultEvent, event => { const parser = event.getParser(); @@ -165,9 +181,9 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); } - }, [ setNavigatorData, setDoorData ]); + }); - const onRoomScoreEvent = useCallback((event: RoomScoreEvent) => + useMessageEvent(RoomScoreEvent, event => { const parser = event.getParser(); @@ -180,9 +196,9 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); - }, [ setNavigatorData ]); + }); - const onRoomDoorbellEvent = useCallback((event: DoorbellMessageEvent) => + useMessageEvent(DoorbellMessageEvent, event => { const parser = event.getParser(); @@ -197,9 +213,9 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); } - }, [ setDoorData ]); + }); - const onRoomDoorbellAcceptedEvent = useCallback((event: RoomDoorbellAcceptedEvent) => + useMessageEvent(RoomDoorbellAcceptedEvent, event => { const parser = event.getParser(); @@ -214,9 +230,9 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); } - }, [ setDoorData ]); + }); - const onRoomDoorbellRejectedEvent = useCallback((event: FlatAccessDeniedMessageEvent) => + useMessageEvent(FlatAccessDeniedMessageEvent, event => { const parser = event.getParser(); @@ -231,9 +247,9 @@ export const NavigatorMessageHandler: FC<{}> = props => return newValue; }); } - }, [ setDoorData ]); + }); - const onGenericErrorEvent = useCallback((event: GenericErrorEvent) => + useMessageEvent(GenericErrorEvent, event => { const parser = event.getParser(); @@ -266,17 +282,17 @@ export const NavigatorMessageHandler: FC<{}> = props => return; } - }, [ setDoorData, simpleAlert ]); + }); - const onNavigatorMetadataEvent = useCallback((event: NavigatorMetadataEvent) => + useMessageEvent(NavigatorMetadataEvent, event => { const parser = event.getParser(); setTopLevelContexts(parser.topLevelContexts); setTopLevelContext(parser.topLevelContexts.length ? parser.topLevelContexts[0] : null); - }, [ setTopLevelContexts, setTopLevelContext ]); + }); - const onNavigatorSearchEvent = useCallback((event: NavigatorSearchEvent) => + useMessageEvent(NavigatorSearchEvent, event => { const parser = event.getParser(); @@ -309,30 +325,30 @@ export const NavigatorMessageHandler: FC<{}> = props => }); setSearchResult(parser.result); - }, [ topLevelContexts, setTopLevelContext, setSearchResult ]); + }); - const onNavigatorCategoriesEvent = useCallback((event: UserFlatCatsEvent) => + useMessageEvent(UserFlatCatsEvent, event => { const parser = event.getParser(); setCategories(parser.categories); - }, [ setCategories ]); + }); - const onNavigatorEventCategoriesEvent = (event: UserEventCatsEvent) => + useMessageEvent(UserEventCatsEvent, event => { const parser = event.getParser(); setEventCategories(parser.categories); - } + }); - const onRoomCreatedEvent = useCallback((event: FlatCreatedEvent) => + useMessageEvent(FlatCreatedEvent, event => { const parser = event.getParser(); CreateRoomSession(parser.roomId); - }, []); + }); - const onNavigatorHomeRoomEvent = useCallback((event: NavigatorHomeRoomEvent) => + useMessageEvent(NavigatorHomeRoomEvent, event => { const parser = event.getParser(); @@ -389,9 +405,9 @@ export const NavigatorMessageHandler: FC<{}> = props => CreateRoomSession(parser.homeRoomId); } } - }, [ setNavigatorData ]); + }); - const onRoomEnterErrorEvent = useCallback((event: RoomEnterErrorEvent) => + useMessageEvent(RoomEnterErrorEvent, event => { const parser = event.getParser(); @@ -416,31 +432,11 @@ export const NavigatorMessageHandler: FC<{}> = props => } VisitDesktop(); - }, [ simpleAlert ]); + }); - const onRoomCreatorEvent = useCallback((event: NavigatorOpenRoomCreatorEvent) => - { - CreateLinkEvent('navigator/show'); - }, []); + useMessageEvent(NavigatorOpenRoomCreatorEvent, event => CreateLinkEvent('navigator/show')); - useMessageEvent(UserInfoEvent, onUserInfoEvent); - useMessageEvent(UserPermissionsEvent, onUserPermissionsEvent); - useMessageEvent(RoomForwardEvent, onRoomForwardEvent); - useMessageEvent(RoomEntryInfoMessageEvent, onRoomEntryInfoMessageEvent); - useMessageEvent(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); - useMessageEvent(RoomScoreEvent, onRoomScoreEvent); - useMessageEvent(DoorbellMessageEvent, onRoomDoorbellEvent); - useMessageEvent(RoomDoorbellAcceptedEvent, onRoomDoorbellAcceptedEvent); - useMessageEvent(FlatAccessDeniedMessageEvent, onRoomDoorbellRejectedEvent); - useMessageEvent(GenericErrorEvent, onGenericErrorEvent); - useMessageEvent(NavigatorMetadataEvent, onNavigatorMetadataEvent); - useMessageEvent(NavigatorSearchEvent, onNavigatorSearchEvent); - useMessageEvent(UserFlatCatsEvent, onNavigatorCategoriesEvent); - useMessageEvent(UserEventCatsEvent, onNavigatorEventCategoriesEvent); - useMessageEvent(FlatCreatedEvent, onRoomCreatedEvent); - useMessageEvent(NavigatorHomeRoomEvent, onNavigatorHomeRoomEvent); - useMessageEvent(RoomEnterErrorEvent, onRoomEnterErrorEvent); - useMessageEvent(NavigatorOpenRoomCreatorEvent, onRoomCreatorEvent); - - return null; + return { categories, doorData, setDoorData, topLevelContext, topLevelContexts, searchResult, navigatorData }; } + +export const useNavigator = () => useBetween(useNavigatorState); diff --git a/src/hooks/navigator/useSharedNavigatorData.ts b/src/hooks/navigator/useSharedNavigatorData.ts deleted file mode 100644 index fa097b44..00000000 --- a/src/hooks/navigator/useSharedNavigatorData.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useState } from 'react'; -import { useBetween } from 'use-between'; -import { INavigatorData } from '../../api'; - -const useNavigatorData = () => -{ - return useState({ - settingsReceived: false, - homeRoomId: 0, - enteredGuestRoom: null, - currentRoomOwner: false, - currentRoomId: 0, - currentRoomIsStaffPick: false, - createdFlatId: 0, - avatarId: 0, - roomPicker: false, - eventMod: false, - currentRoomRating: 0, - canRate: true - }); -} - -export const useSharedNavigatorData = () => useBetween(useNavigatorData);