Activity #3530
Updated by Thara S Pillai over 1 year ago
In the file with notification logo Socket.IO at client for real-time updates, Defined in the page of notification logo to update logo inner text with counts on unread notifications <pre><code class="javascript"> <script> const socket = io(); // Automatically connects to same origin socket.on('new_user_notification', () (data) => { fetchUnreadNotifications(); console.log('Notification:', data.message); // This hits backend Update bell icon, etc. inner text fetchUnreadNotifications() to fetch new data get past unread notifications (e.g. last N days) }); async function fetchUnreadNotifications() { const res = await fetch('/notifications/unread'); const data = await res.json(); updateNotificationBell(data.count); renderNotificationList(data.notifications); } </script> </code></pre>