Set the unread counter on page load
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 Nov 2021 15:22:17 +0000 (16:22 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 Nov 2021 15:22:17 +0000 (16:22 +0100)
ts/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/User/Menu/Data/Notification.js

index 2e231c43b7e33cd033f4654ab2606c9dfc505652..658f5518a19ac3ae161d6f51368d8bfc6535f5a7 100644 (file)
@@ -102,8 +102,23 @@ function drawCounter(ctx: CanvasRenderingContext2D, counter: string): void {
 }
 
 export class UserMenuDataNotification implements UserMenuProvider {
+  private readonly button: HTMLElement | null;
   private view: UserMenuView | undefined = undefined;
 
+  constructor() {
+    this.button = document.getElementById("userNotifications");
+
+    if (this.button) {
+      const badge = this.button.querySelector(".badge");
+      if (badge) {
+        const counter = parseInt(badge.textContent!.trim());
+        if (counter) {
+          updateUnreadCounter(counter);
+        }
+      }
+    }
+  }
+
   getButtons(): UserMenuButton[] {
     return [
       {
index 6b4d23e0958e31151f54f852b8284478562332cb..a824f2f06741fd8d5a57e9ca85c2658128f0924f 100644 (file)
@@ -88,6 +88,16 @@ define(["require", "exports", "tslib", "../../../../Ajax", "../View"], function
     class UserMenuDataNotification {
         constructor() {
             this.view = undefined;
+            this.button = document.getElementById("userNotifications");
+            if (this.button) {
+                const badge = this.button.querySelector(".badge");
+                if (badge) {
+                    const counter = parseInt(badge.textContent.trim());
+                    if (counter) {
+                        updateUnreadCounter(counter);
+                    }
+                }
+            }
         }
         getButtons() {
             return [