FIX: Sidebar mode switching on subfolder ()

This commit is contained in:
Jarek Radosz 2024-05-15 10:12:15 +02:00 committed by GitHub
parent 906f48694c
commit 24c55d6797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 33 deletions
app/assets/javascripts/discourse/app/components/sidebar
plugins/chat
assets/javascripts/discourse
spec/system

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

@ -8,7 +8,6 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import { avatarUrl } from "discourse-common/lib/avatar-utils";
import getURL from "discourse-common/lib/get-url";
import { bind } from "discourse-common/utils/decorators";
import I18n from "discourse-i18n";
import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message";
@ -40,7 +39,7 @@ export default {
switchButtonIcon = "d-chat";
get switchButtonDefaultUrl() {
return getURL(chatStateManager.lastKnownChatURL || "/chat");
return chatStateManager.lastKnownChatURL || "/chat";
}
}
);

@ -98,7 +98,12 @@ export default class ChatRoute extends DiscourseRoute {
});
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);
}

@ -4,7 +4,6 @@ import KeyValueStore from "discourse/lib/key-value-store";
import { withPluginApi } from "discourse/lib/plugin-api";
import { MAIN_PANEL } from "discourse/lib/sidebar/panels";
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";
const PREFERRED_MODE_KEY = "preferred_mode";
@ -182,16 +181,17 @@ export default class ChatStateManager extends Service {
}
get lastKnownAppURL() {
let url = this._appURL;
if (!url || url === "/") {
url = this.router.urlFor(`discovery.${defaultHomepage()}`);
const url = this._appURL;
if (url && url !== "/") {
return url;
}
return getURL(url);
return this.router.urlFor(`discovery.${defaultHomepage()}`);
}
get lastKnownChatURL() {
return getURL(this._chatURL || "/chat");
return this._chatURL || "/chat";
}
#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)
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
describe "when separate sidebar mode is fullscreen" do