Merge pull request #45 from billsonnn/patch/style-fixes

add habblet link handler
This commit is contained in:
Bill 2021-12-05 22:06:59 -05:00 committed by GitHub
commit 367c1ec4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import { RoomSessionEvent } from '@nitrots/nitro-renderer';
import { HabboWebTools, RoomSessionEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react';
import { GetCommunication } from '../../api';
import { AddEventLinkTracker, GetCommunication, RemoveLinkEventTracker } from '../../api';
import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event';
import { TransitionAnimation, TransitionAnimationTypes } from '../../layout';
import { AchievementsView } from '../achievements/AchievementsView';
@ -47,6 +47,32 @@ export const MainView: FC<MainViewProps> = props =>
useRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent);
useRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent);
const onLinkReceived = useCallback((link: string) =>
{
const parts = link.split('/');
if(parts.length < 2) return;
switch(parts[1])
{
case 'open':
if(parts.length > 2)
{
switch(parts[2])
{
case 'credits':
//HabboWebTools.openWebPageAndMinimizeClient(this._windowManager.getProperty(ExternalVariables.WEB_SHOP_RELATIVE_URL));
break;
default: {
const name = parts[2];
HabboWebTools.openHabblet(name);
}
}
}
return;
}
}, []);
useEffect(() =>
{
setIsReady(true);
@ -54,6 +80,17 @@ export const MainView: FC<MainViewProps> = props =>
GetCommunication().connection.onReady();
}, []);
useEffect(() =>
{
const linkTracker = { linkReceived: onLinkReceived, eventUrlPrefix: 'habblet/' };
AddEventLinkTracker(linkTracker);
return () =>
{
RemoveLinkEventTracker(linkTracker);
}
}, [onLinkReceived]);
return (
<div className="nitro-main">
<TransitionAnimation type={ TransitionAnimationTypes.FADE_IN } inProp={ landingViewVisible } timeout={ 300 }>

View File

@ -1,7 +1,8 @@
import { ILinkEventTracker, NavigatorInitComposer, NavigatorSearchComposer, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer';
import { ConvertGlobalRoomIdMessageComposer, HabboWebTools, ILinkEventTracker, LegacyExternalInterface, NavigatorInitComposer, NavigatorSearchComposer, RoomDataParser, RoomSessionEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useMemo, useReducer, useState } from 'react';
import { AddEventLinkTracker, GoToDesktop, LocalizeText, RemoveLinkEventTracker, TryVisitRoom } from '../../api';
import { NavigatorEvent, UpdateDoorStateEvent } from '../../events';
import { UseMountEffect } from '../../hooks';
import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event';
import { useUiEvent } from '../../hooks/events/ui/ui-event';
import { SendMessageHook } from '../../hooks/messages/message-event';
@ -181,6 +182,16 @@ export const NavigatorView: FC<NavigatorViewProps> = props =>
return () => RemoveLinkEventTracker(linkTracker);
}, [ linkReceived]);
const enterRoomWebRequest = useCallback((k: string, _arg_2:boolean=false, _arg_3:string=null) =>
{
SendMessageHook(new ConvertGlobalRoomIdMessageComposer(k));
}, []);
UseMountEffect(() =>
{
LegacyExternalInterface.addCallback(HabboWebTools.OPENROOM, enterRoomWebRequest);
});
useEffect(() =>
{
if(!isVisible || !needsNavigatorUpdate) return;