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);
{
updated = true;
setRoomName(parser.data.roomName);
}
if(roomOwner !== parser.data.ownerName) if(roomTags !== parser.data.tags) setRoomTags(parser.data.tags);
{ }, [ roomName, roomOwner, roomTags ]);
updated = true;
setRoomOwner(parser.data.ownerName);
}
if(roomTags !== parser.data.tags) useEffect(() =>
{ {
updated = true; setRoomInfoOpacity(true);
setRoomTags(parser.data.tags); setRoomInfoDisplay(true);
}
if(updated) let timeoutDisplay = null;
const timeoutOpacity = setTimeout(() =>
{ {
setRoomInfoOpacity(true); setRoomInfoOpacity(false);
setRoomInfoDisplay(true);
setTimeout(() => timeoutDisplay = setTimeout(() => setRoomInfoDisplay(false), 1000);
{ }, 3000);
setRoomInfoOpacity(false);
return () =>
setTimeout(() => setRoomInfoDisplay(false), 1000); {
}, 3000); clearTimeout(timeoutOpacity);
} clearTimeout(timeoutDisplay);
};
}, [ roomName, roomOwner, roomTags ]); }, [ roomName, roomOwner, roomTags ]);
CreateMessageHook(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); CreateMessageHook(GetGuestRoomResultEvent, onGetGuestRoomResultEvent);