mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Sidebar mode switching on subfolder (#27026)
This commit is contained in:
@@ -4,43 +4,32 @@ import { fn } from "@ember/helper";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import DButton from "discourse/components/d-button";
|
||||
import { defaultHomepage } from "discourse/lib/utilities";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
|
||||
export default class SwitchPanelButtons extends Component {
|
||||
@service router;
|
||||
@service sidebarState;
|
||||
|
||||
@tracked currentPanel;
|
||||
@tracked isSwitching = false;
|
||||
|
||||
get destination() {
|
||||
if (this.currentPanel) {
|
||||
const url =
|
||||
this.currentPanel.switchButtonDefaultUrl ||
|
||||
this.currentPanel.lastKnownURL;
|
||||
return url === "/" ? `discovery.${defaultHomepage()}` : getURL(url);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@action
|
||||
async switchPanel(panel) {
|
||||
this.isSwitching = true;
|
||||
this.currentPanel = panel;
|
||||
this.sidebarState.currentPanel.lastKnownURL = this.router.currentURL;
|
||||
|
||||
if (this.destination) {
|
||||
try {
|
||||
await this.router.transitionTo(this.destination).followRedirects();
|
||||
this.sidebarState.setPanel(this.currentPanel.key);
|
||||
} catch (e) {
|
||||
if (e.name !== "TransitionAborted") {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
this.isSwitching = false;
|
||||
const destination = panel?.switchButtonDefaultUrl || panel?.lastKnownURL;
|
||||
if (!destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.router.transitionTo(destination).followRedirects();
|
||||
this.sidebarState.setPanel(panel.key);
|
||||
} catch (e) {
|
||||
if (e.name !== "TransitionAborted") {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
this.isSwitching = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user