diff --git a/packages/react/src/components/Message/Message.js b/packages/react/src/components/Message/Message.js index f07cc9727..2bbb640a9 100644 --- a/packages/react/src/components/Message/Message.js +++ b/packages/react/src/components/Message/Message.js @@ -53,6 +53,7 @@ const Message = ({ showAvatar = false, className = '', style = {}, + showToolbox = true, }) => { const { classNames, styleOverrides } = useComponentOverrides( 'Message', @@ -215,7 +216,7 @@ const Message = ({ handleOpenThread={handleOpenThread} /> ) : null} - {!message.t ? ( + {!message.t && showToolbox ? ( { const { RCInstance } = useContext(RCContext); const setShowSearch = useSearchMessageStore((state) => state.setShowSearch); - const authenticatedUserUsername = useUserStore((state) => state.username); const toggleShowSearch = () => { setShowSearch(false); @@ -27,83 +22,134 @@ const Search = () => { const [text, setText] = useState(''); const [messageList, setMessageList] = useState([]); + const handleInputChange = (e) => { + setText(e.target.value); + }; + const searchMessages = async () => { const { messages } = await RCInstance.getSearchMessages(text); setMessageList(messages); }; - const handleKeyPress = (e) => { - if (e.key === 'Enter') { - searchMessages(); + const debouncedSearch = debounce(async () => { + await searchMessages(); + }, 500); // 500ms delay + + useEffect(() => { + if (!text.trim()) { + setMessageList([]); + } else { + debouncedSearch(); } - }; + + // Cleanup function to cancel the debounce on component unmount + return () => { + debouncedSearch.cancel(); + }; + }, [text, debouncedSearch]); const isMessageNewDay = (current, previous) => !previous || !isSameDay(new Date(current.ts), new Date(previous.ts)); return ( - -

- - Search Messages - - - -

-
- - setText(e.target.value)} - onKeyDown={handleKeyPress} - className={classes.textInput} - /> + + +

+ + + Search Messages + + + + +

+
+ + - - - {messageList && - messageList.map((msg, index, arr) => { - const prev = arr[index + 1]; - const newDay = isMessageNewDay(msg, prev); - return ( - - {newDay && ( - - {format(new Date(msg.ts), 'MMMM d, yyyy')} - - )} - - - - - - - +
+ + {messageList.length == 0 ? ( + + + + No results found + + + ) : ( + messageList.map((msg, index, arr) => { + const prev = arr[index + 1]; + const newDay = isMessageNewDay(msg, prev); + const sequential = isMessageSequential(msg, prev, 300); + return ( + + {newDay && ( + + + {format(new Date(msg.ts), 'MMMM d, yyyy')} + + + )} + - - - - ); - })} + + ); + }) + )} + +
); }; diff --git a/packages/react/src/components/SearchMessage/SearchMessage.module.css b/packages/react/src/components/SearchMessage/SearchMessage.module.css index 8369e2381..a90e7f4c6 100644 --- a/packages/react/src/components/SearchMessage/SearchMessage.module.css +++ b/packages/react/src/components/SearchMessage/SearchMessage.module.css @@ -11,6 +11,12 @@ z-index: 100; } +.wrapContainer { + height: 100%; + display: flex; + flex-direction: column; +} + .container { display: flex; align-items: center;