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