mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 10:22:36 +01:00
Update navigator doorbell/password
This commit is contained in:
parent
aad76422ec
commit
b9f4ee425e
@ -1,4 +1,4 @@
|
||||
import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext } from '@nitrots/nitro-renderer';
|
||||
import { NavigatorCategoryDataParser, NavigatorSearchResultSet, NavigatorTopLevelContext, RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { createContext, Dispatch, FC, ProviderProps, SetStateAction, useContext } from 'react';
|
||||
import { NavigatorData } from './common/NavigatorData';
|
||||
|
||||
@ -12,6 +12,8 @@ interface INavigatorContext
|
||||
setTopLevelContexts: Dispatch<SetStateAction<NavigatorTopLevelContext[]>>;
|
||||
navigatorData: NavigatorData;
|
||||
setNavigatorData: Dispatch<SetStateAction<NavigatorData>>;
|
||||
doorData: { roomInfo: RoomDataParser, state: number };
|
||||
setDoorData: Dispatch<SetStateAction<{ roomInfo: RoomDataParser, state: number }>>;
|
||||
searchResult: NavigatorSearchResultSet;
|
||||
setSearchResult: Dispatch<SetStateAction<NavigatorSearchResultSet>>;
|
||||
}
|
||||
@ -25,6 +27,8 @@ const NavigatorContext = createContext<INavigatorContext>({
|
||||
setTopLevelContexts: null,
|
||||
navigatorData: null,
|
||||
setNavigatorData: null,
|
||||
doorData: null,
|
||||
setDoorData: null,
|
||||
searchResult: null,
|
||||
setSearchResult: null
|
||||
});
|
||||
|
@ -1,13 +1,13 @@
|
||||
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 { UpdateDoorStateEvent } from '../../events';
|
||||
import { BatchUpdates, DispatchUiEvent, UseMessageEventHook } from '../../hooks';
|
||||
import { BatchUpdates, UseMessageEventHook } from '../../hooks';
|
||||
import { DoorStateType } from './common/DoorStateType';
|
||||
import { useNavigatorContext } from './NavigatorContext';
|
||||
|
||||
export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
{
|
||||
const { setCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setSearchResult = null } = useNavigatorContext();
|
||||
const { setCategories = null, setTopLevelContext = null, topLevelContexts = null, setTopLevelContexts = null, setNavigatorData = null, setDoorData = null, setSearchResult = null } = useNavigatorContext();
|
||||
|
||||
const onRoomSettingsUpdatedEvent = useCallback((event: RoomSettingsUpdatedEvent) =>
|
||||
{
|
||||
@ -92,6 +92,8 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
|
||||
if(parser.roomEnter)
|
||||
{
|
||||
setDoorData({ roomInfo: null, state: DoorStateType.NONE });
|
||||
|
||||
setNavigatorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
@ -123,10 +125,26 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
switch(parser.data.doorMode)
|
||||
{
|
||||
case RoomDataParser.DOORBELL_STATE:
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.START_DOORBELL, parser.data));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.roomInfo = parser.data;
|
||||
newValue.state = DoorStateType.START_DOORBELL;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
return;
|
||||
case RoomDataParser.PASSWORD_STATE:
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.START_PASSWORD, parser.data));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.roomInfo = parser.data;
|
||||
newValue.state = DoorStateType.START_PASSWORD;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -147,7 +165,7 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
}, [ setNavigatorData ]);
|
||||
}, [ setNavigatorData, setDoorData ]);
|
||||
|
||||
const onRoomScoreEvent = useCallback((event: RoomScoreEvent) =>
|
||||
{
|
||||
@ -170,9 +188,16 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
|
||||
if(!parser.userName || (parser.userName.length === 0))
|
||||
{
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.STATE_WAITING));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_WAITING;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
}, [ setDoorData ]);
|
||||
|
||||
const onRoomDoorbellAcceptedEvent = useCallback((event: RoomDoorbellAcceptedEvent) =>
|
||||
{
|
||||
@ -180,9 +205,16 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
|
||||
if(!parser.userName || (parser.userName.length === 0))
|
||||
{
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.STATE_ACCEPTED));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_ACCEPTED;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
}, [ setDoorData ]);
|
||||
|
||||
const onRoomDoorbellRejectedEvent = useCallback((event: RoomDoorbellRejectedEvent) =>
|
||||
{
|
||||
@ -190,9 +222,16 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
|
||||
if(!parser.userName || (parser.userName.length === 0))
|
||||
{
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.STATE_NO_ANSWER));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_NO_ANSWER;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
}, [ setDoorData ]);
|
||||
|
||||
const onGenericErrorEvent = useCallback((event: GenericErrorEvent) =>
|
||||
{
|
||||
@ -201,10 +240,33 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
switch(parser.errorCode)
|
||||
{
|
||||
case -100002:
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.STATE_WRONG_PASSWORD));
|
||||
break;
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_WRONG_PASSWORD;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
return;
|
||||
case 4009:
|
||||
NotificationUtilities.simpleAlert(LocalizeText('navigator.alert.need.to.be.vip'), NotificationAlertType.DEFAULT, null, null, LocalizeText('generic.alert.title'));
|
||||
|
||||
return;
|
||||
case 4010:
|
||||
NotificationUtilities.simpleAlert(LocalizeText('navigator.alert.invalid_room_name'), NotificationAlertType.DEFAULT, null, null, LocalizeText('generic.alert.title'));
|
||||
|
||||
return;
|
||||
case 4011:
|
||||
NotificationUtilities.simpleAlert(LocalizeText('navigator.alert.cannot_perm_ban'), NotificationAlertType.DEFAULT, null, null, LocalizeText('generic.alert.title'));
|
||||
|
||||
return;
|
||||
case 4013:
|
||||
NotificationUtilities.simpleAlert(LocalizeText('navigator.alert.room_in_maintenance'), NotificationAlertType.DEFAULT, null, null, LocalizeText('generic.alert.title'));
|
||||
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
}, [ setDoorData ]);
|
||||
|
||||
const onNavigatorMetadataEvent = useCallback((event: NavigatorMetadataEvent) =>
|
||||
{
|
||||
@ -296,7 +358,7 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
let forwardType = -1;
|
||||
let forwardId = -1;
|
||||
|
||||
if(GetConfiguration<string>('friend.id') !== undefined)
|
||||
if((GetConfiguration<string>('friend.id') !== undefined) && (parseInt(GetConfiguration<string>('friend.id')) > 0))
|
||||
{
|
||||
forwardType = 0;
|
||||
SendMessageComposer(new FollowFriendMessageComposer(parseInt(GetConfiguration<string>('friend.id'))));
|
||||
@ -316,16 +378,13 @@ export const NavigatorMessageHandler: FC<{}> = props =>
|
||||
else if((forwardType === -1) && (parser.roomIdToEnter > 0))
|
||||
{
|
||||
CreateLinkEvent('navigator/close');
|
||||
CreateRoomSession(parser.roomIdToEnter);
|
||||
|
||||
if(parser.roomIdToEnter !== parser.homeRoomId)
|
||||
{
|
||||
CreateLinkEvent('navigator/close');
|
||||
CreateRoomSession(parser.roomIdToEnter);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateLinkEvent('navigator/close');
|
||||
CreateRoomSession(parser.homeRoomId);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
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, useMemo, useRef, useState } from 'react';
|
||||
import { AddEventLinkTracker, GoToDesktop, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
import { FC, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, TryVisitRoom } from '../../api';
|
||||
import { Base, Column, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common';
|
||||
import { UpdateDoorStateEvent } from '../../events';
|
||||
import { BatchUpdates, UseRoomSessionManagerEvent, useSharedState, UseUiEvent } from '../../hooks';
|
||||
import { BatchUpdates, UseRoomSessionManagerEvent, useSharedState } from '../../hooks';
|
||||
import { DoorStateType } from './common/DoorStateType';
|
||||
import { NavigatorData } from './common/NavigatorData';
|
||||
import { NavigatorContextProvider } from './NavigatorContext';
|
||||
import { NavigatorMessageHandler } from './NavigatorMessageHandler';
|
||||
import { NavigatorDoorStateView } from './views/NavigatorDoorStateView';
|
||||
import { NavigatorRoomCreatorView } from './views/NavigatorRoomCreatorView';
|
||||
import { NavigatorRoomDoorbellView } from './views/NavigatorRoomDoorbellView';
|
||||
import { NavigatorRoomInfoView } from './views/NavigatorRoomInfoView';
|
||||
import { NavigatorRoomLinkView } from './views/NavigatorRoomLinkView';
|
||||
import { NavigatorRoomPasswordView } from './views/NavigatorRoomPasswordView';
|
||||
import { NavigatorRoomSettingsView } from './views/room-settings/NavigatorRoomSettingsView';
|
||||
import { NavigatorSearchResultView } from './views/search/NavigatorSearchResultView';
|
||||
import { NavigatorSearchView } from './views/search/NavigatorSearchView';
|
||||
@ -44,53 +43,10 @@ export const NavigatorView: FC<{}> = props =>
|
||||
currentRoomRating: 0,
|
||||
canRate: true
|
||||
});
|
||||
const [ doorData, setDoorData ] = useState<{ roomInfo: RoomDataParser, state: number }>({ roomInfo: null, state: DoorStateType.NONE });
|
||||
const [ searchResult, setSearchResult ] = useState<NavigatorSearchResultSet>(null);
|
||||
const [ pendingDoorState, setPendingDoorState ] = useState<{ roomData: RoomDataParser, state: string }>(null);
|
||||
const pendingSearch = useRef<{ value: string, code: string }>(null);
|
||||
|
||||
const onUpdateDoorStateEvent = useCallback((event: UpdateDoorStateEvent) =>
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case UpdateDoorStateEvent.START_DOORBELL:
|
||||
setPendingDoorState({ roomData: event.roomData, state: event.type });
|
||||
return;
|
||||
case UpdateDoorStateEvent.START_PASSWORD:
|
||||
setPendingDoorState({ roomData: event.roomData, state: event.type });
|
||||
return;
|
||||
case UpdateDoorStateEvent.STATE_WAITING:
|
||||
setPendingDoorState(prevValue =>
|
||||
{
|
||||
return { roomData: prevValue.roomData, state: event.type }
|
||||
});
|
||||
return;
|
||||
case UpdateDoorStateEvent.STATE_NO_ANSWER:
|
||||
setPendingDoorState(prevValue =>
|
||||
{
|
||||
if(prevValue.state === UpdateDoorStateEvent.STATE_WAITING) GoToDesktop();
|
||||
|
||||
return { roomData: prevValue.roomData, state: event.type }
|
||||
});
|
||||
return;
|
||||
case UpdateDoorStateEvent.STATE_WRONG_PASSWORD:
|
||||
setPendingDoorState(prevValue =>
|
||||
{
|
||||
return { roomData: prevValue.roomData, state: event.type }
|
||||
});
|
||||
return;
|
||||
case UpdateDoorStateEvent.STATE_ACCEPTED:
|
||||
setPendingDoorState(null);
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
|
||||
UseUiEvent(UpdateDoorStateEvent.START_DOORBELL, onUpdateDoorStateEvent);
|
||||
UseUiEvent(UpdateDoorStateEvent.START_PASSWORD, onUpdateDoorStateEvent);
|
||||
UseUiEvent(UpdateDoorStateEvent.STATE_WAITING, onUpdateDoorStateEvent);
|
||||
UseUiEvent(UpdateDoorStateEvent.STATE_NO_ANSWER, onUpdateDoorStateEvent);
|
||||
UseUiEvent(UpdateDoorStateEvent.STATE_WRONG_PASSWORD, onUpdateDoorStateEvent);
|
||||
UseUiEvent(UpdateDoorStateEvent.STATE_ACCEPTED, onUpdateDoorStateEvent);
|
||||
|
||||
const onRoomSessionEvent = useCallback((event: RoomSessionEvent) =>
|
||||
{
|
||||
switch(event.type)
|
||||
@ -107,18 +63,6 @@ export const NavigatorView: FC<{}> = props =>
|
||||
|
||||
UseRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent);
|
||||
|
||||
const closePendingDoorState = useCallback((state: string) =>
|
||||
{
|
||||
if(state !== null)
|
||||
{
|
||||
setPendingDoorState(prevValue =>
|
||||
{
|
||||
return { ...prevValue, state };
|
||||
});
|
||||
}
|
||||
else setPendingDoorState(null);
|
||||
}, []);
|
||||
|
||||
const sendSearch = useCallback((searchValue: string, contextCode: string) =>
|
||||
{
|
||||
setCreatorOpen(false);
|
||||
@ -292,28 +236,9 @@ export const NavigatorView: FC<{}> = props =>
|
||||
LegacyExternalInterface.addCallback(HabboWebTools.OPENROOM, (k: string, _arg_2: boolean = false, _arg_3: string = null) => SendMessageComposer(new ConvertGlobalRoomIdMessageComposer(k)));
|
||||
}, []);
|
||||
|
||||
const getRoomDoorState = useMemo(() =>
|
||||
{
|
||||
if(!pendingDoorState) return null;
|
||||
|
||||
switch(pendingDoorState.state)
|
||||
{
|
||||
case UpdateDoorStateEvent.START_DOORBELL:
|
||||
case UpdateDoorStateEvent.STATE_WAITING:
|
||||
case UpdateDoorStateEvent.STATE_NO_ANSWER:
|
||||
return <NavigatorRoomDoorbellView roomData={ pendingDoorState.roomData } state={ pendingDoorState.state } onClose={ closePendingDoorState } />;
|
||||
case UpdateDoorStateEvent.START_PASSWORD:
|
||||
case UpdateDoorStateEvent.STATE_WRONG_PASSWORD:
|
||||
return <NavigatorRoomPasswordView roomData={ pendingDoorState.roomData } state={ pendingDoorState.state } onClose={ closePendingDoorState } />;
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [ pendingDoorState, closePendingDoorState ]);
|
||||
|
||||
return (
|
||||
<NavigatorContextProvider value={ { categories, setCategories, topLevelContext, setTopLevelContext, topLevelContexts, setTopLevelContexts, navigatorData, setNavigatorData, searchResult, setSearchResult } }>
|
||||
<NavigatorContextProvider value={ { categories, setCategories, topLevelContext, setTopLevelContext, topLevelContexts, setTopLevelContexts, navigatorData, setNavigatorData, doorData, setDoorData, searchResult, setSearchResult } }>
|
||||
<NavigatorMessageHandler />
|
||||
{ getRoomDoorState }
|
||||
{ isVisible &&
|
||||
<NitroCardView uniqueKey="navigator" className="nitro-navigator">
|
||||
<NitroCardHeaderView headerText={ LocalizeText(isCreatorOpen ? 'navigator.createroom.title' : 'navigator.title') } onCloseClick={ event => setIsVisible(false) } />
|
||||
@ -343,6 +268,7 @@ export const NavigatorView: FC<{}> = props =>
|
||||
{ isCreatorOpen && <NavigatorRoomCreatorView /> }
|
||||
</NitroCardContentView>
|
||||
</NitroCardView> }
|
||||
<NavigatorDoorStateView />
|
||||
{ isRoomInfoOpen && <NavigatorRoomInfoView onCloseClick={ () => setRoomInfoOpen(false) } /> }
|
||||
{ isRoomLinkOpen && <NavigatorRoomLinkView onCloseClick={ () => setRoomLinkOpen(false) } /> }
|
||||
<NavigatorRoomSettingsView />
|
||||
|
12
src/components/navigator/common/DoorStateType.ts
Normal file
12
src/components/navigator/common/DoorStateType.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export class DoorStateType
|
||||
{
|
||||
public static NONE: number = 0;
|
||||
public static START_DOORBELL: number = 1;
|
||||
public static START_PASSWORD: number = 2;
|
||||
public static STATE_PENDING_SERVER: number = 3;
|
||||
public static UPDATE_STATE: number = 4;
|
||||
public static STATE_WAITING: number = 5;
|
||||
public static STATE_NO_ANSWER: number = 6;
|
||||
public static STATE_WRONG_PASSWORD: number = 7;
|
||||
public static STATE_ACCEPTED: number = 8;
|
||||
}
|
111
src/components/navigator/views/NavigatorDoorStateView.tsx
Normal file
111
src/components/navigator/views/NavigatorDoorStateView.tsx
Normal file
@ -0,0 +1,111 @@
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { CreateRoomSession, 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 ];
|
||||
const DOORBELL_STATES = [ DoorStateType.START_DOORBELL, DoorStateType.STATE_WAITING, DoorStateType.STATE_NO_ANSWER ];
|
||||
const PASSWORD_STATES = [ DoorStateType.START_PASSWORD, DoorStateType.STATE_WRONG_PASSWORD ];
|
||||
|
||||
export const NavigatorDoorStateView: FC<{}> = props =>
|
||||
{
|
||||
const [ password, setPassword ] = useState('');
|
||||
const { doorData = null, setDoorData = null } = useNavigatorContext();
|
||||
|
||||
const close = () =>
|
||||
{
|
||||
if(doorData && (doorData.state === DoorStateType.STATE_WAITING)) GoToDesktop();
|
||||
|
||||
setDoorData(null);
|
||||
}
|
||||
|
||||
const ring = () =>
|
||||
{
|
||||
if(!doorData || !doorData.roomInfo) return;
|
||||
|
||||
CreateRoomSession(doorData.roomInfo.roomId);
|
||||
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_PENDING_SERVER;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
|
||||
const tryEntering = () =>
|
||||
{
|
||||
if(!doorData || !doorData.roomInfo) return;
|
||||
|
||||
CreateRoomSession(doorData.roomInfo.roomId, password);
|
||||
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.state = DoorStateType.STATE_PENDING_SERVER;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!doorData || (doorData.state !== DoorStateType.STATE_NO_ANSWER)) return;
|
||||
|
||||
GoToDesktop();
|
||||
}, [ doorData ]);
|
||||
|
||||
if(!doorData || (doorData.state === DoorStateType.NONE) || (VISIBLE_STATES.indexOf(doorData.state) === -1)) return null;
|
||||
|
||||
const isDoorbell = (DOORBELL_STATES.indexOf(doorData.state) >= 0);
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitro-navigator-doorbell" theme="primary-slim">
|
||||
<NitroCardHeaderView headerText={ LocalizeText(isDoorbell ? 'navigator.doorbell.title' : 'navigator.password.title') } onCloseClick={ close } />
|
||||
<NitroCardContentView>
|
||||
<Column gap={ 1 }>
|
||||
<Text bold>{ doorData && doorData.roomInfo && doorData.roomInfo.roomName }</Text>
|
||||
{ (doorData.state === DoorStateType.START_DOORBELL) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.info') }</Text> }
|
||||
{ (doorData.state === DoorStateType.STATE_WAITING) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.waiting') }</Text> }
|
||||
{ (doorData.state === DoorStateType.STATE_NO_ANSWER) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.no.answer') }</Text> }
|
||||
{ (doorData.state === DoorStateType.START_PASSWORD) &&
|
||||
<Text>{ LocalizeText('navigator.password.info') }</Text> }
|
||||
{ (doorData.state === DoorStateType.STATE_WRONG_PASSWORD) &&
|
||||
<Text>{ LocalizeText('navigator.password.retryinfo') }</Text> }
|
||||
</Column>
|
||||
{ isDoorbell &&
|
||||
<Column gap={ 1 }>
|
||||
{ (doorData.state === DoorStateType.START_DOORBELL) &&
|
||||
<Button variant="success" onClick={ ring }>
|
||||
{ LocalizeText('navigator.doorbell.button.ring') }
|
||||
</Button> }
|
||||
<Button variant="danger" onClick={ close }>
|
||||
{ LocalizeText('generic.cancel') }
|
||||
</Button>
|
||||
</Column> }
|
||||
{ !isDoorbell &&
|
||||
<>
|
||||
<Column gap={ 1 }>
|
||||
<Text>{ LocalizeText('navigator.password.enter') }</Text>
|
||||
<input type="password" className="form-control form-control-sm" onChange={ event => setPassword(event.target.value) } />
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
<Button variant="success" onClick={ tryEntering }>
|
||||
{ LocalizeText('navigator.password.button.try') }
|
||||
</Button>
|
||||
<Button variant="danger" onClick={ close }>
|
||||
{ LocalizeText('generic.cancel') }
|
||||
</Button>
|
||||
</Column>
|
||||
</> }
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { FC } from 'react';
|
||||
import { CreateRoomSession, GoToDesktop, LocalizeText } from '../../../api';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../common';
|
||||
import { Button } from '../../../common/Button';
|
||||
import { Column } from '../../../common/Column';
|
||||
import { Text } from '../../../common/Text';
|
||||
import { UpdateDoorStateEvent } from '../../../events';
|
||||
|
||||
export interface NavigatorRoomDoorbellViewProps
|
||||
{
|
||||
roomData: RoomDataParser;
|
||||
state: string;
|
||||
onClose: (state: string) => void;
|
||||
}
|
||||
|
||||
export const NavigatorRoomDoorbellView: FC<NavigatorRoomDoorbellViewProps> = props =>
|
||||
{
|
||||
const { roomData = null, state = null, onClose = null } = props;
|
||||
|
||||
const close = () =>
|
||||
{
|
||||
if(state === UpdateDoorStateEvent.STATE_WAITING) GoToDesktop();
|
||||
|
||||
onClose(null);
|
||||
}
|
||||
|
||||
const ring = () =>
|
||||
{
|
||||
if(!roomData) return;
|
||||
|
||||
CreateRoomSession(roomData.roomId);
|
||||
|
||||
onClose(UpdateDoorStateEvent.STATE_PENDING_SERVER);
|
||||
}
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitro-navigator-doorbell" theme="primary-slim">
|
||||
<NitroCardHeaderView headerText={ LocalizeText('navigator.doorbell.title') } onCloseClick={ close } />
|
||||
<NitroCardContentView>
|
||||
<Column gap={ 1 }>
|
||||
{ roomData &&
|
||||
<Text bold>{ roomData.roomName }</Text> }
|
||||
{ (state === UpdateDoorStateEvent.START_DOORBELL) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.info') }</Text> }
|
||||
{ (state === UpdateDoorStateEvent.STATE_WAITING) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.waiting') }</Text> }
|
||||
{ (state === UpdateDoorStateEvent.STATE_NO_ANSWER) &&
|
||||
<Text>{ LocalizeText('navigator.doorbell.no.answer') }</Text> }
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
{ (state === UpdateDoorStateEvent.START_DOORBELL) &&
|
||||
<Button variant="success" onClick={ ring }>
|
||||
{ LocalizeText('navigator.doorbell.button.ring') }
|
||||
</Button> }
|
||||
<Button variant="danger" onClick={ close }>
|
||||
{ LocalizeText('generic.cancel') }
|
||||
</Button>
|
||||
</Column>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { CreateRoomSession, LocalizeText } from '../../../api';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../common';
|
||||
import { Button } from '../../../common/Button';
|
||||
import { Column } from '../../../common/Column';
|
||||
import { Text } from '../../../common/Text';
|
||||
import { UpdateDoorStateEvent } from '../../../events';
|
||||
|
||||
export interface NavigatorRoomPasswordViewProps
|
||||
{
|
||||
roomData: RoomDataParser;
|
||||
state: string;
|
||||
onClose: (state: string) => void;
|
||||
}
|
||||
|
||||
export const NavigatorRoomPasswordView: FC<NavigatorRoomPasswordViewProps> = props =>
|
||||
{
|
||||
const { roomData = null, state = null, onClose = null } = props;
|
||||
const [ password, setPassword ] = useState('');
|
||||
|
||||
const close = () =>
|
||||
{
|
||||
onClose(null);
|
||||
}
|
||||
|
||||
const tryEntering = useCallback(() =>
|
||||
{
|
||||
if(!roomData) return;
|
||||
|
||||
CreateRoomSession(roomData.roomId, password);
|
||||
|
||||
onClose(UpdateDoorStateEvent.STATE_PENDING_SERVER);
|
||||
}, [ roomData, password, onClose ]);
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitro-navigator-password" theme="primary-slim">
|
||||
<NitroCardHeaderView headerText={ LocalizeText('navigator.password.title') } onCloseClick={ close } />
|
||||
<NitroCardContentView>
|
||||
<Column gap={ 1 }>
|
||||
{ roomData &&
|
||||
<Text bold>{ roomData.roomName }</Text> }
|
||||
{ (state === UpdateDoorStateEvent.START_PASSWORD) &&
|
||||
<Text>{ LocalizeText('navigator.password.info') }</Text> }
|
||||
{ (state === UpdateDoorStateEvent.STATE_WRONG_PASSWORD) &&
|
||||
<Text>{ LocalizeText('navigator.password.retryinfo') }</Text> }
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
<Text>{ LocalizeText('navigator.password.enter') }</Text>
|
||||
<input type="password" className="form-control form-control-sm" onChange={ event => setPassword(event.target.value) } />
|
||||
</Column>
|
||||
<Button variant="success" onClick={ tryEntering }>
|
||||
{ LocalizeText('navigator.password.button.try') }</Button>
|
||||
<Button variant="danger" onClick={ close }>
|
||||
{ LocalizeText('generic.cancel') }
|
||||
</Button>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
}
|
@ -3,8 +3,8 @@ import { RoomDataParser } from '@nitrots/nitro-renderer';
|
||||
import { FC, MouseEvent } from 'react';
|
||||
import { CreateRoomSession, GetSessionDataManager, TryVisitRoom } from '../../../../api';
|
||||
import { Column, Flex, LayoutBadgeImageView, LayoutGridItemProps, LayoutRoomThumbnailView, Text } from '../../../../common';
|
||||
import { UpdateDoorStateEvent } from '../../../../events';
|
||||
import { DispatchUiEvent } from '../../../../hooks';
|
||||
import { DoorStateType } from '../../common/DoorStateType';
|
||||
import { useNavigatorContext } from '../../NavigatorContext';
|
||||
import { NavigatorSearchResultItemInfoView } from './NavigatorSearchResultItemInfoView';
|
||||
|
||||
export interface NavigatorSearchResultItemViewProps extends LayoutGridItemProps
|
||||
@ -16,6 +16,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();
|
||||
|
||||
function getUserCounterColor(): string
|
||||
{
|
||||
@ -53,10 +54,26 @@ export const NavigatorSearchResultItemView: FC<NavigatorSearchResultItemViewProp
|
||||
switch(roomData.doorMode)
|
||||
{
|
||||
case RoomDataParser.DOORBELL_STATE:
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.START_DOORBELL, roomData));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.roomInfo = roomData;
|
||||
newValue.state = DoorStateType.START_DOORBELL;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
return;
|
||||
case RoomDataParser.PASSWORD_STATE:
|
||||
DispatchUiEvent(new UpdateDoorStateEvent(UpdateDoorStateEvent.START_PASSWORD, roomData));
|
||||
setDoorData(prevValue =>
|
||||
{
|
||||
const newValue = { ...prevValue };
|
||||
|
||||
newValue.roomInfo = roomData;
|
||||
newValue.state = DoorStateType.START_PASSWORD;
|
||||
|
||||
return newValue;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user