mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 17:55:07 +08:00
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:
parent
175f6f6a14
commit
3a0212d720
|
@ -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}}
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user