mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 21:36:27 +01:00
Update navigator, fix busted state
This commit is contained in:
parent
fa64a92fc2
commit
fa11f4ef77
@ -28,7 +28,8 @@
|
||||
"react-transition-group": "^4.4.2",
|
||||
"react-virtualized": "^9.22.3",
|
||||
"react-youtube": "^7.13.1",
|
||||
"typescript": "^4.3.5"
|
||||
"typescript": "^4.3.5",
|
||||
"use-between": "^1.3.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"react-error-overlay": "6.0.9"
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
|
||||
export interface NavigatorData
|
||||
export interface INavigatorData
|
||||
{
|
||||
homeRoomId: number;
|
||||
settingsReceived: boolean;
|
@ -1,6 +1,6 @@
|
||||
import { RoomSettingsParser } from '@nitrots/nitro-renderer';
|
||||
|
||||
export default class RoomSettingsData
|
||||
export class RoomSettingsData
|
||||
{
|
||||
public roomId: number;
|
||||
public roomName: string;
|
@ -1 +1,10 @@
|
||||
export * from './DoorStateType';
|
||||
export * from './INavigatorData';
|
||||
export * from './INavigatorSearchFilter';
|
||||
export * from './NavigatorSearchResultViewDisplayMode';
|
||||
export * from './RoomInfoData';
|
||||
export * from './RoomModels';
|
||||
export * from './RoomSettingsData';
|
||||
export * from './RoomSettingsUtils';
|
||||
export * from './SearchFilterOptions';
|
||||
export * from './TryVisitRoom';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react';
|
||||
import { NavigatorData } from './common/NavigatorData';
|
||||
import { INavigatorData } from '../../api';
|
||||
|
||||
interface INavigatorContext
|
||||
{
|
||||
@ -10,8 +10,8 @@ interface INavigatorContext
|
||||
setTopLevelContext: Dispatch<SetStateAction<NavigatorTopLevelContext>>;
|
||||
topLevelContexts: NavigatorTopLevelContext[];
|
||||
setTopLevelContexts: Dispatch<SetStateAction<NavigatorTopLevelContext[]>>;
|
||||
navigatorData: NavigatorData;
|
||||
setNavigatorData: Dispatch<SetStateAction<NavigatorData>>;
|
||||
navigatorData: INavigatorData;
|
||||
setNavigatorData: Dispatch<SetStateAction<INavigatorData>>;
|
||||
doorData: { roomInfo: RoomDataParser, state: number };
|
||||
setDoorData: Dispatch<SetStateAction<{ roomInfo: RoomDataParser, state: number }>>;
|
||||
searchResult: NavigatorSearchResultSet;
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { CanCreateRoomEventEvent, 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 { CreateLinkEvent, CreateRoomSession, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api';
|
||||
import { CreateLinkEvent, CreateRoomSession, DoorStateType, GetConfiguration, GetSessionDataManager, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TryVisitRoom, VisitDesktop } from '../../api';
|
||||
import { BatchUpdates, UseMessageEventHook } from '../../hooks';
|
||||
import { DoorStateType } from './common/DoorStateType';
|
||||
import { useNavigatorContext } from './NavigatorContext';
|
||||
|
||||
export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorCategoryDataParser, NavigatorInitComposer, NavigatorSearchComposer, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
import { AddEventLinkTracker, DoorStateType, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
import { Base, Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common';
|
||||
import { BatchUpdates, UseRoomSessionManagerEvent, useSharedState } from '../../hooks';
|
||||
import { DoorStateType } from './common/DoorStateType';
|
||||
import { NavigatorData } from './common/NavigatorData';
|
||||
import { BatchUpdates, UseRoomSessionManagerEvent, useSharedNavigatorData } from '../../hooks';
|
||||
import { NavigatorContextProvider } from './NavigatorContext';
|
||||
import { NavigatorMessageHandler } from './NavigatorMessageHandler';
|
||||
import { NavigatorDoorStateView } from './views/NavigatorDoorStateView';
|
||||
@ -29,20 +27,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
const [ categories, setCategories ] = useState<NavigatorCategoryDataParser[]>(null);
|
||||
const [ topLevelContext, setTopLevelContext ] = useState<NavigatorTopLevelContext>(null);
|
||||
const [ topLevelContexts, setTopLevelContexts ] = useState<NavigatorTopLevelContext[]>(null);
|
||||
const [ navigatorData, setNavigatorData ] = useSharedState<NavigatorData>('@navigatorData', {
|
||||
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 [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
|
||||
const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE });
|
||||
const [ searchResult, setSearchResult ] = useState<NavigatorSearchResultSet>(null);
|
||||
const pendingSearch = useRef<{ value: string, code: string }>(null);
|
||||
@ -185,7 +170,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
}
|
||||
return;
|
||||
}
|
||||
}, [ isVisible, navigatorData.homeRoomId ]);
|
||||
}, [ isVisible, navigatorData ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { CreateRoomSession, GoToDesktop, LocalizeText } from '../../../api';
|
||||
import { CreateRoomSession, DoorStateType, GoToDesktop, LocalizeText } from '../../../api';
|
||||
import { Button, Column, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../common';
|
||||
import { DoorStateType } from '../common/DoorStateType';
|
||||
import { useNavigatorContext } from '../NavigatorContext';
|
||||
|
||||
const VISIBLE_STATES = [ DoorStateType.START_DOORBELL, DoorStateType.STATE_WAITING, DoorStateType.STATE_NO_ANSWER, DoorStateType.START_PASSWORD, DoorStateType.STATE_WRONG_PASSWORD ];
|
||||
|
@ -1,10 +1,9 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import { HabboClubLevelEnum, RoomCreateComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { GetClubMemberLevel, GetConfiguration, LocalizeText, SendMessageComposer } from '../../../api';
|
||||
import { GetClubMemberLevel, GetConfiguration, IRoomModel, LocalizeText, RoomModels, SendMessageComposer } from '../../../api';
|
||||
import { Button, Column, Flex, Grid, LayoutCurrencyIcon, LayoutGridItem, Text } from '../../../common';
|
||||
import { BatchUpdates } from '../../../hooks';
|
||||
import { IRoomModel, RoomModels } from '../common/RoomModels';
|
||||
import { useNavigatorContext } from '../NavigatorContext';
|
||||
|
||||
export const NavigatorRoomCreatorView: FC<{}> = props =>
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { LocalizeText } from '../../../../api';
|
||||
import { LocalizeText, RoomSettingsData } from '../../../../api';
|
||||
import { Column, Flex, Text } from '../../../../common';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
|
||||
interface NavigatorRoomSettingsTabViewProps
|
||||
{
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { RoomDeleteComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC } from 'react';
|
||||
import { CreateLinkEvent, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../api';
|
||||
import { CreateLinkEvent, GetMaxVisitorsList, LocalizeText, NotificationUtilities, RoomSettingsData, SendMessageComposer } from '../../../../api';
|
||||
import { Base, Flex, Text } from '../../../../common';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
import { GetMaxVisitorsList } from '../../common/RoomSettingsUtils';
|
||||
import { useNavigatorContext } from '../../NavigatorContext';
|
||||
|
||||
const DESC_MAX_LENGTH = 255;
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { RoomUnbanUserComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { LocalizeText, SendMessageComposer } from '../../../../api';
|
||||
import { LocalizeText, RoomSettingsData, SendMessageComposer } from '../../../../api';
|
||||
import { Base, Button, Column, Grid, Text } from '../../../../common';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
|
||||
interface NavigatorRoomSettingsTabViewProps
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { RemoveAllRightsMessageComposer, RoomTakeRightsComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { LocalizeText, SendMessageComposer } from '../../../../api';
|
||||
import { LocalizeText, RoomSettingsData, SendMessageComposer } from '../../../../api';
|
||||
import { Button, Column, Flex, Grid, Text, UserProfileIconView } from '../../../../common';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
|
||||
interface NavigatorRoomSettingsTabViewProps
|
||||
{
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { RoomBannedUsersComposer, RoomSettingsEvent, RoomUsersWithRightsComposer, SaveRoomSettingsComposer } from '@nitrots/nitro-renderer';
|
||||
import { BannedUsersFromRoomEvent, FlatControllerAddedEvent, FlatControllerRemovedEvent, FlatControllersEvent } from '@nitrots/nitro-renderer/src/nitro/communication/messages/incoming/roomsettings';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { LocalizeText, SendMessageComposer } from '../../../../api';
|
||||
import { LocalizeText, RoomSettingsData, SendMessageComposer } from '../../../../api';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../common';
|
||||
import { UseMessageEventHook } from '../../../../hooks';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
import { NavigatorRoomSettingsAccessTabView } from './NavigatorRoomSettingsAccessTabView';
|
||||
import { NavigatorRoomSettingsBasicTabView } from './NavigatorRoomSettingsBasicTabView';
|
||||
import { NavigatorRoomSettingsModTabView } from './NavigatorRoomSettingsModTabView';
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { FC } from 'react';
|
||||
import { LocalizeText } from '../../../../api';
|
||||
import { LocalizeText, RoomSettingsData } from '../../../../api';
|
||||
import { Column, Flex, Grid, Text } from '../../../../common';
|
||||
import RoomSettingsData from '../../common/RoomSettingsData';
|
||||
|
||||
interface NavigatorRoomSettingsTabViewProps
|
||||
{
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { FC, MouseEvent } from 'react';
|
||||
import { CreateRoomSession, GetSessionDataManager, TryVisitRoom } from '../../../../api';
|
||||
import { CreateRoomSession, DoorStateType, GetSessionDataManager, TryVisitRoom } from '../../../../api';
|
||||
import { Column, Flex, LayoutBadgeImageView, LayoutGridItemProps, LayoutRoomThumbnailView, Text } from '../../../../common';
|
||||
import { DoorStateType } from '../../common/DoorStateType';
|
||||
import { useNavigatorContext } from '../../NavigatorContext';
|
||||
import { NavigatorSearchResultItemInfoView } from './NavigatorSearchResultItemInfoView';
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { NavigatorSearchResultList } from '@nitrots/nitro-renderer';
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { LocalizeText } from '../../../../api';
|
||||
import { AutoGrid, AutoGridProps, Grid } from '../../../../common';
|
||||
import { Column } from '../../../../common/Column';
|
||||
import { Flex } from '../../../../common/Flex';
|
||||
import { Text } from '../../../../common/Text';
|
||||
import { LocalizeText, NavigatorSearchResultViewDisplayMode } from '../../../../api';
|
||||
import { AutoGrid, AutoGridProps, Column, Flex, Grid, Text } from '../../../../common';
|
||||
import { BatchUpdates } from '../../../../hooks';
|
||||
import { NavigatorSearchResultViewDisplayMode } from '../../common/NavigatorSearchResultViewDisplayMode';
|
||||
import { NavigatorSearchResultItemView } from './NavigatorSearchResultItemView';
|
||||
|
||||
export interface NavigatorSearchResultViewProps extends AutoGridProps
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import React, { FC, KeyboardEvent, useEffect, useState } from 'react';
|
||||
import { LocalizeText } from '../../../../api';
|
||||
import { Button } from '../../../../common/Button';
|
||||
import { Flex } from '../../../../common/Flex';
|
||||
import { INavigatorSearchFilter, LocalizeText, SearchFilterOptions } from '../../../../api';
|
||||
import { Button, Flex } from '../../../../common';
|
||||
import { BatchUpdates } from '../../../../hooks';
|
||||
import { INavigatorSearchFilter } from '../../common/INavigatorSearchFilter';
|
||||
import { SearchFilterOptions } from '../../common/SearchFilterOptions';
|
||||
import { useNavigatorContext } from '../../NavigatorContext';
|
||||
|
||||
export interface NavigatorSearchViewProps
|
||||
|
@ -2,15 +2,15 @@ import { FriendFurniConfirmLockMessageComposer, LoveLockFurniFinishedEvent, Love
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { GetRoomEngine, GetRoomSession, LocalizeText, RoomWidgetUpdateRoomObjectEvent } from '../../../../../api';
|
||||
import { DraggableWindow, LayoutAvatarImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../common';
|
||||
import { UseEventDispatcherHook, UseMessageEventHook, UseRoomEngineEvent } from '../../../../../hooks';
|
||||
import { BatchUpdates, UseEventDispatcherHook, UseMessageEventHook, UseRoomEngineEvent } from '../../../../../hooks';
|
||||
import { useRoomContext } from '../../../RoomContext';
|
||||
import { FurnitureEngravingLockData } from './FriendFurniLockData';
|
||||
|
||||
export const FurnitureFriendFurniView: FC<{}> = props =>
|
||||
{
|
||||
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||
const [ engravingLockData, setEngravingLockData ] = useState<FurnitureEngravingLockData>(null);
|
||||
const [ engravingStage, setEngravingStage ] = useState(0);
|
||||
const [ engravingLockData, setEngravingLockData ] = useState<FurnitureEngravingLockData>(null);
|
||||
const [ engravingStage, setEngravingStage ] = useState(0);
|
||||
|
||||
const onNitroEvent = (event: NitroEvent) =>
|
||||
{
|
||||
@ -30,7 +30,11 @@ export const FurnitureFriendFurniView: FC<{}> = props =>
|
||||
{
|
||||
if(data.length !== 6) return;
|
||||
|
||||
setEngravingLockData(new FurnitureEngravingLockData(widgetEvent.objectId, widgetEvent.category, type, [ data[1], data[2] ], [ data[3], data[4] ], data[5]));
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setEngravingLockData(new FurnitureEngravingLockData(widgetEvent.objectId, widgetEvent.category, type, [ data[1], data[2] ], [ data[3], data[4] ], data[5]));
|
||||
setEngravingStage(0);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -55,13 +59,11 @@ export const FurnitureFriendFurniView: FC<{}> = props =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
setEngravingLockData(new FurnitureEngravingLockData(parser.furniId));
|
||||
|
||||
if(parser.start)
|
||||
setEngravingStage(1);
|
||||
else
|
||||
setEngravingStage(2);
|
||||
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setEngravingLockData(new FurnitureEngravingLockData(parser.furniId));
|
||||
setEngravingStage(parser.start ? 1 : 2);
|
||||
});
|
||||
}, []);
|
||||
|
||||
UseMessageEventHook(LoveLockFurniStartEvent, onLoveLockFurniStartEvent);
|
||||
@ -75,6 +77,7 @@ export const FurnitureFriendFurniView: FC<{}> = props =>
|
||||
return;
|
||||
case 'accept_request':
|
||||
GetRoomSession().connection.send(new FriendFurniConfirmLockMessageComposer(engravingLockData.objectId, true));
|
||||
processAction('close_request');
|
||||
return;
|
||||
case 'reject_request':
|
||||
GetRoomSession().connection.send(new FriendFurniConfirmLockMessageComposer(engravingLockData.objectId, false));
|
||||
@ -97,7 +100,7 @@ export const FurnitureFriendFurniView: FC<{}> = props =>
|
||||
|
||||
return (
|
||||
<>
|
||||
{ engravingStage > 0 && <NitroCardView className="nitro-engraving-lock" theme="primary-slim">
|
||||
{ (engravingStage > 0) && <NitroCardView className="nitro-engraving-lock" theme="primary-slim">
|
||||
<NitroCardHeaderView headerText={ LocalizeText('friend.furniture.confirm.lock.caption') } onCloseClick={ event => processAction('close_request') } />
|
||||
<NitroCardContentView>
|
||||
<h5 className="text-black text-center fw-bold mt-2 mb-2">
|
||||
|
@ -3,8 +3,7 @@ import classNames from 'classnames';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { CreateLinkEvent, LocalizeText, RoomWidgetZoomToggleMessage, SendMessageComposer } from '../../../../api';
|
||||
import { Base, Column, Flex, Text, TransitionAnimation, TransitionAnimationTypes } from '../../../../common';
|
||||
import { BatchUpdates, UseMessageEventHook, useSharedState } from '../../../../hooks';
|
||||
import { NavigatorData } from '../../../navigator/common/NavigatorData';
|
||||
import { BatchUpdates, UseMessageEventHook, useSharedNavigatorData } from '../../../../hooks';
|
||||
import { useRoomContext } from '../../RoomContext';
|
||||
|
||||
export const RoomToolsWidgetView: FC<{}> = props =>
|
||||
@ -15,7 +14,7 @@ export const RoomToolsWidgetView: FC<{}> = props =>
|
||||
const [ roomTags, setRoomTags ] = useState<string[]>(null);
|
||||
const [ roomInfoDisplay, setRoomInfoDisplay ] = useState<boolean>(false);
|
||||
const [ isOpen, setIsOpen ] = useState<boolean>(false);
|
||||
const [ navigatorData, setNavigatorData ] = useSharedState<NavigatorData>('@navigatorData');
|
||||
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
|
||||
const { widgetHandler = null } = useRoomContext();
|
||||
|
||||
const handleToolClick = (action: string) =>
|
||||
|
@ -23,8 +23,6 @@ export const WiredConditionFurniMatchesSnapshotView: FC<{}> = props =>
|
||||
setPositionFlag(trigger.getBoolean(2) ? 1 : 0);
|
||||
});
|
||||
}, [ trigger ]);
|
||||
|
||||
console.log(stateFlag, directionFlag, positionFlag);
|
||||
|
||||
return (
|
||||
<WiredConditionBaseView requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID } hasSpecialInput={ true } save={ save }>
|
||||
|
@ -1,67 +0,0 @@
|
||||
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||
|
||||
const sharedStates: Map<string, any> = new Map();
|
||||
const sharedSetters: Map<string, Dispatch<SetStateAction<any>>[]> = new Map();
|
||||
|
||||
export const useSharedState = <T>(key: string, initialValue?: T | (() => T)): [T, Dispatch<SetStateAction<T>>] =>
|
||||
{
|
||||
const [ state, setState ] = useState<T>(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
const item = sharedStates.get(key);
|
||||
|
||||
return item || initialValue;
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.error(error);
|
||||
|
||||
return initialValue;
|
||||
}
|
||||
});
|
||||
|
||||
const updateState: Dispatch<SetStateAction<T>> = data =>
|
||||
{
|
||||
try
|
||||
{
|
||||
const valueToStore = data instanceof Function ? data(state as T) : data;
|
||||
const setters = sharedSetters.get(key);
|
||||
|
||||
if(setters) for(const setter of setters) setter(valueToStore);
|
||||
|
||||
sharedStates.set(key, valueToStore);
|
||||
}
|
||||
|
||||
catch (error)
|
||||
{
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!key || !key.length) return;
|
||||
|
||||
let existing = sharedSetters.get(key);
|
||||
|
||||
if(!existing)
|
||||
{
|
||||
existing = [];
|
||||
|
||||
sharedSetters.set(key, existing);
|
||||
}
|
||||
|
||||
existing.push(setState);
|
||||
|
||||
return () =>
|
||||
{
|
||||
const index = existing.findIndex(dispatch => (dispatch === setState));
|
||||
|
||||
if(index >= 0) existing.splice(index, 1);
|
||||
}
|
||||
}, [ key ]);
|
||||
|
||||
return [ state as T, updateState ];
|
||||
}
|
@ -4,5 +4,5 @@ export * from './events/core';
|
||||
export * from './events/nitro';
|
||||
export * from './events/ui';
|
||||
export * from './messages';
|
||||
export * from './navigator';
|
||||
export * from './UseMountEffect';
|
||||
export * from './UseSharedState';
|
||||
|
1
src/hooks/navigator/index.ts
Normal file
1
src/hooks/navigator/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './useSharedNavigatorData';
|
23
src/hooks/navigator/useSharedNavigatorData.ts
Normal file
23
src/hooks/navigator/useSharedNavigatorData.ts
Normal file
@ -0,0 +1,23 @@
|
||||
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);
|
@ -11821,6 +11821,11 @@ url@^0.11.0:
|
||||
punycode "1.3.2"
|
||||
querystring "0.2.0"
|
||||
|
||||
use-between@^1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/use-between/-/use-between-1.3.1.tgz#5a22ea7799d65cbe38329a8242b1ccb99161d8d3"
|
||||
integrity sha512-/UZe/gxNNkJUTlmqpWyVH2yJsaEh2kKTyZwgHSiSk0X2/rxOKFb5qjGCqM71LxI50cWHuhwkVGl6m+UYUvDUNQ==
|
||||
|
||||
use@^3.1.0:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
|
||||
|
Loading…
Reference in New Issue
Block a user