mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 10:22:36 +01:00
Fix dumb stuff
This commit is contained in:
parent
e85dd7cda8
commit
8f7410b0a1
@ -1,5 +1,5 @@
|
||||
import { NitroSettingsEvent, UserSettingsCameraFollowComposer, UserSettingsEvent, UserSettingsOldChatComposer, UserSettingsRoomInvitesComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { UserSettingsUIEvent } from '../../events/user-settings/UserSettingsUIEvent';
|
||||
import { CreateMessageHook, dispatchMainEvent, SendMessageHook, useUiEvent } from '../../hooks';
|
||||
import { NitroCardContentView, NitroCardHeaderView } from '../../layout';
|
||||
@ -8,15 +8,8 @@ import { LocalizeText } from '../../utils';
|
||||
|
||||
export const UserSettingsView: FC<{}> = props =>
|
||||
{
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const [useOldChat, setUseOldChat] = useState(false);
|
||||
const [allowRoomInvites, setAllowRoomInvites] = useState(false);
|
||||
const [cameraFollowDisabled, setCameraFollowDisabled] = useState(false);
|
||||
const [systemVolume, setSystemVolume] = useState(0);
|
||||
const [furniVolume, setFurniVolume] = useState(0);
|
||||
const [traxVolume, setTraxVolume] = useState(0);
|
||||
const [flags, setFlags] = useState(0);
|
||||
const [chatType, setChatType] = useState(0);
|
||||
const [ isVisible, setIsVisible ] = useState(false);
|
||||
const [ userSettings, setUserSettings ] = useState<NitroSettingsEvent>(null);
|
||||
|
||||
const onUserSettingsUIEvent = useCallback((event: UserSettingsUIEvent) =>
|
||||
{
|
||||
@ -38,66 +31,62 @@ export const UserSettingsView: FC<{}> = props =>
|
||||
useUiEvent(UserSettingsUIEvent.HIDE_USER_SETTINGS, onUserSettingsUIEvent);
|
||||
useUiEvent(UserSettingsUIEvent.TOGGLE_USER_SETTINGS, onUserSettingsUIEvent);
|
||||
|
||||
const updateUserSettings = useCallback(() =>
|
||||
{
|
||||
const event = new NitroSettingsEvent(NitroSettingsEvent.SETTINGS_UPDATED);
|
||||
event.flags = flags;
|
||||
event.oldChat = useOldChat;
|
||||
event.roomInvites = allowRoomInvites;
|
||||
event.volumeFurni = furniVolume;
|
||||
event.volumeSystem = systemVolume;
|
||||
event.volumeTrax = traxVolume;
|
||||
event.oldChat = useOldChat;
|
||||
event.chatType = chatType
|
||||
event.cameraFollow = cameraFollowDisabled;
|
||||
dispatchMainEvent(event);
|
||||
}, [allowRoomInvites, cameraFollowDisabled, chatType, flags, furniVolume, systemVolume, traxVolume, useOldChat]);
|
||||
|
||||
const onUserSettingsEvent = useCallback((event: UserSettingsEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
const settingsEvent = new NitroSettingsEvent();
|
||||
|
||||
setAllowRoomInvites(parser.roomInvites);
|
||||
setCameraFollowDisabled(parser.cameraFollow);
|
||||
setFurniVolume(parser.volumeFurni);
|
||||
setSystemVolume(parser.volumeSystem);
|
||||
setTraxVolume(parser.volumeTrax);
|
||||
setUseOldChat(parser.oldChat);
|
||||
setChatType(parser.chatType);
|
||||
setFlags(parser.flags);
|
||||
settingsEvent.volumeSystem = parser.volumeSystem;
|
||||
settingsEvent.volumeFurni = parser.volumeFurni;
|
||||
settingsEvent.volumeTrax = parser.volumeTrax;
|
||||
settingsEvent.oldChat = parser.oldChat;
|
||||
settingsEvent.roomInvites = parser.roomInvites;
|
||||
settingsEvent.cameraFollow = parser.cameraFollow;
|
||||
settingsEvent.flags = parser.flags;
|
||||
settingsEvent.chatType = parser.chatType;
|
||||
|
||||
updateUserSettings();
|
||||
console.log(parser);
|
||||
}, [updateUserSettings]);
|
||||
setUserSettings(settingsEvent);
|
||||
}, []);
|
||||
|
||||
CreateMessageHook(UserSettingsEvent, onUserSettingsEvent);
|
||||
|
||||
const processAction = useCallback((type: string, value?: string | number | boolean) =>
|
||||
const processAction = useCallback((type: string, value: boolean = false) =>
|
||||
{
|
||||
switch (type)
|
||||
let doUpdate = true;
|
||||
|
||||
const clone = userSettings.clone();
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 'close_view':
|
||||
setIsVisible(false);
|
||||
return;
|
||||
case 'oldchat':
|
||||
setUseOldChat(Boolean(value));
|
||||
SendMessageHook(new UserSettingsOldChatComposer(useOldChat));
|
||||
updateUserSettings();
|
||||
return;
|
||||
clone.oldChat = value;
|
||||
SendMessageHook(new UserSettingsOldChatComposer(value));
|
||||
break;
|
||||
case 'room_invites':
|
||||
setAllowRoomInvites(Boolean(value));
|
||||
SendMessageHook(new UserSettingsRoomInvitesComposer(allowRoomInvites));
|
||||
updateUserSettings();
|
||||
return;
|
||||
clone.roomInvites = value;
|
||||
SendMessageHook(new UserSettingsRoomInvitesComposer(value));
|
||||
break;
|
||||
case 'camera_follow':
|
||||
setCameraFollowDisabled(value as boolean);
|
||||
SendMessageHook(new UserSettingsCameraFollowComposer(cameraFollowDisabled));
|
||||
updateUserSettings();
|
||||
console.log(value as boolean);
|
||||
console.log(cameraFollowDisabled);
|
||||
return;
|
||||
console.log(value);
|
||||
clone.cameraFollow = value;
|
||||
SendMessageHook(new UserSettingsCameraFollowComposer(value));
|
||||
break;
|
||||
}
|
||||
}, [allowRoomInvites, cameraFollowDisabled, updateUserSettings, useOldChat]);
|
||||
|
||||
if(doUpdate) setUserSettings(clone);
|
||||
}, [ userSettings ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if(!userSettings) return;
|
||||
|
||||
console.log(userSettings);
|
||||
|
||||
dispatchMainEvent(userSettings);
|
||||
}, [ userSettings ]);
|
||||
|
||||
if (!isVisible) return null;
|
||||
|
||||
@ -107,15 +96,15 @@ export const UserSettingsView: FC<{}> = props =>
|
||||
<NitroCardHeaderView headerText={LocalizeText('widget.memenu.settings.title')} onCloseClick={event => processAction('close_view')} />
|
||||
<NitroCardContentView>
|
||||
<div className="form-check">
|
||||
<input className="form-check-input" type="checkbox" checked={useOldChat} onChange={event => processAction('oldchat', event.target.checked)} />
|
||||
<input className="form-check-input" type="checkbox" checked={ userSettings.oldChat } onChange={event => processAction('oldchat', event.target.checked)} />
|
||||
<label className="form-check-label">{LocalizeText('memenu.settings.chat.prefer.old.chat')}</label>
|
||||
</div>
|
||||
<div className="form-check">
|
||||
<input className="form-check-input" type="checkbox" checked={allowRoomInvites} onChange={event => processAction('room_invites', event.target.checked)} />
|
||||
<input className="form-check-input" type="checkbox" checked={ userSettings.roomInvites } onChange={event => processAction('room_invites', event.target.checked)} />
|
||||
<label className="form-check-label">{LocalizeText('memenu.settings.other.ignore.room.invites')}</label>
|
||||
</div>
|
||||
<div className="form-check">
|
||||
<input className="form-check-input" type="checkbox" checked={cameraFollowDisabled} onChange={event => processAction('camera_follow', event.target.checked)} />
|
||||
<input className="form-check-input" type="checkbox" checked={ userSettings.cameraFollow } onChange={event => processAction('camera_follow', event.target.checked)} />
|
||||
<label className="form-check-label">{LocalizeText('memenu.settings.other.disable.room.camera.follow')}</label>
|
||||
</div>
|
||||
<div className="mt-3 mb-2">{LocalizeText('widget.memenu.settings.volume')}</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user