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:
parent
906f48694c
commit
24c55d6797
@ -4,36 +4,26 @@ import { fn } from "@ember/helper";
|
|||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import DButton from "discourse/components/d-button";
|
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 {
|
export default class SwitchPanelButtons extends Component {
|
||||||
@service router;
|
@service router;
|
||||||
@service sidebarState;
|
@service sidebarState;
|
||||||
|
|
||||||
@tracked currentPanel;
|
|
||||||
@tracked isSwitching = false;
|
@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
|
@action
|
||||||
async switchPanel(panel) {
|
async switchPanel(panel) {
|
||||||
this.isSwitching = true;
|
this.isSwitching = true;
|
||||||
this.currentPanel = panel;
|
|
||||||
this.sidebarState.currentPanel.lastKnownURL = this.router.currentURL;
|
this.sidebarState.currentPanel.lastKnownURL = this.router.currentURL;
|
||||||
|
|
||||||
if (this.destination) {
|
const destination = panel?.switchButtonDefaultUrl || panel?.lastKnownURL;
|
||||||
|
if (!destination) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.router.transitionTo(this.destination).followRedirects();
|
await this.router.transitionTo(destination).followRedirects();
|
||||||
this.sidebarState.setPanel(this.currentPanel.key);
|
this.sidebarState.setPanel(panel.key);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.name !== "TransitionAborted") {
|
if (e.name !== "TransitionAborted") {
|
||||||
throw e;
|
throw e;
|
||||||
@ -42,7 +32,6 @@ export default class SwitchPanelButtons extends Component {
|
|||||||
this.isSwitching = false;
|
this.isSwitching = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
{{#each @buttons as |button|}}
|
{{#each @buttons as |button|}}
|
||||||
|
@ -8,7 +8,6 @@ import { withPluginApi } from "discourse/lib/plugin-api";
|
|||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
import { escapeExpression } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import { avatarUrl } from "discourse-common/lib/avatar-utils";
|
import { avatarUrl } from "discourse-common/lib/avatar-utils";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message";
|
import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message";
|
||||||
@ -40,7 +39,7 @@ export default {
|
|||||||
switchButtonIcon = "d-chat";
|
switchButtonIcon = "d-chat";
|
||||||
|
|
||||||
get switchButtonDefaultUrl() {
|
get switchButtonDefaultUrl() {
|
||||||
return getURL(chatStateManager.lastKnownChatURL || "/chat");
|
return chatStateManager.lastKnownChatURL || "/chat";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -98,7 +98,12 @@ export default class ChatRoute extends DiscourseRoute {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (transition) {
|
if (transition) {
|
||||||
const url = this.router.urlFor(transition.from.name);
|
let url = this.router.urlFor(transition.from.name);
|
||||||
|
|
||||||
|
if (this.router.rootURL !== "/") {
|
||||||
|
url = url.replace(new RegExp(`^${this.router.rootURL}`), "/");
|
||||||
|
}
|
||||||
|
|
||||||
this.chatStateManager.storeChatURL(url);
|
this.chatStateManager.storeChatURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import KeyValueStore from "discourse/lib/key-value-store";
|
|||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
|
||||||
import { defaultHomepage } from "discourse/lib/utilities";
|
import { defaultHomepage } from "discourse/lib/utilities";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
|
||||||
import { getUserChatSeparateSidebarMode } from "discourse/plugins/chat/discourse/lib/get-user-chat-separate-sidebar-mode";
|
import { getUserChatSeparateSidebarMode } from "discourse/plugins/chat/discourse/lib/get-user-chat-separate-sidebar-mode";
|
||||||
|
|
||||||
const PREFERRED_MODE_KEY = "preferred_mode";
|
const PREFERRED_MODE_KEY = "preferred_mode";
|
||||||
@ -182,16 +181,17 @@ export default class ChatStateManager extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get lastKnownAppURL() {
|
get lastKnownAppURL() {
|
||||||
let url = this._appURL;
|
const url = this._appURL;
|
||||||
if (!url || url === "/") {
|
|
||||||
url = this.router.urlFor(`discovery.${defaultHomepage()}`);
|
if (url && url !== "/") {
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getURL(url);
|
return this.router.urlFor(`discovery.${defaultHomepage()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
get lastKnownChatURL() {
|
get lastKnownChatURL() {
|
||||||
return getURL(this._chatURL || "/chat");
|
return this._chatURL || "/chat";
|
||||||
}
|
}
|
||||||
|
|
||||||
#publishStateChange() {
|
#publishStateChange() {
|
||||||
|
@ -205,6 +205,25 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with subfolder" do
|
||||||
|
let!(:channel_browse_page) { PageObjects::Pages::ChatBrowse.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
set_subfolder "/discuss"
|
||||||
|
chat_page.prefers_full_page
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has the expected behavior" do
|
||||||
|
visit("/discuss/about")
|
||||||
|
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
expect(channel_browse_page.component).to be_present
|
||||||
|
|
||||||
|
sidebar_component.switch_to_main
|
||||||
|
expect(page).to have_current_path("/discuss/")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when separate sidebar mode is fullscreen" do
|
describe "when separate sidebar mode is fullscreen" do
|
||||||
|
Loading…
Reference in New Issue
Block a user