Navigator updates

This commit is contained in:
Bill 2022-07-27 23:31:12 -04:00
parent 5a4dd89319
commit 0fb8a46b0e
13 changed files with 97 additions and 187 deletions

View File

@ -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<SetStateAction<NavigatorCategoryDataParser[]>>;
eventCategories: NavigatorEventCategoryDataParser[];
setEventCategories: Dispatch<SetStateAction<NavigatorEventCategoryDataParser[]>>;
topLevelContext: NavigatorTopLevelContext;
setTopLevelContext: Dispatch<SetStateAction<NavigatorTopLevelContext>>;
topLevelContexts: NavigatorTopLevelContext[];
setTopLevelContexts: Dispatch<SetStateAction<NavigatorTopLevelContext[]>>;
navigatorData: INavigatorData;
setNavigatorData: Dispatch<SetStateAction<INavigatorData>>;
doorData: { roomInfo: RoomDataParser, state: number };
setDoorData: Dispatch<SetStateAction<{ roomInfo: RoomDataParser, state: number }>>;
searchResult: NavigatorSearchResultSet;
setSearchResult: Dispatch<SetStateAction<NavigatorSearchResultSet>>;
}
const NavigatorContext = createContext<INavigatorContext>({
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<ProviderProps<INavigatorContext>> = props =>
{
return <NavigatorContext.Provider value={ props.value }>{ props.children }</NavigatorContext.Provider>
}
export const useNavigatorContext = () => useContext(NavigatorContext);

View File

@ -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<NavigatorCategoryDataParser[]>(null);
const [ eventCategories, setEventCategories ] = useState<NavigatorEventCategoryDataParser[]>(null);
const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null);
const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null);
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE });
const [ searchResult, setSearchResult ] = useState<NavigatorSearchResultSet>(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>(RoomSessionEvent.CREATED, event =>
{
switch(event.type)
{
case RoomSessionEvent.CREATED:
setIsVisible(false);
setCreatorOpen(false);
return;
}
}, []);
useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent);
});
const sendSearch = useCallback((searchValue: string, contextCode: string) =>
{
@ -206,8 +191,7 @@ export const NavigatorView: FC<{}> = props =>
}, []);
return (
<NavigatorContextProvider value={ { categories, setCategories, eventCategories, setEventCategories, topLevelContext, setTopLevelContext, topLevelContexts, setTopLevelContexts, navigatorData, setNavigatorData, doorData, setDoorData, searchResult, setSearchResult } }>
<NavigatorMessageHandler />
<>
{ isVisible &&
<NitroCardView uniqueKey="navigator" className="nitro-navigator">
<NitroCardHeaderView headerText={ LocalizeText(isCreatorOpen ? 'navigator.createroom.title' : 'navigator.title') } onCloseClick={ event => setIsVisible(false) } />
@ -241,6 +225,6 @@ export const NavigatorView: FC<{}> = props =>
{ isRoomInfoOpen && <NavigatorRoomInfoView onCloseClick={ () => setRoomInfoOpen(false) } /> }
{ isRoomLinkOpen && <NavigatorRoomLinkView onCloseClick={ () => setRoomLinkOpen(false) } /> }
<NavigatorRoomSettingsView />
</NavigatorContextProvider>
</>
);
}

View File

@ -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 = () =>
{

View File

@ -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<number>(0);
const [ roomModels, setRoomModels ] = useState<IRoomModel[]>([]);
const [ selectedModelName, setSelectedModelName ] = useState<string>('');
const { categories = null } = useNavigatorContext();
const { categories = null } = useNavigator();
const hcDisabled = GetConfiguration<boolean>('hc.disabled', false);

View File

@ -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<NavigatorRoomInfoViewProps> = 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) =>
{

View File

@ -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<NavigatorRoomLinkViewProps> = props =>
{
const { onCloseClick = null } = props;
const { navigatorData = null } = useNavigatorContext();
const { navigatorData = null } = useNavigator();
if(!navigatorData.enteredGuestRoom) return null;

View File

@ -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<NavigatorRoomSettingsTabViewP
const [ roomName, setRoomName ] = useState<string>('');
const [ roomDescription, setRoomDescription ] = useState<string>('');
const { showConfirm = null } = useNotification();
const { categories = null } = useNavigatorContext();
const { categories = null } = useNavigator();
const deleteRoom = () =>
{

View File

@ -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<NavigatorSearchResultItemViewProps> = props =>
{
const { roomData = null, children = null, thumbnail = false, ...rest } = props;
const { setDoorData = null } = useNavigatorContext();
const { setDoorData = null } = useNavigator();
const getUserCounterColor = () =>
{

View File

@ -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<NavigatorSearchViewProps> = 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 = () =>
{

View File

@ -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<string>(null);
const [ roomTags, setRoomTags ] = useState<string[]>(null);
const [ isOpen, setIsOpen ] = useState<boolean>(false);
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
const { navigatorData = null } = useNavigator();
const { roomSession = null } = useRoom();
const handleToolClick = (action: string) =>

View File

@ -1 +1 @@
export * from './useSharedNavigatorData';
export * from './useNavigator';

View File

@ -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<NavigatorCategoryDataParser[]>(null);
const [ eventCategories, setEventCategories ] = useState<NavigatorEventCategoryDataParser[]>(null);
const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null);
const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null);
const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE });
const [ searchResult, setSearchResult ] = useState<NavigatorSearchResultSet>(null);
const [ navigatorData, setNavigatorData ] = useState<INavigatorData>({
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>(RoomSettingsUpdatedEvent, event =>
{
const parser = event.getParser();
SendMessageComposer(new GetGuestRoomMessageComposer(parser.roomId, false, false));
}, []);
});
useMessageEvent(RoomSettingsUpdatedEvent, onRoomSettingsUpdatedEvent);
const onCanCreateRoomEventEvent = useCallback((event: CanCreateRoomEventEvent) =>
useMessageEvent<CanCreateRoomEventEvent>(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>(UserInfoEvent, event =>
{
SendMessageComposer(new GetUserFlatCatsMessageComposer());
SendMessageComposer(new GetUserEventCatsMessageComposer());
}, []);
});
const onUserPermissionsEvent = useCallback((event: UserPermissionsEvent) =>
useMessageEvent<UserPermissionsEvent>(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>(RoomForwardEvent, event =>
{
const parser = event.getParser();
TryVisitRoom(parser.roomId);
}, []);
});
const onRoomEntryInfoMessageEvent = useCallback((event: RoomEntryInfoMessageEvent) =>
useMessageEvent<RoomEntryInfoMessageEvent>(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>(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>(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>(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>(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>(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>(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>(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>(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>(UserFlatCatsEvent, event =>
{
const parser = event.getParser();
setCategories(parser.categories);
}, [ setCategories ]);
});
const onNavigatorEventCategoriesEvent = (event: UserEventCatsEvent) =>
useMessageEvent<UserEventCatsEvent>(UserEventCatsEvent, event =>
{
const parser = event.getParser();
setEventCategories(parser.categories);
}
});
const onRoomCreatedEvent = useCallback((event: FlatCreatedEvent) =>
useMessageEvent<FlatCreatedEvent>(FlatCreatedEvent, event =>
{
const parser = event.getParser();
CreateRoomSession(parser.roomId);
}, []);
});
const onNavigatorHomeRoomEvent = useCallback((event: NavigatorHomeRoomEvent) =>
useMessageEvent<NavigatorHomeRoomEvent>(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>(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>(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);

View File

@ -1,23 +0,0 @@
import { useState } from 'react';
import { useBetween } from 'use-between';
import { INavigatorData } from '../../api';
const useNavigatorData = () =>
{
return useState<INavigatorData>({
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);