From 2a1b94abc5657f571cbf5b6d9756332f0beecec1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 8 Jan 2025 17:31:51 +0100 Subject: [PATCH] Use the new tab counters to reflect the number of stored quotes --- .../Core/Component/Message/MessageTabMenu.ts | 37 +++++++++---------- ts/WoltLabSuite/Core/Component/Quote/List.ts | 16 ++++---- .../Core/Component/Message/MessageTabMenu.js | 32 +++++++--------- .../WoltLabSuite/Core/Component/Quote/List.js | 11 ++++-- 4 files changed, 47 insertions(+), 49 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts b/ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts index 3b38892d18..390433d0ef 100644 --- a/ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts +++ b/ts/WoltLabSuite/Core/Component/Message/MessageTabMenu.ts @@ -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 { diff --git a/ts/WoltLabSuite/Core/Component/Quote/List.ts b/ts/WoltLabSuite/Core/Component/Quote/List.ts index fa2c558a0b..d206427e26 100644 --- a/ts/WoltLabSuite/Core/Component/Quote/List.ts +++ b/ts/WoltLabSuite/Core/Component/Quote/List.ts @@ -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"); } } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js index 7974eff75d..6ed16709b1 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Message/MessageTabMenu.js @@ -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); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js index 6d12ac1fb2..6365343534 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/List.js @@ -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"); } } } -- 2.20.1