mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 18:32: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 { 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 { UserSettingsUIEvent } from '../../events/user-settings/UserSettingsUIEvent';
|
||||||
import { CreateMessageHook, dispatchMainEvent, SendMessageHook, useUiEvent } from '../../hooks';
|
import { CreateMessageHook, dispatchMainEvent, SendMessageHook, useUiEvent } from '../../hooks';
|
||||||
import { NitroCardContentView, NitroCardHeaderView } from '../../layout';
|
import { NitroCardContentView, NitroCardHeaderView } from '../../layout';
|
||||||
@ -8,15 +8,8 @@ import { LocalizeText } from '../../utils';
|
|||||||
|
|
||||||
export const UserSettingsView: FC<{}> = props =>
|
export const UserSettingsView: FC<{}> = props =>
|
||||||
{
|
{
|
||||||
const [isVisible, setIsVisible] = useState(false);
|
const [ isVisible, setIsVisible ] = useState(false);
|
||||||
const [useOldChat, setUseOldChat] = useState(false);
|
const [ userSettings, setUserSettings ] = useState<NitroSettingsEvent>(null);
|
||||||
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 onUserSettingsUIEvent = useCallback((event: UserSettingsUIEvent) =>
|
const onUserSettingsUIEvent = useCallback((event: UserSettingsUIEvent) =>
|
||||||
{
|
{
|
||||||
@ -38,66 +31,62 @@ export const UserSettingsView: FC<{}> = props =>
|
|||||||
useUiEvent(UserSettingsUIEvent.HIDE_USER_SETTINGS, onUserSettingsUIEvent);
|
useUiEvent(UserSettingsUIEvent.HIDE_USER_SETTINGS, onUserSettingsUIEvent);
|
||||||
useUiEvent(UserSettingsUIEvent.TOGGLE_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 onUserSettingsEvent = useCallback((event: UserSettingsEvent) =>
|
||||||
{
|
{
|
||||||
const parser = event.getParser();
|
const parser = event.getParser();
|
||||||
|
const settingsEvent = new NitroSettingsEvent();
|
||||||
|
|
||||||
setAllowRoomInvites(parser.roomInvites);
|
settingsEvent.volumeSystem = parser.volumeSystem;
|
||||||
setCameraFollowDisabled(parser.cameraFollow);
|
settingsEvent.volumeFurni = parser.volumeFurni;
|
||||||
setFurniVolume(parser.volumeFurni);
|
settingsEvent.volumeTrax = parser.volumeTrax;
|
||||||
setSystemVolume(parser.volumeSystem);
|
settingsEvent.oldChat = parser.oldChat;
|
||||||
setTraxVolume(parser.volumeTrax);
|
settingsEvent.roomInvites = parser.roomInvites;
|
||||||
setUseOldChat(parser.oldChat);
|
settingsEvent.cameraFollow = parser.cameraFollow;
|
||||||
setChatType(parser.chatType);
|
settingsEvent.flags = parser.flags;
|
||||||
setFlags(parser.flags);
|
settingsEvent.chatType = parser.chatType;
|
||||||
|
|
||||||
updateUserSettings();
|
setUserSettings(settingsEvent);
|
||||||
console.log(parser);
|
}, []);
|
||||||
}, [updateUserSettings]);
|
|
||||||
|
|
||||||
CreateMessageHook(UserSettingsEvent, onUserSettingsEvent);
|
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':
|
case 'close_view':
|
||||||
setIsVisible(false);
|
setIsVisible(false);
|
||||||
return;
|
return;
|
||||||
case 'oldchat':
|
case 'oldchat':
|
||||||
setUseOldChat(Boolean(value));
|
clone.oldChat = value;
|
||||||
SendMessageHook(new UserSettingsOldChatComposer(useOldChat));
|
SendMessageHook(new UserSettingsOldChatComposer(value));
|
||||||
updateUserSettings();
|
break;
|
||||||
return;
|
|
||||||
case 'room_invites':
|
case 'room_invites':
|
||||||
setAllowRoomInvites(Boolean(value));
|
clone.roomInvites = value;
|
||||||
SendMessageHook(new UserSettingsRoomInvitesComposer(allowRoomInvites));
|
SendMessageHook(new UserSettingsRoomInvitesComposer(value));
|
||||||
updateUserSettings();
|
break;
|
||||||
return;
|
|
||||||
case 'camera_follow':
|
case 'camera_follow':
|
||||||
setCameraFollowDisabled(value as boolean);
|
console.log(value);
|
||||||
SendMessageHook(new UserSettingsCameraFollowComposer(cameraFollowDisabled));
|
clone.cameraFollow = value;
|
||||||
updateUserSettings();
|
SendMessageHook(new UserSettingsCameraFollowComposer(value));
|
||||||
console.log(value as boolean);
|
break;
|
||||||
console.log(cameraFollowDisabled);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}, [allowRoomInvites, cameraFollowDisabled, updateUserSettings, useOldChat]);
|
|
||||||
|
if(doUpdate) setUserSettings(clone);
|
||||||
|
}, [ userSettings ]);
|
||||||
|
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
|
if(!userSettings) return;
|
||||||
|
|
||||||
|
console.log(userSettings);
|
||||||
|
|
||||||
|
dispatchMainEvent(userSettings);
|
||||||
|
}, [ userSettings ]);
|
||||||
|
|
||||||
if (!isVisible) return null;
|
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')} />
|
<NitroCardHeaderView headerText={LocalizeText('widget.memenu.settings.title')} onCloseClick={event => processAction('close_view')} />
|
||||||
<NitroCardContentView>
|
<NitroCardContentView>
|
||||||
<div className="form-check">
|
<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>
|
<label className="form-check-label">{LocalizeText('memenu.settings.chat.prefer.old.chat')}</label>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-check">
|
<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>
|
<label className="form-check-label">{LocalizeText('memenu.settings.other.ignore.room.invites')}</label>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-check">
|
<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>
|
<label className="form-check-label">{LocalizeText('memenu.settings.other.disable.room.camera.follow')}</label>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-3 mb-2">{LocalizeText('widget.memenu.settings.volume')}</div>
|
<div className="mt-3 mb-2">{LocalizeText('widget.memenu.settings.volume')}</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user