Room settings update

This commit is contained in:
Bill 2021-07-29 01:37:41 -04:00
parent 63cf84d872
commit 2961ef64ce
5 changed files with 92 additions and 112 deletions

View File

@ -1,3 +1,5 @@
import { RoomSettingsParser } from 'nitro-renderer';
export default class RoomSettingsData export default class RoomSettingsData
{ {
public roomId: number; public roomId: number;
@ -35,40 +37,42 @@ export default class RoomSettingsData
public bannedUsers: Map<number, string>; public bannedUsers: Map<number, string>;
public selectedUserToUnban: number; public selectedUserToUnban: number;
constructor() constructor(parser: RoomSettingsParser)
{ {
this.roomId = 0; if(!parser) throw new Error('invalid_parser');
this.roomName = null;
this.roomOriginalName = null;
this.roomDescription = null;
this.categoryId = 0;
this.userCount = 0;
this.tags = [];
this.tradeState = 0;
this.allowWalkthrough = false;
this.lockState = 0; this.roomId = parser.roomId;
this.originalLockState = 0; this.roomName = parser.name;
this.roomOriginalName = parser.name;
this.roomDescription = parser.description;
this.categoryId = parser.categoryId;
this.userCount = parser.userCount;
this.tags = parser.tags;
this.tradeState = parser.tradeMode;
this.allowWalkthrough = parser.allowWalkthrough;
this.lockState = parser.state;
this.originalLockState = parser.state;
this.password = null; this.password = null;
this.confirmPassword = null; this.confirmPassword = null;
this.allowPets = false; this.allowPets = parser.allowPets;
this.allowPetsEat = false; this.allowPetsEat = parser.allowPetsEat;
this.usersWithRights = new Map<number, string>(); this.usersWithRights = new Map<number, string>();
this.friendsWithoutRights = new Map<number, string>(); this.friendsWithoutRights = new Map<number, string>();
this.hideWalls = false; this.hideWalls = parser.hideWalls;
this.wallThickness = 0; this.wallThickness = parser.thicknessWall;
this.floorThickness = 0; this.floorThickness = parser.thicknessFloor;
this.chatBubbleMode = 0; this.chatBubbleMode = parser.chatSettings.mode;
this.chatBubbleWeight = 0; this.chatBubbleWeight = parser.chatSettings.weight;
this.chatBubbleSpeed = 0; this.chatBubbleSpeed = parser.chatSettings.speed;
this.chatFloodProtection = 0; this.chatFloodProtection = parser.chatSettings.protection;
this.chatDistance = 0; this.chatDistance = parser.chatSettings.distance;
this.muteState = 0; this.muteState = parser.moderationSettings.allowMute;
this.kickState = 0; this.kickState = parser.moderationSettings.allowKick;
this.banState = 0; this.banState = parser.moderationSettings.allowBan;
this.bannedUsers = new Map<number, string>(); this.bannedUsers = new Map<number, string>();
this.selectedUserToUnban = 0; this.selectedUserToUnban = 0;
} }

View File

@ -0,0 +1,11 @@
export function GetMaxVisitorsList(): number[]
{
const list: number[] = [];
for(let i = 10; i <= 100; i = i + 10)
{
list.push(i);
}
return list;
}

View File

@ -1,3 +1,7 @@
.nitro-room-settings { .nitro-room-settings {
width: 400px; width: 400px;
.content-area {
height: 350px;
}
} }

View File

@ -30,70 +30,42 @@ export const NavigatorRoomSettingsView: FC<{}> = props =>
{ {
const parser = event.getParser(); const parser = event.getParser();
const roomSettingsData = new RoomSettingsData(); if(!parser) return;
roomSettingsData.roomId = parser.roomId; setRoomSettingsData(new RoomSettingsData(parser));
roomSettingsData.roomName = parser.name;
roomSettingsData.roomOriginalName = parser.name;
roomSettingsData.roomDescription = parser.description;
roomSettingsData.categoryId = parser.categoryId;
roomSettingsData.userCount = parser.userCount;
roomSettingsData.tradeState = parser.tradeMode;
roomSettingsData.allowWalkthrough = parser.allowWalkthrough;
roomSettingsData.lockState = parser.state;
roomSettingsData.originalLockState = parser.state;
roomSettingsData.allowPets = parser.allowPets;
roomSettingsData.hideWalls = parser.hideWalls;
roomSettingsData.wallThickness = parser.thicknessWall;
roomSettingsData.floorThickness = parser.thicknessFloor;
roomSettingsData.chatBubbleMode = parser.chatSettings.mode;
roomSettingsData.chatBubbleWeight = parser.chatSettings.weight;
roomSettingsData.chatBubbleSpeed = parser.chatSettings.speed;
roomSettingsData.chatFloodProtection = parser.chatSettings.protection;
roomSettingsData.chatDistance = parser.chatSettings.distance;
roomSettingsData.muteState = parser.moderationSettings.allowMute;
roomSettingsData.kickState = parser.moderationSettings.allowKick;
roomSettingsData.banState = parser.moderationSettings.allowBan;
setRoomSettingsData(roomSettingsData);
}, []); }, []);
CreateMessageHook(RoomSettingsEvent, onRoomSettingsEvent); CreateMessageHook(RoomSettingsEvent, onRoomSettingsEvent);
const save = useCallback(() => const save = useCallback(() =>
{ {
console.log('save', roomSettingsData) SendMessageHook(
const composer = new SaveRoomSettingsComposer( new SaveRoomSettingsComposer(
roomSettingsData.roomId, roomSettingsData.roomId,
roomSettingsData.roomName, roomSettingsData.roomName,
roomSettingsData.roomDescription, roomSettingsData.roomDescription,
roomSettingsData.lockState, roomSettingsData.lockState,
roomSettingsData.password, roomSettingsData.password,
roomSettingsData.userCount, roomSettingsData.userCount,
roomSettingsData.categoryId, roomSettingsData.categoryId,
roomSettingsData.tags.length, roomSettingsData.tags.length,
roomSettingsData.tags, roomSettingsData.tags,
roomSettingsData.tradeState, roomSettingsData.tradeState,
roomSettingsData.allowPets, roomSettingsData.allowPets,
roomSettingsData.allowPetsEat, roomSettingsData.allowPetsEat,
roomSettingsData.allowWalkthrough, roomSettingsData.allowWalkthrough,
roomSettingsData.hideWalls, roomSettingsData.hideWalls,
roomSettingsData.wallThickness, roomSettingsData.wallThickness,
roomSettingsData.floorThickness, roomSettingsData.floorThickness,
roomSettingsData.muteState, roomSettingsData.muteState,
roomSettingsData.kickState, roomSettingsData.kickState,
roomSettingsData.banState, roomSettingsData.banState,
roomSettingsData.chatBubbleMode, roomSettingsData.chatBubbleMode,
roomSettingsData.chatBubbleWeight, roomSettingsData.chatBubbleWeight,
roomSettingsData.chatBubbleSpeed, roomSettingsData.chatBubbleSpeed,
roomSettingsData.chatDistance, roomSettingsData.chatDistance,
roomSettingsData.chatFloodProtection roomSettingsData.chatFloodProtection
); ));
SendMessageHook(composer);
}, [ roomSettingsData ]); }, [ roomSettingsData ]);
const processAction = useCallback((action: string) => const processAction = useCallback((action: string) =>

View File

@ -1,36 +1,20 @@
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useState } from 'react';
import { LocalizeText } from '../../../../../../utils/LocalizeText'; import { LocalizeText } from '../../../../../../utils/LocalizeText';
import RoomSettingsData from '../../../../common/RoomSettingsData'; import { GetMaxVisitorsList } from '../../../../common/RoomSettingsUtils';
import { useNavigatorContext } from '../../../../context/NavigatorContext'; import { useNavigatorContext } from '../../../../context/NavigatorContext';
import { NavigatorRoomSettingsTabViewProps } from '../../NavigatorRoomSettingsView.types'; import { NavigatorRoomSettingsTabViewProps } from '../../NavigatorRoomSettingsView.types';
export const NavigatorRoomSettingsBasicTabView: FC<NavigatorRoomSettingsTabViewProps> = props => export const NavigatorRoomSettingsBasicTabView: FC<NavigatorRoomSettingsTabViewProps> = props =>
{ {
const { roomSettingsData = null, setRoomSettingsData = null, onSave = null } = props; const { roomSettingsData = null, setRoomSettingsData = null, onSave = null } = props;
const [ maxVisitorsList, setMaxVisitorsList ] = useState(GetMaxVisitorsList());
const { navigatorState = null } = useNavigatorContext(); const { navigatorState = null } = useNavigatorContext();
const { categories = null } = navigatorState; const { categories = null } = navigatorState;
const [ maxVisitorsList, setMaxVisitorsList ] = useState(null);
useEffect(() =>
{
if(!maxVisitorsList)
{
const list = [];
for(let i = 10; i <= 100; i = i + 10)
{
list.push(i);
}
setMaxVisitorsList(list);
}
}, [ maxVisitorsList ]);
const handleChange = useCallback((field: string, value: string | number | boolean) => const handleChange = useCallback((field: string, value: string | number | boolean) =>
{ {
const roomSettings = ({...roomSettingsData} as RoomSettingsData); const roomSettings = Object.assign({}, roomSettingsData);
let save = true; let save = true;
switch(field) switch(field)
@ -66,15 +50,15 @@ export const NavigatorRoomSettingsBasicTabView: FC<NavigatorRoomSettingsTabViewP
<> <>
<div className="form-group mb-1"> <div className="form-group mb-1">
<label>{ LocalizeText('navigator.roomname') }</label> <label>{ LocalizeText('navigator.roomname') }</label>
<input className="form-control form-control-sm" value={ roomSettingsData.roomName } onChange={ e => handleChange('name', e.target.value) } onBlur={ onSave } /> <input className="form-control form-control-sm" value={ roomSettingsData.roomName } onChange={ event => handleChange('name', event.target.value) } onBlur={ onSave } />
</div> </div>
<div className="form-group mb-1"> <div className="form-group mb-1">
<label>{ LocalizeText('navigator.roomsettings.desc') }</label> <label>{ LocalizeText('navigator.roomsettings.desc') }</label>
<input className="form-control form-control-sm" value={ roomSettingsData.roomDescription } onChange={ e => handleChange('description', e.target.value) } onBlur={ () => onSave() } /> <input className="form-control form-control-sm" value={ roomSettingsData.roomDescription } onChange={ event => handleChange('description', event.target.value) } onBlur={ onSave } />
</div> </div>
<div className="form-group mb-1"> <div className="form-group mb-1">
<label>{ LocalizeText('navigator.category') }</label> <label>{ LocalizeText('navigator.category') }</label>
<select className="form-select form-select-sm" value={ roomSettingsData.categoryId } onChange={ (e) => handleChange('category', e.target.value) }> <select className="form-select form-select-sm" value={ roomSettingsData.categoryId } onChange={ event => handleChange('category', event.target.value) }>
{ categories && categories.map(category => { categories && categories.map(category =>
{ {
return <option key={ category.id } value={ category.id }>{ LocalizeText(category.name) }</option> return <option key={ category.id } value={ category.id }>{ LocalizeText(category.name) }</option>
@ -83,7 +67,7 @@ export const NavigatorRoomSettingsBasicTabView: FC<NavigatorRoomSettingsTabViewP
</div> </div>
<div className="form-group mb-1"> <div className="form-group mb-1">
<label>{ LocalizeText('navigator.maxvisitors') }</label> <label>{ LocalizeText('navigator.maxvisitors') }</label>
<select className="form-select form-select-sm" value={ roomSettingsData.userCount } onChange={ (e) => handleChange('max_visitors', e.target.value) }> <select className="form-select form-select-sm" value={ roomSettingsData.userCount } onChange={ event => handleChange('max_visitors', event.target.value) }>
{ maxVisitorsList && maxVisitorsList.map(value => { maxVisitorsList && maxVisitorsList.map(value =>
{ {
return <option key={ value } value={ value }>{ value }</option> return <option key={ value } value={ value }>{ value }</option>
@ -92,16 +76,21 @@ export const NavigatorRoomSettingsBasicTabView: FC<NavigatorRoomSettingsTabViewP
</div> </div>
<div className="form-group mb-1"> <div className="form-group mb-1">
<label>{ LocalizeText('navigator.tradesettings') }</label> <label>{ LocalizeText('navigator.tradesettings') }</label>
<select className="form-select form-select-sm" value={ roomSettingsData.tradeState } onChange={ (e) => handleChange('trade_state', e.target.value) }> <select className="form-select form-select-sm" value={ roomSettingsData.tradeState } onChange={ event => handleChange('trade_state', event.target.value) }>
<option value="0">{ LocalizeText('${navigator.roomsettings.trade_not_allowed}') }</option> <option value="0">{ LocalizeText('navigator.roomsettings.trade_not_allowed') }</option>
<option value="1">{ LocalizeText('${navigator.roomsettings.trade_not_with_Controller}') }</option> <option value="1">{ LocalizeText('navigator.roomsettings.trade_not_with_Controller') }</option>
<option value="2">{ LocalizeText('${navigator.roomsettings.trade_allowed}') }</option> <option value="2">{ LocalizeText('navigator.roomsettings.trade_allowed') }</option>
</select> </select>
</div> </div>
<div className="form-check"> <div className="form-check">
<input className="form-check-input" type="checkbox" checked={ roomSettingsData.allowWalkthrough } onChange={ (e) => handleChange('allow_walkthrough', e.target.checked) } /> <input className="form-check-input" type="checkbox" checked={ roomSettingsData.allowWalkthrough } onChange={ event => handleChange('allow_walkthrough', event.target.checked) } />
<label className="form-check-label">{ LocalizeText('navigator.roomsettings.allow_walk_through') }</label> <label className="form-check-label">{ LocalizeText('navigator.roomsettings.allow_walk_through') }</label>
</div> </div>
<div className="form-group d-flex justify-content-center mt-1">
<button type="button" className="btn btn-link btn-sm text-danger fw-bold">
<i className="fas fa-times me-1" />
{ LocalizeText('navigator.roomsettings.delete') }</button>
</div>
</> </>
); );
}; };