@@ -86,58 +86,14 @@ function Navbar({ showBack }) {
8686 . then ( ( d ) => Array . isArray ( d ) && setNotifs ( d ) ) ;
8787
8888 const socket = getSocket ( user . id ) ;
89- socket . on ( "new-course" , ( notif ) => {
90- setNotifs ( ( prev ) => [
91- {
92- id : notif . id || Date . now ( ) ,
93- message : notif . message ,
94- createdAt : notif . createdAt ,
95- read : false ,
96- } ,
97- ...prev ,
98- ] ) ;
99- } ) ;
100- socket . on ( "live-class-scheduled" , ( data ) => {
101- setNotifs ( ( prev ) => [
102- {
103- id : `lc_${ Date . now ( ) } ` ,
104- message : `📹 Live class scheduled: "${ data . title } "` ,
105- createdAt : new Date ( ) . toISOString ( ) ,
106- read : false ,
107- } ,
108- ...prev ,
109- ] ) ;
110- } ) ;
111- socket . on ( "live-class-status" , ( data ) => {
112- if ( data . status === "live" ) {
113- setNotifs ( ( prev ) => [
114- {
115- id : `lcs_${ Date . now ( ) } ` ,
116- message : `🔴 A live class just started!` ,
117- createdAt : new Date ( ) . toISOString ( ) ,
118- read : false ,
119- } ,
120- ...prev ,
121- ] ) ;
122- }
123- } ) ;
124- socket . on ( "student-enrolled" , ( data ) => {
125- setNotifs ( ( prev ) => [
126- {
127- id : `enroll_${ Date . now ( ) } ` ,
128- message : data . message || "A student enrolled in your course" ,
129- createdAt : new Date ( ) . toISOString ( ) ,
130- read : false ,
131- } ,
132- ...prev ,
133- ] ) ;
89+
90+ // Single unified listener — backend persists to DB before emitting
91+ socket . on ( "notification:new" , ( notif ) => {
92+ setNotifs ( ( prev ) => [ { ...notif , read : false } , ...prev ] ) ;
13493 } ) ;
13594
13695 return ( ) => {
137- socket . off ( "new-course" ) ;
138- socket . off ( "live-class-scheduled" ) ;
139- socket . off ( "live-class-status" ) ;
140- socket . off ( "student-enrolled" ) ;
96+ socket . off ( "notification:new" ) ;
14197 } ;
14298 } , [ user ?. id , isAuthenticated ] ) ;
14399
0 commit comments