From 4eaf918aad4f7144d0c4cd73f155180d5835ffa6 Mon Sep 17 00:00:00 2001 From: duckietm Date: Wed, 9 Apr 2025 16:54:27 +0200 Subject: [PATCH] :up: ReDesign ChatHistory --- .../images/chathistory/chathistory_toggle.png | Bin 0 -> 398 bytes .../chat-history/ChatHistoryView.scss | 39 +++++- .../chat-history/ChatHistoryView.tsx | 112 +++++++++++------- src/hooks/chat-history/useChatHistory.ts | 10 +- 4 files changed, 114 insertions(+), 47 deletions(-) create mode 100644 src/assets/images/chathistory/chathistory_toggle.png diff --git a/src/assets/images/chathistory/chathistory_toggle.png b/src/assets/images/chathistory/chathistory_toggle.png new file mode 100644 index 0000000000000000000000000000000000000000..ac3bbd5e35f9d07b4acaaad5fc0e17c9c6760eff GIT binary patch literal 398 zcmeAS@N?(olHy`uVBq!ia0vp^{6K8a!3HANOnMHa7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS0%1l`4X*~E24znd$B+p3x6=c&4mk+4sY?rc@CCb?i1912 za5cGqSZMbmxpo7;t?R+rBA!bp$f-55OrCX8M`ESwX6>NF{nP(Qe>$tSc|+pbiyOjk zZEG;Ad9zQai^F@`2_>6u3HxuSU#(K{o)QZ?=p4@u@RXC7%VayT2jf1H = props => { - const { chatHistory = [] } = useChatHistory(); + const { chatHistory = [], clearChatHistory } = useChatHistory(); const [ isVisible, setIsVisible ] = useState(false); - const { onClickChat = null } = useOnClickChat(); + const { onClickChat = null } = useOnClickChat(); const [ searchText, setSearchText ] = useState(''); + const elementRef = useRef(null); const filteredChatHistory = useMemo(() => @@ -21,6 +23,13 @@ export const ChatHistoryView: FC<{}> = props => return chatHistory.filter(entry => ((entry.message && entry.message.toLowerCase().includes(text))) || (entry.name && entry.name.toLowerCase().includes(text))); }, [ chatHistory, searchText ]); + const handleClearHistory = () => + { + if (clearChatHistory) { + clearChatHistory(); + } + }; + useEffect(() => { if(elementRef && elementRef.current && isVisible) elementRef.current.scrollTop = elementRef.current.scrollHeight; @@ -32,9 +41,9 @@ export const ChatHistoryView: FC<{}> = props => linkReceived: (url: string) => { const parts = url.split('/'); - + if(parts.length < 2) return; - + switch(parts[1]) { case 'show': @@ -56,42 +65,61 @@ export const ChatHistoryView: FC<{}> = props => return () => RemoveLinkEventTracker(linkTracker); }, []); - if(!isVisible) return null; - return ( - - setIsVisible(false) }/> - - setSearchText(event.target.value) } /> - - { - return ( - - { row.timestamp } - { (row.type === ChatEntryType.TYPE_CHAT) && -
- { (row.style === 0) && -
} -
-
- { row.imageUrl && (row.imageUrl.length > 0) && -
} -
-
- - onClickChat(e) }/> -
-
-
} - { (row.type === ChatEntryType.TYPE_ROOM_INFO) && - <> - - { row.name } - } - - ) - } } /> - - + + { isVisible && ( + + + + + + + + + { + return ( + + {row.timestamp} + { (row.type === ChatEntryType.TYPE_CHAT) && +
+ { (row.style === 0) && +
} +
+
+ { row.imageUrl && (row.imageUrl.length > 0) && +
} +
+
+ + onClickChat(e)} /> +
+
+
} + { (row.type === ChatEntryType.TYPE_ROOM_INFO) && + <> + + {row.name} + } + + ) + }} + /> + + + setIsVisible(false)} /> + + + )} + ); -} +}; \ No newline at end of file diff --git a/src/hooks/chat-history/useChatHistory.ts b/src/hooks/chat-history/useChatHistory.ts index 4c0aa03..83c9ad0 100644 --- a/src/hooks/chat-history/useChatHistory.ts +++ b/src/hooks/chat-history/useChatHistory.ts @@ -65,6 +65,12 @@ const useChatHistoryState = () => }); } + const clearChatHistory = () => + { + setChatHistory([]); + CHAT_HISTORY_COUNTER = 0; + }; + useRoomSessionManagerEvent(RoomSessionEvent.STARTED, event => setNeedsRoomInsert(true)); useMessageEvent(GetGuestRoomResultEvent, event => @@ -99,7 +105,7 @@ const useChatHistoryState = () => addMessengerEntry({ id: -1, webId: parser.senderId, entityId: -1, name: '', message: parser.messageText, roomId: -1, timestamp: MessengerHistoryCurrentDate(), type: ChatEntryType.TYPE_IM }); }); - return { addChatEntry, chatHistory, roomHistory, messengerHistory }; + return { addChatEntry, chatHistory, roomHistory, messengerHistory, clearChatHistory }; } -export const useChatHistory = () => useBetween(useChatHistoryState); +export const useChatHistory = () => useBetween(useChatHistoryState); \ No newline at end of file