From e4a9b8a9babecccd940b8c9efcf37e48b8ce1837 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Tue, 13 Dec 2022 01:40:04 +0100 Subject: [PATCH 1/2] Issue #75 - Room settings tags --- src/api/navigator/RoomSettingsErrorType.ts | 10 +++ src/api/navigator/index.ts | 1 + .../navigator/views/NavigatorRoomInfoView.tsx | 4 +- .../NavigatorRoomSettingsBasicTabView.tsx | 74 +++++++++++++++++-- .../NavigatorRoomSettingsView.tsx | 5 +- src/components/room/widgets/RoomWidgets.scss | 1 - .../room-tools/RoomToolsWidgetView.tsx | 16 ++-- 7 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 src/api/navigator/RoomSettingsErrorType.ts diff --git a/src/api/navigator/RoomSettingsErrorType.ts b/src/api/navigator/RoomSettingsErrorType.ts new file mode 100644 index 00000000..8fbe90f5 --- /dev/null +++ b/src/api/navigator/RoomSettingsErrorType.ts @@ -0,0 +1,10 @@ +export class RoomSettingsErrorType +{ + public static readonly PASSWORD_REQUIRED = 5; + public static readonly ROOM_NAME_MISSING = 7; + public static readonly ROOM_NAME_BADWORDS = 8; + public static readonly ROOM_DESCRIPTION_BADWORDS = 10; + public static readonly ROOM_TAGS_BADWWORDS = 11; + public static readonly RESTRICTED_TAGS = 12; + public static readonly TAGS_TOO_LONG = 13; +} diff --git a/src/api/navigator/index.ts b/src/api/navigator/index.ts index bceb33e4..08e40ccc 100644 --- a/src/api/navigator/index.ts +++ b/src/api/navigator/index.ts @@ -7,6 +7,7 @@ export * from './IRoomModel'; export * from './IRoomModerationSettings'; export * from './NavigatorSearchResultViewDisplayMode'; export * from './RoomInfoData'; +export * from './RoomSettingsErrorType'; export * from './RoomSettingsUtils'; export * from './SearchFilterOptions'; export * from './TryVisitRoom'; diff --git a/src/components/navigator/views/NavigatorRoomInfoView.tsx b/src/components/navigator/views/NavigatorRoomInfoView.tsx index 2651d8a4..cf80b472 100644 --- a/src/components/navigator/views/NavigatorRoomInfoView.tsx +++ b/src/components/navigator/views/NavigatorRoomInfoView.tsx @@ -1,5 +1,5 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { RoomMuteComposer, RoomSettingsComposer, SecurityLevel, ToggleStaffPickMessageComposer, UpdateHomeRoomMessageComposer } from '@nitrots/nitro-renderer'; +import { NavigatorSearchComposer, RoomMuteComposer, RoomSettingsComposer, SecurityLevel, ToggleStaffPickMessageComposer, UpdateHomeRoomMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, DispatchUiEvent, GetGroupInformation, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../api'; import { Button, classNames, Column, Flex, LayoutBadgeImageView, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text, UserProfileIconView } from '../../../common'; @@ -47,6 +47,8 @@ export const NavigatorRoomInfoView: FC = props => if(newRoomId > 0) SendMessageComposer(new UpdateHomeRoomMessageComposer(newRoomId)); return; case 'navigator_search_tag': + CreateLinkEvent(`navigator/search/${ value }`); + SendMessageComposer(new NavigatorSearchComposer('hotel_view', `tag:${ value }`)); return; case 'open_room_thumbnail_camera': DispatchUiEvent(new RoomWidgetThumbnailEvent(RoomWidgetThumbnailEvent.TOGGLE_THUMBNAIL)); diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx index 70c51b37..247d82de 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx @@ -1,30 +1,52 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { RoomDeleteComposer } from '@nitrots/nitro-renderer'; +import { RoomDeleteComposer, RoomSettingsSaveErrorEvent } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; -import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, SendMessageComposer } from '../../../../api'; +import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, RoomSettingsErrorType, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, Text } from '../../../../common'; -import { useNavigator, useNotification } from '../../../../hooks'; +import { useMessageEvent, useNavigator, useNotification } from '../../../../hooks'; const ROOM_NAME_MIN_LENGTH = 3; const ROOM_NAME_MAX_LENGTH = 60; const DESC_MAX_LENGTH = 255; +const TAGS_MAX_LENGTH = 15; interface NavigatorRoomSettingsTabViewProps { roomData: IRoomData; - handleChange: (field: string, value: string | number | boolean) => void; + handleChange: (field: string, value: string | number | boolean | string[]) => void; onClose: () => void; } - export const NavigatorRoomSettingsBasicTabView: FC = props => { const { roomData = null, handleChange = null, onClose = null } = props; const [ roomName, setRoomName ] = useState(''); const [ roomDescription, setRoomDescription ] = useState(''); + const [ roomTag1, setRoomTag1 ] = useState(''); + const [ roomTag2, setRoomTag2 ] = useState(''); + const [ tagIndex, setTagIndex ] = useState(0); + const [ typeError, setTypeError ] = useState(''); const { showConfirm = null } = useNotification(); const { categories = null } = useNavigator(); + useMessageEvent(RoomSettingsSaveErrorEvent, event => + { + const parser = event.getParser(); + + if (!parser) return; + + switch (parser.code) + { + case RoomSettingsErrorType.ROOM_TAGS_BADWWORDS: + case RoomSettingsErrorType.RESTRICTED_TAGS: + setTypeError('trading.mode.not.allowed'); + break; + default: + setTypeError(''); + break; + } + }); + const deleteRoom = () => { showConfirm(LocalizeText('navigator.roomsettings.deleteroom.confirm.message', [ 'room_name' ], [ roomData.roomName ] ), () => @@ -50,12 +72,27 @@ export const NavigatorRoomSettingsBasicTabView: FC DESC_MAX_LENGTH)) return; handleChange('description', roomDescription); - } + } + + const saveTags = (index: number) => + { + if(index === 0 && (roomTag1 === roomData.tags[0]) || (roomTag1.length > TAGS_MAX_LENGTH)) return; + + if(index === 1 && (roomTag2 === roomData.tags[1]) || (roomTag2.length > TAGS_MAX_LENGTH)) return; + + if(roomTag1 === '' && roomTag2 !== '') setRoomTag2(''); + + setTypeError(''); + setTagIndex(index); + handleChange('tags', (roomTag1 === '' && roomTag2 !== '') ? [ roomTag2 ] : [ roomTag1, roomTag2 ]); + } useEffect(() => { setRoomName(roomData.roomName); setRoomDescription(roomData.roomDescription); + setRoomTag1((roomData.tags.length > 0 && roomData.tags[0]) ? roomData.tags[0] : ''); + setRoomTag2((roomData.tags.length > 0 && roomData.tags[1]) ? roomData.tags[1] : ''); }, [ roomData ]); return ( @@ -94,6 +131,31 @@ export const NavigatorRoomSettingsBasicTabView: FC{ LocalizeText('navigator.roomsettings.trade_allowed') } + + { LocalizeText('navigator.tags') } + + setRoomTag1(event.target.value) } onBlur={ () => saveTags(0) } /> + { (roomTag1.length > TAGS_MAX_LENGTH) && + + { LocalizeText('navigator.roomsettings.toomanycharacters') } + } + { (tagIndex === 0 && typeError != '') && + + { LocalizeText(typeError) } + } + + + setRoomTag2(event.target.value) } onBlur={ () => saveTags(1) } /> + { (roomTag2.length > TAGS_MAX_LENGTH) && + + { LocalizeText('navigator.roomsettings.toomanycharacters') } + } + { (tagIndex === 1 && typeError != '') && + + { LocalizeText(typeError) } + } + + handleChange('allow_walkthrough', event.target.checked) } /> diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx index ed03de13..bdda1779 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsView.tsx @@ -69,7 +69,7 @@ export const NavigatorRoomSettingsView: FC<{}> = props => setCurrentTab(TABS[0]); } - const handleChange = (field: string, value: string | number | boolean) => + const handleChange = (field: string, value: string | number | boolean | string[]) => { setRoomData(prevValue => { @@ -92,6 +92,9 @@ export const NavigatorRoomSettingsView: FC<{}> = props => case 'trade_state': newValue.tradeState = Number(value); break; + case 'tags': + newValue.tags = value as Array; + break; case 'allow_walkthrough': newValue.allowWalkthrough = Boolean(value); break; diff --git a/src/components/room/widgets/RoomWidgets.scss b/src/components/room/widgets/RoomWidgets.scss index a0757de9..38270c32 100644 --- a/src/components/room/widgets/RoomWidgets.scss +++ b/src/components/room/widgets/RoomWidgets.scss @@ -49,7 +49,6 @@ background: rgba($dark, .95); box-shadow: inset 0px 5px lighten(rgba($dark, .6), 2.5), inset 0 -4px darken(rgba($dark, .6), 4); transition: all .2s ease; - pointer-events: none; max-width: 250px; } } diff --git a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx index ab1db4bc..0bd2656b 100644 --- a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx +++ b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx @@ -1,4 +1,4 @@ -import { GetGuestRoomResultEvent, RateFlatMessageComposer } from '@nitrots/nitro-renderer'; +import { GetGuestRoomResultEvent, NavigatorSearchComposer, RateFlatMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; import { Base, classNames, Column, Flex, Text, TransitionAnimation, TransitionAnimationTypes } from '../../../../common'; @@ -14,7 +14,7 @@ export const RoomToolsWidgetView: FC<{}> = props => const { navigatorData = null } = useNavigator(); const { roomSession = null } = useRoom(); - const handleToolClick = (action: string) => + const handleToolClick = (action: string, value?: string) => { switch(action) { @@ -25,10 +25,10 @@ export const RoomToolsWidgetView: FC<{}> = props => setIsZoomedIn(prevValue => { let scale = GetRoomEngine().getRoomInstanceRenderingCanvasScale(roomSession.roomId, 1); - + if(!prevValue) scale /= 2; else scale *= 2; - + GetRoomEngine().setRoomInstanceRenderingCanvasScale(roomSession.roomId, 1, scale); return !prevValue; @@ -43,6 +43,10 @@ export const RoomToolsWidgetView: FC<{}> = props => case 'toggle_room_link': CreateLinkEvent('navigator/toggle-room-link'); return; + case 'navigator_search_tag': + CreateLinkEvent(`navigator/search/${ value }`); + SendMessageComposer(new NavigatorSearchComposer('hotel_view', `tag:${ value }`)); + return; } } @@ -65,7 +69,7 @@ export const RoomToolsWidgetView: FC<{}> = props => return () => clearTimeout(timeout); }, [ roomName, roomOwner, roomTags ]); - + return ( @@ -85,7 +89,7 @@ export const RoomToolsWidgetView: FC<{}> = props => { roomTags && roomTags.length > 0 && - { roomTags.map((tag, index) => #{ tag }) } + { roomTags.map((tag, index) => handleToolClick('navigator_search_tag', tag) }>#{ tag }) } } From 0a28e69e19eff291a4339bd44c4152b460af0e23 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Tue, 13 Dec 2022 21:52:40 +0100 Subject: [PATCH 2/2] Fixed required changes --- src/api/navigator/RoomSettingsErrorType.ts | 10 ---------- src/api/navigator/index.ts | 1 - .../NavigatorRoomSettingsBasicTabView.tsx | 11 ++++++----- 3 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 src/api/navigator/RoomSettingsErrorType.ts diff --git a/src/api/navigator/RoomSettingsErrorType.ts b/src/api/navigator/RoomSettingsErrorType.ts deleted file mode 100644 index 8fbe90f5..00000000 --- a/src/api/navigator/RoomSettingsErrorType.ts +++ /dev/null @@ -1,10 +0,0 @@ -export class RoomSettingsErrorType -{ - public static readonly PASSWORD_REQUIRED = 5; - public static readonly ROOM_NAME_MISSING = 7; - public static readonly ROOM_NAME_BADWORDS = 8; - public static readonly ROOM_DESCRIPTION_BADWORDS = 10; - public static readonly ROOM_TAGS_BADWWORDS = 11; - public static readonly RESTRICTED_TAGS = 12; - public static readonly TAGS_TOO_LONG = 13; -} diff --git a/src/api/navigator/index.ts b/src/api/navigator/index.ts index 08e40ccc..bceb33e4 100644 --- a/src/api/navigator/index.ts +++ b/src/api/navigator/index.ts @@ -7,7 +7,6 @@ export * from './IRoomModel'; export * from './IRoomModerationSettings'; export * from './NavigatorSearchResultViewDisplayMode'; export * from './RoomInfoData'; -export * from './RoomSettingsErrorType'; export * from './RoomSettingsUtils'; export * from './SearchFilterOptions'; export * from './TryVisitRoom'; diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx index 247d82de..ce0d6f83 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx @@ -1,7 +1,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { RoomDeleteComposer, RoomSettingsSaveErrorEvent } from '@nitrots/nitro-renderer'; +import { RoomDeleteComposer, RoomSettingsSaveErrorEvent, RoomSettingsSaveErrorParser } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; -import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, RoomSettingsErrorType, SendMessageComposer } from '../../../../api'; +import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, Text } from '../../../../common'; import { useMessageEvent, useNavigator, useNotification } from '../../../../hooks'; @@ -37,9 +37,10 @@ export const NavigatorRoomSettingsBasicTabView: FC