Skip to content

A platform for community discussion. Free, open, simple.

UX: alters chat icon behavior on drawer and mobile (#19192)

Joffrey JAFFEUX9ade68233cc0
diff --git a/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js b/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js
index a0c280a5d19..50985147a84 100644
--- a/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js
+++ b/plugins/chat/assets/javascripts/discourse/widgets/chat-header-icon.js
@@ -64,13 +64,21 @@ export default createWidget("header-chat-link", {
},
click() {
- if (this.chatStateManager.isFullPageActive && !this.site.mobileView) {
+ if (this.chatStateManager.isFullPageActive && this.site.desktopView) {
return;
}
- return this.router.transitionTo(
- this.chatStateManager.lastKnownChatURL || "chat"
- );
+ if (this.chatStateManager.isFullPageActive && this.site.mobileView) {
+ return this.router.transitionTo("chat");
+ }
+
+ if (this.chatStateManager.isDrawerActive) {
+ return this.router.transitionTo("chat");
+ } else {
+ return this.router.transitionTo(
+ this.chatStateManager.lastKnownChatURL || "chat"
+ );
+ }
},
chatRerenderHeader() {
diff --git a/plugins/chat/spec/system/navigation_spec.rb b/plugins/chat/spec/system/navigation_spec.rb
index 3a4ee506fe9..e0a51aa0fe1 100644
--- a/plugins/chat/spec/system/navigation_spec.rb
+++ b/plugins/chat/spec/system/navigation_spec.rb
@@ -17,6 +17,38 @@ RSpec.describe "Navigation", type: :system, js: true do
sign_in(user)
end
+ context "when clicking chat icon and drawer is viewing channel" do
+ it "navigates to index" do
+ chat_page.open_from_header
+ chat_drawer_page.open_channel(category_channel_2)
+ chat_page.open_from_header
+
+ expect(page).to have_content(I18n.t("js.chat.direct_messages.title"))
+ end
+ end
+
+ context "when clicking chat icon on mobile and is viewing channel" do
+ it "navigates to index" do
+ visit("/chat?mobile_view=1")
+ chat_page.visit_channel(category_channel_2)
+ chat_page.open_from_header
+
+ expect(page).to have_current_path(chat_path)
+ end
+ end
+
+ context "when clicking chat icon on desktop and is viewing channel" do
+ it "stays on channel page" do
+ visit("/chat")
+ chat_page.visit_channel(category_channel_2)
+ chat_page.open_from_header
+
+ expect(page).to have_current_path(
+ chat.channel_path(category_channel_2.id, category_channel_2.slug),
+ )
+ end
+ end
+
context "when visiting /chat" do
it "opens full page" do
chat_page.open