Use the new tab counters to reflect the number of stored quotes
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jan 2025 16:31:51 +0000 (17:31 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Jan 2025 16:31:51 +0000 (17:31 +0100)
ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts
ts/WoltLabSuite/Core/Component/Quote/List.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js

index 3b38892d181e5ea3b1e4ff399eaf2e028441da3d..390433d0ef4cb07e898e8c1c0b3df2a859becce9 100644 (file)
@@ -65,29 +65,26 @@ class TabMenu {
     this.#activeTabName = tabName;
   }
 
-  showTab(tabName: string, title?: string): void {
-    this.#tabs
-      .filter((element) => element.dataset.name === tabName)
-      .forEach((element) => {
-        element.hidden = false;
-
-        // Set new title
-        if (title) {
-          element.querySelector("span")!.textContent = title;
-        }
-      });
+  showTab(tabName: string): void {
+    const tab = this.#tabs.find((element) => element.dataset.name === tabName);
+    if (tab === undefined) {
+      return;
+    }
+
+    tab.hidden = false;
   }
 
   hideTab(tabName: string): void {
-    this.#tabs
-      .filter((element) => element.dataset.name === tabName)
-      .forEach((element) => {
-        element.hidden = true;
-
-        if (element.classList.contains("active")) {
-          this.#closeAllTabs();
-        }
-      });
+    const tab = this.#tabs.find((element) => element.dataset.name === tabName);
+    if (tab === undefined) {
+      return;
+    }
+
+    tab.hidden = false;
+
+    if (tab.classList.contains("active")) {
+      this.#closeAllTabs();
+    }
   }
 
   setTabCounter(tabName: string, value: number): void {
index fa2c558a0bfea43f8b9421e53c81a04e74b51a3b..d206427e26ba79f828f830b7c408cc412380b744 100644 (file)
@@ -86,15 +86,17 @@ class QuoteList {
       });
     }
 
+    const tabMenu = getTabMenu(this.#editorId);
+    if (tabMenu === undefined) {
+      throw new Error(`Could not find the tab menu for '${this.#editorId}'.`);
+    }
+
+    tabMenu.setTabCounter("quotes", quotesCount);
+
     if (quotesCount > 0) {
-      getTabMenu(this.#editorId)?.showTab(
-        "quotes",
-        getPhrase("wcf.message.quote.showQuotes", {
-          count: quotesCount,
-        }),
-      );
+      tabMenu.showTab("quotes");
     } else {
-      getTabMenu(this.#editorId)?.hideTab("quotes");
+      tabMenu.hideTab("quotes");
     }
   }
 }
index 7974eff75d1935666d3db92613fe5047f9fa2d35..6ed16709b1b66d3b776d7be442ba24a4df61e0e9 100644 (file)
@@ -53,26 +53,22 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "Wol
             this.#tabContainers[tabIndex].classList.add("active");
             this.#activeTabName = tabName;
         }
-        showTab(tabName, title) {
-            this.#tabs
-                .filter((element) => element.dataset.name === tabName)
-                .forEach((element) => {
-                element.hidden = false;
-                // Set new title
-                if (title) {
-                    element.querySelector("span").textContent = title;
-                }
-            });
+        showTab(tabName) {
+            const tab = this.#tabs.find((element) => element.dataset.name === tabName);
+            if (tab === undefined) {
+                return;
+            }
+            tab.hidden = false;
         }
         hideTab(tabName) {
-            this.#tabs
-                .filter((element) => element.dataset.name === tabName)
-                .forEach((element) => {
-                element.hidden = true;
-                if (element.classList.contains("active")) {
-                    this.#closeAllTabs();
-                }
-            });
+            const tab = this.#tabs.find((element) => element.dataset.name === tabName);
+            if (tab === undefined) {
+                return;
+            }
+            tab.hidden = false;
+            if (tab.classList.contains("active")) {
+                this.#closeAllTabs();
+            }
         }
         setTabCounter(tabName, value) {
             const tab = this.#tabs.find((element) => element.dataset.name === tabName);
index 6d12ac1fb2b334f7c22a4c81b8fc5d0ec7d913cc..63653435347e2773fc2fb4d379db87111c3697a7 100644 (file)
@@ -73,13 +73,16 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Ckeditor/Eve
                     this.#container.append(fragment);
                 });
             }
+            const tabMenu = (0, MessageTabMenu_1.getTabMenu)(this.#editorId);
+            if (tabMenu === undefined) {
+                throw new Error(`Could not find the tab menu for '${this.#editorId}'.`);
+            }
+            tabMenu.setTabCounter("quotes", quotesCount);
             if (quotesCount > 0) {
-                (0, MessageTabMenu_1.getTabMenu)(this.#editorId)?.showTab("quotes", (0, Language_1.getPhrase)("wcf.message.quote.showQuotes", {
-                    count: quotesCount,
-                }));
+                tabMenu.showTab("quotes");
             }
             else {
-                (0, MessageTabMenu_1.getTabMenu)(this.#editorId)?.hideTab("quotes");
+                tabMenu.hideTab("quotes");
             }
         }
     }