@@ -8,6 +8,7 @@ import { HiMiniUserGroup } from "react-icons/hi2";
88import { useAppDispatch } from "../redux/hooks" ;
99import Spinner from "../components/dashboard/Spinner" ;
1010import { fetchChats , fetchUsers } from "../redux/reducers/chatSlice" ;
11+ import { socket } from "../config/socket" ;
1112
1213interface UserListProps {
1314 onUserSelect : ( chat : any | null , user : any ) => void ;
@@ -38,6 +39,17 @@ const UserList: React.FC<UserListProps> = ({
3839 useEffect ( ( ) => {
3940 dispatch ( fetchChats ( ) ) ;
4041 dispatch ( fetchUsers ( ) ) ;
42+
43+ const handlePrivateMessage = ( ) => {
44+ dispatch ( fetchChats ( ) ) ;
45+ dispatch ( fetchUsers ( ) ) ;
46+ } ;
47+
48+ socket . on ( "private message recieved" , handlePrivateMessage ) ;
49+
50+ return ( ) => {
51+ socket . off ( "private message recieved" , handlePrivateMessage ) ;
52+ } ;
4153 } , [ dispatch ] ) ;
4254
4355 useEffect ( ( ) => {
@@ -114,7 +126,7 @@ const UserList: React.FC<UserListProps> = ({
114126 < input
115127 type = "text"
116128 placeholder = "Search..."
117- className = "px-10 py-2 rounded-md dark: border-[1px] text-gray-500 w-full outline-none bg-bg-gray dark: bg-transparent dark: border-dark-gray focus:outline-none"
129+ className = "px-10 py-2 rounded-md border-[1px] text-gray-500 w-full outline-none bg-bg-gray bg-transparent border-dark-gray focus:outline-none"
118130 value = { searchTerm }
119131 onChange = { handleSearchChange }
120132 />
@@ -193,7 +205,7 @@ const UserList: React.FC<UserListProps> = ({
193205 { chat . messages . length > 0
194206 ? chat . messages [
195207 chat . messages . length - 1
196- ] . message . substring ( 0 , 20 )
208+ ] . message . substring ( 0 , 15 )
197209 : "No messages yet" }
198210 ...
199211 </ p >
0 commit comments