mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 08:50:51 +01:00
Update nitropedia
This commit is contained in:
parent
9cddf652ba
commit
c2762cc0d0
@ -13,6 +13,7 @@
|
|||||||
@import './loading/LoadingView';
|
@import './loading/LoadingView';
|
||||||
@import './mod-tools/ModToolsView';
|
@import './mod-tools/ModToolsView';
|
||||||
@import './navigator/NavigatorView';
|
@import './navigator/NavigatorView';
|
||||||
|
@import './nitropedia/NitropediaView';
|
||||||
@import './notification-center/NotificationCenterView';
|
@import './notification-center/NotificationCenterView';
|
||||||
@import './purse/PurseView';
|
@import './purse/PurseView';
|
||||||
@import './right-side/RightSideView';
|
@import './right-side/RightSideView';
|
||||||
|
@ -5,7 +5,6 @@ import { Base, TransitionAnimation, TransitionAnimationTypes } from '../../commo
|
|||||||
import { UseRoomSessionManagerEvent } from '../../hooks';
|
import { UseRoomSessionManagerEvent } from '../../hooks';
|
||||||
import { HcCenterView } from '../../views/hc-center/HcCenterView';
|
import { HcCenterView } from '../../views/hc-center/HcCenterView';
|
||||||
import { HotelView } from '../../views/hotel-view/HotelView';
|
import { HotelView } from '../../views/hotel-view/HotelView';
|
||||||
import { NitropediaView } from '../../views/nitropedia/NitropediaView';
|
|
||||||
import { AchievementsView } from '../achievements/AchievementsView';
|
import { AchievementsView } from '../achievements/AchievementsView';
|
||||||
import { AvatarEditorView } from '../avatar-editor/AvatarEditorView';
|
import { AvatarEditorView } from '../avatar-editor/AvatarEditorView';
|
||||||
import { CameraWidgetView } from '../camera/CameraWidgetView';
|
import { CameraWidgetView } from '../camera/CameraWidgetView';
|
||||||
@ -20,6 +19,7 @@ import { HelpView } from '../help/HelpView';
|
|||||||
import { InventoryView } from '../inventory/InventoryView';
|
import { InventoryView } from '../inventory/InventoryView';
|
||||||
import { ModToolsView } from '../mod-tools/ModToolsView';
|
import { ModToolsView } from '../mod-tools/ModToolsView';
|
||||||
import { NavigatorView } from '../navigator/NavigatorView';
|
import { NavigatorView } from '../navigator/NavigatorView';
|
||||||
|
import { NitropediaView } from '../nitropedia/NitropediaView';
|
||||||
import { RightSideView } from '../right-side/RightSideView';
|
import { RightSideView } from '../right-side/RightSideView';
|
||||||
import { RoomHostView } from '../room/RoomHostView';
|
import { RoomHostView } from '../room/RoomHostView';
|
||||||
import { ToolbarView } from '../toolbar/ToolbarView';
|
import { ToolbarView } from '../toolbar/ToolbarView';
|
||||||
|
@ -1,25 +1,43 @@
|
|||||||
import { MouseEventType } from '@nitrots/nitro-renderer';
|
import { MouseEventType } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useEffect, useRef, useState } from 'react';
|
import { FC, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { AddEventLinkTracker, GetConfiguration, NotificationUtilities, RemoveLinkEventTracker } from '../../api';
|
import { AddEventLinkTracker, GetConfiguration, NotificationUtilities, RemoveLinkEventTracker } from '../../api';
|
||||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common';
|
import { Base, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common';
|
||||||
|
import { BatchUpdates } from '../../hooks';
|
||||||
|
|
||||||
|
const NEW_LINE_REGEX = /\n\r|\n|\r/mg;
|
||||||
|
|
||||||
const newLineRegex = /\n\r|\n|\r/mg;
|
|
||||||
export const NitropediaView: FC<{}> = props =>
|
export const NitropediaView: FC<{}> = props =>
|
||||||
{
|
{
|
||||||
const [ content, setContent ] = useState<string>(null);
|
const [ content, setContent ] = useState<string>(null);
|
||||||
const [ header, setHeader ] = useState<string>('');
|
const [ header, setHeader ] = useState<string>('');
|
||||||
const elementRef = useRef<HTMLDivElement>(null);
|
const elementRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const openPage = useCallback((link: string) =>
|
const openPage = useCallback(async (link: string) =>
|
||||||
{
|
{
|
||||||
fetch(link)
|
const response = await fetch(link);
|
||||||
.then(response => response.text())
|
|
||||||
.then(data =>
|
if(!response) return;
|
||||||
{
|
|
||||||
const splitData = data.split(newLineRegex);
|
const text = await response.text();
|
||||||
setHeader(splitData.shift());
|
|
||||||
setContent(splitData.join(''));
|
const splitData = text.split(NEW_LINE_REGEX);
|
||||||
})
|
|
||||||
|
BatchUpdates(() =>
|
||||||
|
{
|
||||||
|
setHeader(splitData.shift());
|
||||||
|
setContent(splitData.join(''));
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onClick = useCallback((event: MouseEvent) =>
|
||||||
|
{
|
||||||
|
if(!(event.target instanceof HTMLAnchorElement)) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const link = event.target.href;
|
||||||
|
|
||||||
|
NotificationUtilities.openUrl(link);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onLinkReceived = useCallback((link: string) =>
|
const onLinkReceived = useCallback((link: string) =>
|
||||||
@ -31,46 +49,27 @@ export const NitropediaView: FC<{}> = props =>
|
|||||||
value.shift();
|
value.shift();
|
||||||
|
|
||||||
openPage(GetConfiguration<string>('habbopages.url') + value.join('/'));
|
openPage(GetConfiguration<string>('habbopages.url') + value.join('/'));
|
||||||
}, [openPage]);
|
}, [ openPage ]);
|
||||||
|
|
||||||
const onClick = useCallback((event: MouseEvent) =>
|
|
||||||
{
|
|
||||||
if(event.target instanceof HTMLAnchorElement)
|
|
||||||
{
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
const link = event.target.href;
|
|
||||||
|
|
||||||
NotificationUtilities.openUrl(link);
|
|
||||||
}
|
|
||||||
|
|
||||||
},[]);
|
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
const linkTracker = { linkReceived: onLinkReceived, eventUrlPrefix: 'habbopages/' };
|
const linkTracker = { linkReceived: onLinkReceived, eventUrlPrefix: 'habbopages/' };
|
||||||
|
|
||||||
AddEventLinkTracker(linkTracker);
|
AddEventLinkTracker(linkTracker);
|
||||||
|
|
||||||
return () =>
|
return () => RemoveLinkEventTracker(linkTracker);
|
||||||
{
|
}, [ onLinkReceived ]);
|
||||||
RemoveLinkEventTracker(linkTracker);
|
|
||||||
}
|
|
||||||
}, [onLinkReceived]);
|
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
const element = elementRef.current;
|
const element = elementRef.current;
|
||||||
|
|
||||||
if(element)
|
if(!element) return;
|
||||||
{
|
|
||||||
element.addEventListener(MouseEventType.MOUSE_CLICK, onClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () =>
|
element.addEventListener(MouseEventType.MOUSE_CLICK, onClick);
|
||||||
{
|
|
||||||
if(element) element.removeEventListener(MouseEventType.MOUSE_CLICK, onClick);
|
return () => element.removeEventListener(MouseEventType.MOUSE_CLICK, onClick);
|
||||||
}
|
}, [ onClick, content ]);
|
||||||
}, [onClick, content]);
|
|
||||||
|
|
||||||
if(!content) return null;
|
if(!content) return null;
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ export const NitropediaView: FC<{}> = props =>
|
|||||||
<NitroCardView className="nitropedia">
|
<NitroCardView className="nitropedia">
|
||||||
<NitroCardHeaderView headerText={header} onCloseClick={() => setContent(null)}/>
|
<NitroCardHeaderView headerText={header} onCloseClick={() => setContent(null)}/>
|
||||||
<NitroCardContentView>
|
<NitroCardContentView>
|
||||||
<div ref={elementRef} className="w-100 h-100 text-black" dangerouslySetInnerHTML={{ __html: content }} />
|
<Base fit innerRef={ elementRef } className="text-black" dangerouslySetInnerHTML={{ __html: content }} />
|
||||||
</NitroCardContentView>
|
</NitroCardContentView>
|
||||||
</NitroCardView>
|
</NitroCardView>
|
||||||
);
|
);
|
@ -1,3 +1,2 @@
|
|||||||
@import "./hotel-view/HotelView";
|
@import "./hotel-view/HotelView";
|
||||||
@import "./nitropedia/NitropediaView";
|
|
||||||
@import "./hc-center/HcCenterView.scss";
|
@import "./hc-center/HcCenterView.scss";
|
||||||
|
Loading…
Reference in New Issue
Block a user