diff --git a/src/api/utils/CloneObject.ts b/src/api/utils/CloneObject.ts new file mode 100644 index 00000000..6cd8d3eb --- /dev/null +++ b/src/api/utils/CloneObject.ts @@ -0,0 +1,14 @@ +export const CloneObject = (object: T): T => +{ + if((object == null) || ('object' != typeof object)) return object; + + // @ts-ignore + const copy = new object.constructor(); + + for(const attr in object) + { + if(object.hasOwnProperty(attr)) copy[attr] = object[attr]; + } + + return copy; +} diff --git a/src/api/utils/index.ts b/src/api/utils/index.ts index 6e223495..398758cb 100644 --- a/src/api/utils/index.ts +++ b/src/api/utils/index.ts @@ -1,3 +1,4 @@ +export * from './CloneObject'; export * from './ColorUtils'; export * from './LocalizeBadgeDescription'; export * from './LocalizeBageName'; diff --git a/src/common/Base.tsx b/src/common/Base.tsx index 72ee2c27..8bffe170 100644 --- a/src/common/Base.tsx +++ b/src/common/Base.tsx @@ -1,9 +1,9 @@ -import { CSSProperties, DetailedHTMLProps, FC, HTMLAttributes, LegacyRef, useMemo } from 'react'; +import { CSSProperties, DetailedHTMLProps, FC, HTMLAttributes, MutableRefObject, useMemo } from 'react'; import { ColorVariantType, DisplayType, FloatType, OverflowType, PositionType } from './types'; export interface BaseProps extends DetailedHTMLProps, T> { - innerRef?: LegacyRef; + innerRef?: MutableRefObject; display?: DisplayType; fit?: boolean; grow?: boolean; diff --git a/src/components/nitropedia/NitropediaView.tsx b/src/components/nitropedia/NitropediaView.tsx index 865a2acd..165219f7 100644 --- a/src/components/nitropedia/NitropediaView.tsx +++ b/src/components/nitropedia/NitropediaView.tsx @@ -1,3 +1,4 @@ +import { NitroLogger } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { AddEventLinkTracker, GetConfiguration, NotificationUtilities, RemoveLinkEventTracker } from '../../api'; import { Base, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; @@ -13,19 +14,28 @@ export const NitropediaView: FC<{}> = props => const openPage = useCallback(async (link: string) => { - const response = await fetch(link); - - if(!response) return; - - const text = await response.text(); - - const splitData = text.split(NEW_LINE_REGEX); - - BatchUpdates(() => + console.log(link); + try { - setHeader(splitData.shift()); - setContent(splitData.join('')); - }); + const response = await fetch(link); + + if(!response) return; + + const text = await response.text(); + + const splitData = text.split(NEW_LINE_REGEX); + + BatchUpdates(() => + { + setHeader(splitData.shift()); + setContent(splitData.join('')); + }); + } + + catch (error) + { + NitroLogger.error(`Failed to fetch ${ link }`); + } }, []); const onLinkReceived = useCallback((link: string) => diff --git a/src/components/room/RoomView.tsx b/src/components/room/RoomView.tsx index ce2743f3..ccb1c1fd 100644 --- a/src/components/room/RoomView.tsx +++ b/src/components/room/RoomView.tsx @@ -121,7 +121,7 @@ export const RoomView: FC = props => GetNitroInstance().render(); } - if(elementRef && elementRef.current) elementRef.current.appendChild(canvas); + if(elementRef && elementRef.current) elementRef.current.replaceChildren(canvas); setCanvasId(canvasId); }, [ roomSession ]); diff --git a/src/components/room/widgets/avatar-info/AvatarInfoWidgetAvatarView.tsx b/src/components/room/widgets/avatar-info/AvatarInfoWidgetAvatarView.tsx index a1ec2437..d7302ab4 100644 --- a/src/components/room/widgets/avatar-info/AvatarInfoWidgetAvatarView.tsx +++ b/src/components/room/widgets/avatar-info/AvatarInfoWidgetAvatarView.tsx @@ -199,7 +199,6 @@ export const AvatarInfoWidgetAvatarView: FC = p break; case 'rship_none': messageType = RoomWidgetUserActionMessage.RELATIONSHIP_NONE; - console.log('here') break; } diff --git a/src/components/room/widgets/furniture/background-color/FurnitureBackgroundColorView.tsx b/src/components/room/widgets/furniture/background-color/FurnitureBackgroundColorView.tsx index de6b1e54..a0b09924 100644 --- a/src/components/room/widgets/furniture/background-color/FurnitureBackgroundColorView.tsx +++ b/src/components/room/widgets/furniture/background-color/FurnitureBackgroundColorView.tsx @@ -23,11 +23,7 @@ export const FurnitureBackgroundColorView: FC<{}> = props => const canOpenBackgroundToner = useCallback(() => { - const isRoomOwner = roomSession.isRoomOwner; - const hasLevel = (roomSession.controllerLevel >= RoomControllerLevel.GUEST); - const isGodMode = GetSessionDataManager().isGodMode; - - return (isRoomOwner || hasLevel || isGodMode); + return (roomSession.isRoomOwner || (roomSession.controllerLevel >= RoomControllerLevel.GUEST) || GetSessionDataManager().isModerator); }, [ roomSession ]); const onRoomEngineObjectEvent = useCallback((event: RoomEngineObjectEvent) => diff --git a/src/components/room/widgets/infostand/InfoStandWidgetUserRelationshipsView.tsx b/src/components/room/widgets/infostand/InfoStandWidgetUserRelationshipsView.tsx index ced56dd2..f7aa72fc 100644 --- a/src/components/room/widgets/infostand/InfoStandWidgetUserRelationshipsView.tsx +++ b/src/components/room/widgets/infostand/InfoStandWidgetUserRelationshipsView.tsx @@ -30,7 +30,7 @@ export const InfoStandWidgetUserRelationshipsView: FC GetUserProfile(relationshipInfo.randomFriendId) }> - { relationshipInfo.randomFriendName } + { relationshipInfo.randomFriendName } { (relationshipInfo.friendCount > 1) && (' ' + LocalizeText(`extendedprofile.relstatus.others.${ relationshipName }`, [ 'count' ], [ (relationshipInfo.friendCount - 1).toString() ])) } diff --git a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx index 925300ef..b35cd7bd 100644 --- a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx +++ b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx @@ -65,11 +65,6 @@ export const RoomToolsWidgetView: FC<{}> = props => return () => clearTimeout(timeout); }, [ roomName, roomOwner, roomTags ]); - - useEffect(() => - { - console.log(navigatorData); - }, [ navigatorData ]); return (