More chat updates

This commit is contained in:
Bill 2021-06-30 23:00:39 -04:00
parent 3ac7184758
commit 24b5ba658c

View File

@ -15,22 +15,13 @@ export const ChatWidgetView: FC<ChatWidgetViewProps> = props =>
const { roomSession = null } = useRoomContext();
const elementRef = useRef<HTMLDivElement>();
const removeFirstHiddenChat = useCallback(() =>
const removeHiddenChats = useCallback(() =>
{
if(!chatMessages.length) return;
const lastChat = chatMessages[0];
const newMessages = chatMessages.filter(chat => ((chat.top > (-(chat.height) * 2))));
if((lastChat.top > (-(lastChat.height) * 2))) return;
setChatMessages(prevValue =>
{
const newMessages = [ ...prevValue ];
newMessages.shift();
return newMessages;
});
if(newMessages.length !== chatMessages.length) setChatMessages(newMessages);
}, [ chatMessages ]);
const moveChatUp = useCallback((chat: ChatBubbleMessage, amount: number) =>
@ -42,8 +33,8 @@ export const ChatWidgetView: FC<ChatWidgetViewProps> = props =>
{
chatMessages.forEach(chat => moveChatUp(chat, amount));
removeFirstHiddenChat();
}, [ chatMessages, moveChatUp, removeFirstHiddenChat ]);
removeHiddenChats();
}, [ chatMessages, moveChatUp, removeHiddenChats ]);
const makeRoom = useCallback((chat: ChatBubbleMessage) =>
{
@ -142,7 +133,7 @@ export const ChatWidgetView: FC<ChatWidgetViewProps> = props =>
{
if(!chat.elementRef) return;
chat.left = (chat.elementRef.offsetLeft + event.offsetX);
chat.left += event.offsetX;
});
}, [ roomSession, chatMessages ]);