diff --git a/src/components/LBDashboard/Messaging/LBMessaging.jsx b/src/components/LBDashboard/Messaging/LBMessaging.jsx index 7dcf80469d..8ebf0b5328 100644 --- a/src/components/LBDashboard/Messaging/LBMessaging.jsx +++ b/src/components/LBDashboard/Messaging/LBMessaging.jsx @@ -20,6 +20,7 @@ import { markMessagesAsReadViaSocket, } from '../../../utils/messagingSocket'; import logo from '../../../assets/images/logo2.png'; +import Header from '../../Header/Header'; export default function LBMessaging() { const dispatch = useDispatch(); @@ -56,7 +57,7 @@ export default function LBMessaging() { const sidebarContacts = useMemo(() => { const chats = [...existingChats]; const sid = selectedUser?.userId; - if (!sid) return chats; + if (!sid || !selectedUser?.firstName) return chats; const exists = chats.some(c => String(c.userId ?? c._id) === String(sid)); if (!exists) { chats.unshift({ @@ -152,7 +153,7 @@ export default function LBMessaging() { useEffect(() => { const handleClickOutside = event => { if (menuRef.current && !menuRef.current.contains(event.target)) { - setMobileHamMenu(false); // Close the menu if clicked outside + setMobileHamMenu(false); } }; @@ -259,7 +260,6 @@ export default function LBMessaging() { toast.success('Preferences updated successfully!'); setBellDropdownActive(false); - // Refresh preferences after saving dispatch(fetchUserPreferences(currentUserId, selectedUser.userId)).then(response => { if (response?.payload) { setSelectedOption({ @@ -313,6 +313,34 @@ export default function LBMessaging() { return () => window.removeEventListener('resize', handleResize); }, []); + const handleSearchChange = e => { + const query = e.target.value; + setSearchQuery(query); + if (query.trim() === '') { + setSearchResults([]); + } else { + searchUserProfiles(query); + } + }; + + const renderContactButton = (key, user, onClick) => ( + + ); + const renderContacts = () => { if (sidebarContacts.length === 0) { return ( @@ -320,40 +348,21 @@ export default function LBMessaging() { ); } - return sidebarContacts.map(user => ( - - )); + return sidebarContacts.map(user => + renderContactButton(user.userId || user._id, user, () => { + updateSelection(user); + setMobileHamMenu(false); + }), + ); }; const renderChatMessages = () => { if (messagesLoading) { - return
Loading messages...
; + returnLoading messages...
; } if (messages.length === 0) { - returnNo messages to display.
; + returnNo messages to display.
; } const filteredMessages = messages.filter( @@ -363,12 +372,12 @@ export default function LBMessaging() { ); if (filteredMessages.length === 0) { - returnNo messages to display.
; + returnNo messages to display.
; } return ( -+
{String(message.content ?? '') .split('\n') .map((line, lineIdx) => ( @@ -396,61 +405,63 @@ export default function LBMessaging() { return ( (users?.userProfilesBasicInfo?.length ?? 0) !== 0 && (
Select a user to start chatting
+Select a user to start chatting
)}