mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
More chat updates
This commit is contained in:
parent
3ac7184758
commit
24b5ba658c
@ -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 ]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user