@@ -24,7 +24,6 @@ import { useEffect, useState } from "react";
2424import { useNotifications } from "../hooks/useNotifications" ;
2525import { useFriendNotifications } from "../contexts/FriendNotificationContext" ;
2626import { useMessageNotifications } from "../contexts/MessageNotificationContext" ;
27- import { createAuthSocket } from "@/socket" ;
2827
2928const navItems = [
3029 { label : "Servers" , icon : Users , path : "/servers" } ,
@@ -42,7 +41,7 @@ export default function Sidebar() {
4241 const [ error , setError ] = useState < string | null > ( null ) ;
4342
4443 // ✅ Get values directly from hooks (no refreshCount needed)
45- const { unreadCount, setUnreadCount } = useNotifications ( ) ;
44+ const { unreadCount } = useNotifications ( ) ;
4645 const { friendRequestCount, refreshCount : refreshFriendCount } =
4746 useFriendNotifications ( ) ;
4847 const { unreadMessageCount, refreshCount : refreshMessageCount } =
@@ -58,51 +57,6 @@ export default function Sidebar() {
5857 // Notifications page will handle its own refresh
5958 } ;
6059
61- // ✅ WebSocket-based real-time updates
62- useEffect ( ( ) => {
63- if ( ! user ?. id ) return ;
64-
65- const socket = createAuthSocket ( user . id ) ;
66-
67- // Listen for real-time notification events
68- socket . on ( "new_notification" , ( data ?: { count ?: number } ) => {
69- console . log ( "📬 New notification received" , data ) ;
70-
71- // If backend sends the new count, use it
72- if ( data ?. count !== undefined ) {
73- setUnreadCount ( data . count ) ;
74- } else {
75- // Otherwise increment locally
76- setUnreadCount ( ( prev ) => prev + 1 ) ;
77- }
78- } ) ;
79-
80- socket . on ( "new_message" , ( ) => {
81- console . log ( "💬 New message received" ) ;
82- // Message notifications context will handle its own update
83- refreshMessageCount ?.( ) ;
84- } ) ;
85-
86- socket . on ( "friend_request" , ( ) => {
87- console . log ( "👋 New friend request received" ) ;
88- refreshFriendCount ?.( ) ;
89- } ) ;
90-
91- socket . on ( "friend_request_accepted" , ( ) => {
92- console . log ( "✅ Friend request accepted" ) ;
93- refreshFriendCount ?.( ) ;
94- } ) ;
95-
96- // Cleanup on unmount
97- return ( ) => {
98- socket . off ( "new_notification" ) ;
99- socket . off ( "new_message" ) ;
100- socket . off ( "friend_request" ) ;
101- socket . off ( "friend_request_accepted" ) ;
102- socket . disconnect ( ) ;
103- } ;
104- } , [ user ?. id , setUnreadCount , refreshFriendCount , refreshMessageCount ] ) ;
105-
10660 // ✅ Refresh counts when window regains focus
10761 useEffect ( ( ) => {
10862 const handleFocus = async ( ) => {
@@ -164,12 +118,12 @@ export default function Sidebar() {
164118 >
165119 { /* Background */ }
166120 < div
167- className = "absolute inset-0 z-0 bg-no-repeat bg-cover opacity-90 border-r border-gray-800 pointer-events-none "
168- />
121+ className = "absolute inset-0 z-0 bg-no-repeat bg-cover opacity-90 border-r border-gray-800"
122+ />
169123
170124
171125 { /* Content */ }
172- < div className = "relative flex flex-col h-full justify-between" >
126+ < div className = "relative z-10 flex flex-col h-full justify-between" >
173127 { /* Top Section */ }
174128 < div >
175129 < div className = "flex items-center justify-between p-4" >
@@ -199,7 +153,6 @@ export default function Sidebar() {
199153 { navItems . map ( ( item ) => {
200154 const isActive = pathname === item . path ;
201155 let notificationCount = 0 ;
202- const showDotOnly = item . label === "Notifications" ;
203156 if ( item . label === "Notifications" ) {
204157 notificationCount = unreadCount ;
205158 } else if ( item . label === "Messages" ) {
@@ -224,9 +177,7 @@ export default function Sidebar() {
224177 < div className = "relative" >
225178 < item . icon className = "w-5 h-5" />
226179 { /* Show notification badge with animation */ }
227- { notificationCount > 0 && showDotOnly ? (
228- < span className = "absolute -top-1 -right-1 h-2.5 w-2.5 rounded-full bg-red-500 ring-2 ring-[#111214] animate-pulse" />
229- ) : notificationCount > 0 && (
180+ { notificationCount > 0 && (
230181 < span className = "absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full min-w-[16px] h-[16px] flex items-center justify-center px-1 font-bold animate-pulse" >
231182 { notificationCount > 99 ? "99+" : notificationCount }
232183 </ span >
@@ -239,7 +190,7 @@ export default function Sidebar() {
239190 { collapsed && (
240191 < div className = "absolute left-full top-1/2 -translate-y-1/2 ml-2 z-20 px-3 py-1 text-sm text-white bg-black rounded shadow-lg opacity-0 group-hover:opacity-100 transition" >
241192 { item . label }
242- { notificationCount > 0 && ! showDotOnly && ` (${ notificationCount } )` }
193+ { notificationCount > 0 && ` (${ notificationCount } )` }
243194 </ div >
244195 ) }
245196 </ div >
0 commit comments