A platform for community discussion. Free, open, simple.
FIX: disable switch sidebar panel button after click (#23007)
Krzysztof Kotlarek3a0212d72086
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.hbs b/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.hbsindex aee2505a104..e558957c56c 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.hbs+++ b/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.hbs@@ -1,8 +1,9 @@{{#each @buttons as |button|}}<DButton- @action={{action "switchPanel" @currentPanel button}}+ @action={{action "switchPanel" button}}@class="btn-default sidebar__panel-switch-button"@icon={{button.switchButtonIcon}}+ @disabled={{this.isSwitching}}@translatedLabel={{button.switchButtonLabel}}/>{{/each}}\ No newline at end of filediff --git a/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.js b/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.jsindex 05f9c679789..b6ed9bae1ae 100644--- a/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.js+++ b/app/assets/javascripts/discourse/app/components/sidebar/switch-panel-buttons.js@@ -1,20 +1,23 @@import Component from "@glimmer/component";import { inject as service } from "@ember/service";import { action } from "@ember/object";+import { tracked } from "@glimmer/tracking";export default class SwitchPanelButtons extends Component {@service router;@service sidebarState;+ @tracked isSwitching = false;@action- switchPanel(currentPanel, panel) {+ switchPanel(panel) {+ this.isSwitching = true;this.sidebarState.currentPanel.lastKnownURL = this.router.currentURL;- this.sidebarState.setPanel(panel.key);+const url = panel.lastKnownURL || panel.switchButtonDefaultUrl;- if (url === "/") {- this.router.transitionTo("discovery.latest");- } else {- this.router.transitionTo(url);- }+ const destination = url === "/" ? "/latest" : url;+ this.router.transitionTo(destination).finally(() => {+ this.isSwitching = false;+ this.sidebarState.setPanel(panel.key);+ });}}