From afc6bc44f8b9b92dfdb6478ce1f130e09cf6f8b5 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 27 Mar 2022 18:44:29 -0400 Subject: [PATCH] Navigator settings update --- src/api/navigator/IRoomChatSettings.ts | 8 + src/api/navigator/IRoomData.ts | 23 ++ src/api/navigator/IRoomModerationSettings.ts | 6 + src/api/navigator/index.ts | 3 + .../navigator/views/NavigatorRoomInfoView.tsx | 6 +- .../NavigatorRoomSettingsAccessTabView.tsx | 57 ++- .../NavigatorRoomSettingsBasicTabView.tsx | 60 ++- .../NavigatorRoomSettingsModTabView.tsx | 98 ++++- .../NavigatorRoomSettingsRightsTabView.tsx | 105 +++-- .../NavigatorRoomSettingsView.tsx | 385 +++++++----------- .../NavigatorRoomSettingsVipChatTabView.tsx | 69 ++-- .../search/NavigatorSearchResultItemView.tsx | 2 +- 12 files changed, 455 insertions(+), 367 deletions(-) create mode 100644 src/api/navigator/IRoomChatSettings.ts create mode 100644 src/api/navigator/IRoomData.ts create mode 100644 src/api/navigator/IRoomModerationSettings.ts diff --git a/src/api/navigator/IRoomChatSettings.ts b/src/api/navigator/IRoomChatSettings.ts new file mode 100644 index 00000000..aee426cb --- /dev/null +++ b/src/api/navigator/IRoomChatSettings.ts @@ -0,0 +1,8 @@ +export interface IRoomChatSettings +{ + mode: number; + weight: number; + speed: number; + distance: number; + protection: number; +} diff --git a/src/api/navigator/IRoomData.ts b/src/api/navigator/IRoomData.ts new file mode 100644 index 00000000..91463147 --- /dev/null +++ b/src/api/navigator/IRoomData.ts @@ -0,0 +1,23 @@ +import { IRoomChatSettings } from './IRoomChatSettings'; +import { IRoomModerationSettings } from './IRoomModerationSettings'; + +export interface IRoomData +{ + roomId: number; + roomName: string; + roomDescription: string; + categoryId: number; + userCount: number; + tags: string[]; + tradeState: number; + allowWalkthrough: boolean; + lockState: number; + password: string; + allowPets: boolean; + allowPetsEat: boolean; + hideWalls: boolean; + wallThickness: number; + floorThickness: number; + chatSettings: IRoomChatSettings; + moderationSettings: IRoomModerationSettings; +} diff --git a/src/api/navigator/IRoomModerationSettings.ts b/src/api/navigator/IRoomModerationSettings.ts new file mode 100644 index 00000000..266fe478 --- /dev/null +++ b/src/api/navigator/IRoomModerationSettings.ts @@ -0,0 +1,6 @@ +export interface IRoomModerationSettings +{ + allowMute: number; + allowKick: number; + allowBan: number; +} diff --git a/src/api/navigator/index.ts b/src/api/navigator/index.ts index f913250d..ade27895 100644 --- a/src/api/navigator/index.ts +++ b/src/api/navigator/index.ts @@ -1,6 +1,9 @@ export * from './DoorStateType'; export * from './INavigatorData'; export * from './INavigatorSearchFilter'; +export * from './IRoomChatSettings'; +export * from './IRoomData'; +export * from './IRoomModerationSettings'; export * from './NavigatorSearchResultViewDisplayMode'; export * from './RoomInfoData'; export * from './RoomModels'; diff --git a/src/components/navigator/views/NavigatorRoomInfoView.tsx b/src/components/navigator/views/NavigatorRoomInfoView.tsx index b488551d..02e9b9f2 100644 --- a/src/components/navigator/views/NavigatorRoomInfoView.tsx +++ b/src/components/navigator/views/NavigatorRoomInfoView.tsx @@ -16,11 +16,9 @@ export class NavigatorRoomInfoViewProps export const NavigatorRoomInfoView: FC = props => { const { onCloseClick = null } = props; - const [ roomThumbnail, setRoomThumbnail ] = useState(null); const [ isRoomPicked, setIsRoomPicked ] = useState(false); const [ isRoomMuted, setIsRoomMuted ] = useState(false); const { navigatorData = null } = useNavigatorContext(); - const isMod = GetSessionDataManager().isModerator; const hasPermission = (permission: string) => @@ -28,7 +26,7 @@ export const NavigatorRoomInfoView: FC = props => switch(permission) { case 'settings': - return (GetSessionDataManager().userId === navigatorData.enteredGuestRoom.ownerId || isMod ); + return (GetSessionDataManager().userId === navigatorData.enteredGuestRoom.ownerId || GetSessionDataManager().isModerator); case 'staff_pick': return GetSessionDataManager().securityLevel >= SecurityLevel.COMMUNITY; default: return false; @@ -49,7 +47,7 @@ export const NavigatorRoomInfoView: FC = props => newRoomId = navigatorData.enteredGuestRoom.roomId; } - SendMessageComposer(new UserHomeRoomComposer(newRoomId)); + if(newRoomId > 0) SendMessageComposer(new UserHomeRoomComposer(newRoomId)); return; case 'navigator_search_tag': return; diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsAccessTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsAccessTabView.tsx index 58c47afb..657caead 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsAccessTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsAccessTabView.tsx @@ -1,27 +1,38 @@ import { RoomDataParser } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { LocalizeText, RoomSettingsData } from '../../../../api'; +import { FC, useEffect, useState } from 'react'; +import { IRoomData, LocalizeText } from '../../../../api'; import { Column, Flex, Text } from '../../../../common'; +import { BatchUpdates } from '../../../../hooks'; interface NavigatorRoomSettingsTabViewProps { - roomSettingsData: RoomSettingsData; + roomData: IRoomData; handleChange: (field: string, value: string | number | boolean) => void; } export const NavigatorRoomSettingsAccessTabView: FC = props => { - const { roomSettingsData = null, handleChange = null } = props; + const { roomData = null, handleChange = null } = props; + const [ password, setPassword ] = useState(''); + const [ confirmPassword, setConfirmPassword ] = useState(''); + const [ isTryingPassword, setIsTryingPassword ] = useState(false); - const isPasswordValid = useCallback(() => + const saveRoomPassword = () => { - return (roomSettingsData.password && (roomSettingsData.password.length > 0) && (roomSettingsData.password === roomSettingsData.confirmPassword)); - }, [ roomSettingsData ]); + if(!isTryingPassword || ((password.length <= 0) || (confirmPassword.length <= 0) || (password !== confirmPassword))) return; - const trySave = useCallback(() => + handleChange('password', password); + } + + useEffect(() => { - if(isPasswordValid()) handleChange('save', null); - }, [ isPasswordValid, handleChange ]); + BatchUpdates(() => + { + setPassword(''); + setConfirmPassword(''); + setIsTryingPassword(false); + }); + }, [ roomData ]); return ( <> @@ -33,27 +44,31 @@ export const NavigatorRoomSettingsAccessTabView: FC { LocalizeText('navigator.roomsettings.doormode') } - handleChange('lock_state', RoomDataParser.OPEN_STATE) } /> + handleChange('lock_state', RoomDataParser.OPEN_STATE) } /> { LocalizeText('navigator.roomsettings.doormode.open') } - handleChange('lock_state', RoomDataParser.DOORBELL_STATE) } /> + handleChange('lock_state', RoomDataParser.DOORBELL_STATE) } /> { LocalizeText('navigator.roomsettings.doormode.doorbell') } - handleChange('lock_state', RoomDataParser.INVISIBLE_STATE) } /> + handleChange('lock_state', RoomDataParser.INVISIBLE_STATE) } /> { LocalizeText('navigator.roomsettings.doormode.invisible') } - handleChange('lock_state', RoomDataParser.PASSWORD_STATE) } /> - { (roomSettingsData.lockState !== RoomDataParser.PASSWORD_STATE) && + setIsTryingPassword(event.target.checked) } /> + { !isTryingPassword && (roomData.lockState !== RoomDataParser.PASSWORD_STATE) && { LocalizeText('navigator.roomsettings.doormode.password') } } - { (roomSettingsData.lockState === RoomDataParser.PASSWORD_STATE) && + { (isTryingPassword || (roomData.lockState === RoomDataParser.PASSWORD_STATE)) && { LocalizeText('navigator.roomsettings.doormode.password') } - handleChange('password', e.target.value) } onBlur={ trySave } placeholder={ LocalizeText('navigator.roomsettings.password') } /> - handleChange('confirm_password', e.target.value) } onBlur={ trySave } placeholder={ LocalizeText('navigator.roomsettings.passwordconfirm') } /> - { !isPasswordValid() && + setPassword(event.target.value) } placeholder={ LocalizeText('navigator.roomsettings.password') } onFocus={ event => setIsTryingPassword(true) } /> + { isTryingPassword && (password.length <= 0) && + + { LocalizeText('navigator.roomsettings.passwordismandatory') } + } + setConfirmPassword(event.target.value) } onBlur={ saveRoomPassword } placeholder={ LocalizeText('navigator.roomsettings.passwordconfirm') } /> + { isTryingPassword && ((password.length > 0) && (password !== confirmPassword)) && { LocalizeText('navigator.roomsettings.invalidconfirm') } } @@ -63,11 +78,11 @@ export const NavigatorRoomSettingsAccessTabView: FC { LocalizeText('navigator.roomsettings.pets') } - handleChange('allow_pets', event.target.checked) } /> + handleChange('allow_pets', event.target.checked) } /> { LocalizeText('navigator.roomsettings.allowpets') } - handleChange('allow_pets_eat', event.target.checked) } /> + handleChange('allow_pets_eat', event.target.checked) } /> { LocalizeText('navigator.roomsettings.allowfoodconsume') } diff --git a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx index f7bac91e..30cb8c23 100644 --- a/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx +++ b/src/components/navigator/views/room-settings/NavigatorRoomSettingsBasicTabView.tsx @@ -1,15 +1,18 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { RoomDeleteComposer } from '@nitrots/nitro-renderer'; -import { FC } from 'react'; -import { CreateLinkEvent, GetMaxVisitorsList, LocalizeText, NotificationUtilities, RoomSettingsData, SendMessageComposer } from '../../../../api'; -import { Base, Flex, Text } from '../../../../common'; +import { FC, useEffect, useState } from 'react'; +import { CreateLinkEvent, GetMaxVisitorsList, IRoomData, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../api'; +import { Base, Column, Flex, Text } from '../../../../common'; +import { BatchUpdates } from '../../../../hooks'; import { useNavigatorContext } from '../../NavigatorContext'; +const ROOM_NAME_MIN_LENGTH = 3; +const ROOM_NAME_MAX_LENGTH = 60; const DESC_MAX_LENGTH = 255; interface NavigatorRoomSettingsTabViewProps { - roomSettingsData: RoomSettingsData; + roomData: IRoomData; handleChange: (field: string, value: string | number | boolean) => void; close: () => void; } @@ -17,14 +20,16 @@ interface NavigatorRoomSettingsTabViewProps export const NavigatorRoomSettingsBasicTabView: FC = props => { - const { roomSettingsData = null, handleChange = null, close = null } = props; + const { roomData = null, handleChange = null, close = null } = props; + const [ roomName, setRoomName ] = useState(''); + const [ roomDescription, setRoomDescription ] = useState(''); const { categories = null } = useNavigatorContext(); const deleteRoom = () => { - NotificationUtilities.confirm(LocalizeText('navigator.roomsettings.deleteroom.confirm.message', [ 'room_name' ], [ roomSettingsData.roomName ] ), () => + NotificationUtilities.confirm(LocalizeText('navigator.roomsettings.deleteroom.confirm.message', [ 'room_name' ], [ roomData.roomName ] ), () => { - SendMessageComposer(new RoomDeleteComposer(roomSettingsData.roomId)); + SendMessageComposer(new RoomDeleteComposer(roomData.roomId)); if(close) close(); @@ -33,31 +38,60 @@ export const NavigatorRoomSettingsBasicTabView: FC + { + if((roomName === roomData.roomName) || (roomName.length < ROOM_NAME_MIN_LENGTH) || (roomName.length > ROOM_NAME_MAX_LENGTH)) return; + + handleChange('name', roomName); + } + + const saveRoomDescription = () => + { + if((roomDescription === roomData.roomDescription) || (roomDescription.length > DESC_MAX_LENGTH)) return; + + handleChange('description', roomDescription); + } + + useEffect(() => + { + BatchUpdates(() => + { + setRoomName(roomData.roomName); + setRoomDescription(roomData.roomDescription); + }); + }, [ roomData ]); + return ( <> { LocalizeText('navigator.roomname') } - handleChange('name', event.target.value) } onBlur={ event => handleChange('save', null) } /> + + setRoomName(event.target.value) } onBlur={ saveRoomName } /> + { (roomName.length < ROOM_NAME_MIN_LENGTH) && + + { LocalizeText('navigator.roomsettings.roomnameismandatory') } + } + { LocalizeText('navigator.roomsettings.desc') } -