mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FIX: Save previous chat state when navigating with the sidebar (#25537)
This commit is contained in:
@ -8,24 +8,32 @@ 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
|
||||||
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;
|
||||||
|
|
||||||
const url = panel.lastKnownURL || panel.switchButtonDefaultUrl;
|
if (this.destination) {
|
||||||
const destination =
|
try {
|
||||||
url === "/" ? `discovery.${defaultHomepage()}` : getURL(url);
|
await this.router.transitionTo(this.destination);
|
||||||
|
this.sidebarState.setPanel(this.currentPanel.key);
|
||||||
this.router
|
} finally {
|
||||||
.transitionTo(destination)
|
|
||||||
.then(() => {
|
|
||||||
this.sidebarState.setPanel(panel.key);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.isSwitching = false;
|
this.isSwitching = false;
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,18 @@ export default {
|
|||||||
this.currentUser = container.lookup("service:current-user");
|
this.currentUser = container.lookup("service:current-user");
|
||||||
|
|
||||||
withPluginApi("1.8.0", (api) => {
|
withPluginApi("1.8.0", (api) => {
|
||||||
|
const chatStateManager = container.lookup("service:chat-state-manager");
|
||||||
|
|
||||||
api.addSidebarPanel(
|
api.addSidebarPanel(
|
||||||
(BaseCustomSidebarPanel) =>
|
(BaseCustomSidebarPanel) =>
|
||||||
class ChatSidebarPanel extends BaseCustomSidebarPanel {
|
class ChatSidebarPanel extends BaseCustomSidebarPanel {
|
||||||
key = CHAT_PANEL;
|
key = CHAT_PANEL;
|
||||||
switchButtonLabel = I18n.t("sidebar.panels.chat.label");
|
switchButtonLabel = I18n.t("sidebar.panels.chat.label");
|
||||||
switchButtonIcon = "d-chat";
|
switchButtonIcon = "d-chat";
|
||||||
switchButtonDefaultUrl = getURL("/chat");
|
|
||||||
|
get switchButtonDefaultUrl() {
|
||||||
|
return getURL(chatStateManager.lastKnownChatURL || "/chat");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ RSpec.describe "Navigation", type: :system do
|
|||||||
thread.add(current_user)
|
thread.add(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "correctly closes the panel" do
|
it "correctly shows the thread panel" do
|
||||||
chat_page.visit_thread(thread)
|
chat_page.visit_thread(thread)
|
||||||
|
|
||||||
expect(side_panel_page).to have_open_thread(thread)
|
expect(side_panel_page).to have_open_thread(thread)
|
||||||
@ -443,7 +443,7 @@ RSpec.describe "Navigation", type: :system do
|
|||||||
find("#site-logo").click
|
find("#site-logo").click
|
||||||
sidebar_component.switch_to_chat
|
sidebar_component.switch_to_chat
|
||||||
|
|
||||||
expect(page).to have_no_css(".chat-side-panel")
|
expect(side_panel_page).to have_open_thread(thread)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,6 +27,10 @@ module PageObjects
|
|||||||
find(".chat-header-icon").click
|
find(".chat-header-icon").click
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_from_header
|
||||||
|
find(".chat-header-icon").click
|
||||||
|
end
|
||||||
|
|
||||||
def has_header_href?(href)
|
def has_header_href?(href)
|
||||||
find(".chat-header-icon").has_link?(href: href)
|
find(".chat-header-icon").has_link?(href: href)
|
||||||
end
|
end
|
||||||
|
@ -9,10 +9,12 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
|
|
||||||
fab!(:current_user) { Fabricate(:user) }
|
fab!(:current_user) { Fabricate(:user) }
|
||||||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||||
|
fab!(:channel_2) { Fabricate(:chat_channel) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.navigation_menu = "sidebar"
|
SiteSetting.navigation_menu = "sidebar"
|
||||||
channel_1.add(current_user)
|
channel_1.add(current_user)
|
||||||
|
channel_2.add(current_user)
|
||||||
chat_system_bootstrap
|
chat_system_bootstrap
|
||||||
sign_in(current_user)
|
sign_in(current_user)
|
||||||
end
|
end
|
||||||
@ -145,6 +147,15 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
|
|
||||||
expect(sidebar_component).to have_no_section("chat-channels")
|
expect(sidebar_component).to have_no_section("chat-channels")
|
||||||
expect(sidebar_component).to have_section("Categories")
|
expect(sidebar_component).to have_section("Categories")
|
||||||
|
|
||||||
|
chat_drawer_page.open_channel(channel_2)
|
||||||
|
|
||||||
|
expect(chat_drawer_page).to have_open_channel(channel_2)
|
||||||
|
|
||||||
|
chat_drawer_page.close
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
|
||||||
|
expect(chat_drawer_page).to have_open_channel(channel_2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -182,6 +193,16 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
|
|
||||||
expect(sidebar_component).to have_no_section("chat-channels")
|
expect(sidebar_component).to have_no_section("chat-channels")
|
||||||
expect(sidebar_component).to have_section("Categories")
|
expect(sidebar_component).to have_section("Categories")
|
||||||
|
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
sidebar_page.open_channel(channel_2)
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
|
|
||||||
|
chat_page.close_from_header
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -222,6 +243,15 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
|
|
||||||
expect(sidebar_component).to have_section("Categories")
|
expect(sidebar_component).to have_section("Categories")
|
||||||
expect(sidebar_component).to have_section("chat-channels")
|
expect(sidebar_component).to have_section("chat-channels")
|
||||||
|
|
||||||
|
sidebar_page.open_channel(channel_2)
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
|
|
||||||
|
chat_drawer_page.close
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -259,6 +289,16 @@ RSpec.describe "Separate sidebar mode", type: :system do
|
|||||||
|
|
||||||
expect(sidebar_component).to have_section("chat-channels")
|
expect(sidebar_component).to have_section("chat-channels")
|
||||||
expect(sidebar_component).to have_section("Categories")
|
expect(sidebar_component).to have_section("Categories")
|
||||||
|
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
sidebar_page.open_channel(channel_2)
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
|
|
||||||
|
chat_page.close_from_header
|
||||||
|
sidebar_component.switch_to_chat
|
||||||
|
|
||||||
|
expect(sidebar_component).to have_section_link(channel_2.name, active: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user