Fix chat style code

This commit is contained in:
Bill 2022-07-19 12:08:39 -04:00
parent 33dd28f089
commit d397a2944e
3 changed files with 40 additions and 40 deletions

View File

@ -3,14 +3,13 @@ import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { ChatMessageTypeEnum, GetClubMemberLevel, GetConfiguration, GetRoomSession, GetSessionDataManager, LocalizeText, RoomWidgetUpdateChatInputContentEvent } from '../../../../api';
import { Text } from '../../../../common';
import { useChatInputWidget, useUiEvent } from '../../../../hooks';
import { useChatInputWidget, useSessionInfo, useUiEvent } from '../../../../hooks';
import { ChatInputStyleSelectorView } from './ChatInputStyleSelectorView';
export const ChatInputView: FC<{}> = props =>
{
const [ chatValue, setChatValue ] = useState<string>('');
const [ chatStyleId, setChatStyleId ] = useState(GetSessionDataManager().chatStyle);
const [ needsChatStyleUpdate, setNeedsChatStyleUpdate ] = useState(false);
const { chatStyleId = 0, updateChatStyleId = null } = useSessionInfo();
const { selectedUsername = '', floodBlocked = false, floodBlockedSeconds = 0, setIsTyping = null, setIsIdle = null, sendChat = null } = useChatInputWidget();
const inputRef = useRef<HTMLInputElement>();
@ -90,19 +89,12 @@ export const ChatInputView: FC<{}> = props =>
if(text.length <= maxChatLength)
{
if(needsChatStyleUpdate)
{
GetSessionDataManager().sendChatStyleUpdate(chatStyleId);
setNeedsChatStyleUpdate(false);
}
setChatValue('');
sendChat(text, chatType, recipientName, chatStyleId);
}
setChatValue(append);
}, [ chatModeIdWhisper, chatModeIdShout, chatModeIdSpeak, maxChatLength, chatStyleId, needsChatStyleUpdate, setIsTyping, setIsIdle, sendChat ]);
}, [ chatModeIdWhisper, chatModeIdShout, chatModeIdSpeak, maxChatLength, chatStyleId, setIsTyping, setIsIdle, sendChat ]);
const updateChatInput = useCallback((value: string) =>
{
@ -165,12 +157,6 @@ export const ChatInputView: FC<{}> = props =>
}
});
const selectChatStyleId = useCallback((styleId: number) =>
{
setChatStyleId(styleId);
setNeedsChatStyleUpdate(true);
}, []);
const chatStyleIds = useMemo(() =>
{
let styleIds: number[] = [];
@ -248,7 +234,7 @@ export const ChatInputView: FC<{}> = props =>
{ floodBlocked &&
<Text variant="danger">{ LocalizeText('chat.input.alert.flood', [ 'time' ], [ floodBlockedSeconds.toString() ]) } </Text> }
</div>
<ChatInputStyleSelectorView chatStyleId={ chatStyleId } chatStyleIds={ chatStyleIds } selectChatStyleId={ selectChatStyleId } />
<ChatInputStyleSelectorView chatStyleId={ chatStyleId } chatStyleIds={ chatStyleIds } selectChatStyleId={ updateChatStyleId } />
</div>, document.getElementById('toolbar-chat-input-container'))
);
}

View File

@ -12,26 +12,6 @@ export const UserSettingsView: FC<{}> = props =>
const [ catalogPlaceMultipleObjects, setCatalogPlaceMultipleObjects ] = useCatalogPlaceMultipleItems();
const [ catalogSkipPurchaseConfirmation, setCatalogSkipPurchaseConfirmation ] = useCatalogSkipPurchaseConfirmation();
const onUserSettingsEvent = useCallback((event: UserSettingsEvent) =>
{
const parser = event.getParser();
const settingsEvent = new NitroSettingsEvent();
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;
setUserSettings(settingsEvent);
DispatchMainEvent(settingsEvent);
}, []);
useMessageEvent(UserSettingsEvent, onUserSettingsEvent);
const processAction = useCallback((type: string, value?: boolean | number | string) =>
{
let doUpdate = true;
@ -88,6 +68,24 @@ export const UserSettingsView: FC<{}> = props =>
}
}, [ userSettings ]);
useMessageEvent<UserSettingsEvent>(UserSettingsEvent, event =>
{
const parser = event.getParser();
const settingsEvent = new NitroSettingsEvent();
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;
setUserSettings(settingsEvent);
DispatchMainEvent(settingsEvent);
});
useEffect(() =>
{
const linkTracker: ILinkEventTracker = {

View File

@ -1,12 +1,21 @@
import { FigureUpdateEvent, UserInfoDataParser, UserInfoEvent } from '@nitrots/nitro-renderer';
import { FigureUpdateEvent, RoomUnitChatStyleComposer, UserInfoDataParser, UserInfoEvent, UserSettingsEvent } from '@nitrots/nitro-renderer';
import { useState } from 'react';
import { useBetween } from 'use-between';
import { SendMessageComposer } from '../../api';
import { useMessageEvent } from '../events';
const useSessionInfoState = () =>
{
const [ userInfo, setUserInfo ] = useState<UserInfoDataParser>(null);
const [ userFigure, setUserFigure ] = useState<string>(null);
const [ chatStyleId, setChatStyleId ] = useState<number>(0);
const updateChatStyleId = (styleId: number) =>
{
setChatStyleId(styleId);
SendMessageComposer(new RoomUnitChatStyleComposer(styleId));
}
useMessageEvent<UserInfoEvent>(UserInfoEvent, event =>
{
@ -23,7 +32,14 @@ const useSessionInfoState = () =>
setUserFigure(parser.figure);
});
return { userInfo, userFigure };
useMessageEvent<UserSettingsEvent>(UserSettingsEvent, event =>
{
const parser = event.getParser();
setChatStyleId(parser.chatType);
});
return { userInfo, userFigure, chatStyleId, updateChatStyleId };
}
export const useSessionInfo = () => useBetween(useSessionInfoState);