Fix dumb room-tools timeout issue

This commit is contained in:
MyNameIsBatman 2022-02-13 19:42:56 -03:00
parent 77819a7e2b
commit a4c0492034

View File

@ -1,6 +1,6 @@
import { GetGuestRoomResultEvent, RoomLikeRoomComposer } from '@nitrots/nitro-renderer'; import { GetGuestRoomResultEvent, RoomLikeRoomComposer } from '@nitrots/nitro-renderer';
import classNames from 'classnames'; import classNames from 'classnames';
import { FC, useCallback, useState } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { LocalizeText, RoomWidgetZoomToggleMessage } from '../../../../api'; import { LocalizeText, RoomWidgetZoomToggleMessage } from '../../../../api';
import { NavigatorEvent } from '../../../../events'; import { NavigatorEvent } from '../../../../events';
import { ChatHistoryEvent } from '../../../../events/chat-history/ChatHistoryEvent'; import { ChatHistoryEvent } from '../../../../events/chat-history/ChatHistoryEvent';
@ -53,38 +53,32 @@ export const RoomToolsWidgetView: FC<{}> = props =>
{ {
const parser = event.getParser(); const parser = event.getParser();
let updated = false; if(roomName !== parser.data.roomName) setRoomName(parser.data.roomName);
if(roomName !== parser.data.roomName) if(roomOwner !== parser.data.ownerName) setRoomOwner(parser.data.ownerName);
if(roomTags !== parser.data.tags) setRoomTags(parser.data.tags);
}, [ roomName, roomOwner, roomTags ]);
useEffect(() =>
{
setRoomInfoOpacity(true);
setRoomInfoDisplay(true);
let timeoutDisplay = null;
const timeoutOpacity = setTimeout(() =>
{ {
updated = true; setRoomInfoOpacity(false);
setRoomName(parser.data.roomName);
}
if(roomOwner !== parser.data.ownerName) timeoutDisplay = setTimeout(() => setRoomInfoDisplay(false), 1000);
}, 3000);
return () =>
{ {
updated = true; clearTimeout(timeoutOpacity);
setRoomOwner(parser.data.ownerName); clearTimeout(timeoutDisplay);
} };
if(roomTags !== parser.data.tags)
{
updated = true;
setRoomTags(parser.data.tags);
}
if(updated)
{
setRoomInfoOpacity(true);
setRoomInfoDisplay(true);
setTimeout(() =>
{
setRoomInfoOpacity(false);
setTimeout(() => setRoomInfoDisplay(false), 1000);
}, 3000);
}
}, [ roomName, roomOwner, roomTags ]); }, [ roomName, roomOwner, roomTags ]);
CreateMessageHook(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); CreateMessageHook(GetGuestRoomResultEvent, onGetGuestRoomResultEvent);