FIX: Sidebar mode switching on subfolder (#27026)

This commit is contained in:
Jarek Radosz
2024-05-15 10:12:15 +02:00
committed by GitHub
parent 906f48694c
commit 24c55d6797
5 changed files with 45 additions and 33 deletions

View File

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