FIX: disable switch sidebar panel button after click (#23007)

Bug when you click fast on the switch panel button. It is happening because we are not waiting for the transition to finish before update state.

In addition, unused currentPanel property was removed.
This commit is contained in:
Krzysztof Kotlarek 2023-08-08 14:58:27 +10:00 committed by GitHub
parent 175f6f6a14
commit 3a0212d720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -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}}

View File

@ -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);
});
}
}