A platform for community discussion. Free, open, simple.
UX: Improvements to starred chat channels on mobile and drawer (#36470)
Keegan George39aca6a503f0
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/drawer-routes/channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/drawer-routes/channel.gjsindex f2667820df1..76e5308e95a 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/drawer-routes/channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/drawer-routes/channel.gjs@@ -22,6 +22,10 @@ export default class ChatDrawerRoutesChannel extends Component {get backBtnRoute() {if (this.chatHistory.previousRoute?.name === "chat.browse") {return "chat.browse";+ } else if (+ this.chatHistory.previousRoute?.name === "chat.starred-channels"+ ) {+ return "chat.starred-channels";} else if (this.args.model?.channel?.isDirectMessageChannel) {return "chat.direct-messages";} else {diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjsindex 5f5c1b34a07..17670042c89 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs@@ -10,6 +10,7 @@ export default class ChatRoutesChannel extends Component {@service site;@service siteSettings;@service chat;+ @service chatHistory;@tracked isFiltering = false;@@ -20,9 +21,17 @@ export default class ChatRoutesChannel extends Component {}get getChannelsRoute() {- return this.args.channel.isDirectMessageChannel- ? "chat.direct-messages"- : "chat.channels";+ if (this.chatHistory.previousRoute?.name === "chat.browse") {+ return "chat.browse";+ } else if (+ this.chatHistory.previousRoute?.name === "chat.starred-channels"+ ) {+ return "chat.starred-channels";+ } else if (this.args.channel.isDirectMessageChannel) {+ return "chat.direct-messages";+ } else {+ return "chat.channels";+ }}<template>diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.jsindex 056798d1c89..6162b75ce66 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js@@ -279,6 +279,10 @@ export default class ChatChannelsManager extends Service {);return starredChannels.sort((a, b) => {+ if (a.isDirectMessageChannel !== b.isDirectMessageChannel) {+ return a.isDirectMessageChannel ? 1 : -1;+ }+const aUrgent = this.#getChannelUrgentCount(a);const bUrgent = this.#getChannelUrgentCount(b);diff --git a/plugins/chat/spec/system/drawer/starred_channels_spec.rb b/plugins/chat/spec/system/drawer/starred_channels_spec.rbindex b6a1705ead8..336e07bafae 100644--- a/plugins/chat/spec/system/drawer/starred_channels_spec.rb+++ b/plugins/chat/spec/system/drawer/starred_channels_spec.rb@@ -76,4 +76,84 @@ RSpec.describe "Drawer - starred channels", type: :system doexpect(page).to have_no_css("#c-footer-starred")endend++ context "when user has starred both channels and DMs" do+ fab!(:user_1, :user)+ fab!(:user_2, :user)+ fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }+ fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_2]) }++ before do+ user_1.update!(username: "alice")+ user_2.update!(username: "bob")+ channel_1.membership_for(current_user).update!(starred: true)+ channel_2.membership_for(current_user).update!(starred: true)+ dm_channel_1.membership_for(current_user).update!(starred: true)+ dm_channel_2.membership_for(current_user).update!(starred: true)+ end++ it "shows regular channels before DMs in the starred channels list" do+ visit("/")+ chat_page.open_from_header+ drawer_page.click_starred_channels++ channels = page.all(".chat-channel-row")+ expect(channels[0]["data-chat-channel-id"]).to eq(channel_1.id.to_s)+ expect(channels[1]["data-chat-channel-id"]).to eq(channel_2.id.to_s)+ expect(channels[2]["data-chat-channel-id"]).to eq(dm_channel_1.id.to_s)+ expect(channels[3]["data-chat-channel-id"]).to eq(dm_channel_2.id.to_s)+ end++ it "shows regular channels with unreads before DMs with unreads" do+ Fabricate(:chat_message, chat_channel: channel_2, user: user_1)+ Fabricate(:chat_message, chat_channel: dm_channel_1, user: user_1)+ channel_2.membership_for(current_user).update!(last_viewed_at: 1.minute.ago)+ dm_channel_1.membership_for(current_user).update!(last_viewed_at: 1.minute.ago)++ visit("/")+ chat_page.open_from_header+ drawer_page.click_starred_channels++ channels = page.all(".chat-channel-row")+ expect(channels[0]["data-chat-channel-id"]).to eq(channel_2.id.to_s)+ expect(channels[1]["data-chat-channel-id"]).to eq(channel_1.id.to_s)+ expect(channels[2]["data-chat-channel-id"]).to eq(dm_channel_1.id.to_s)+ expect(channels[3]["data-chat-channel-id"]).to eq(dm_channel_2.id.to_s)+ end+ end++ context "when navigating from starred channels tab" do+ fab!(:user_1, :user)+ fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }++ before do+ channel_1.membership_for(current_user).update!(starred: true)+ channel_2.membership_for(current_user).update!(starred: true)+ dm_channel_1.membership_for(current_user).update!(starred: true)+ end++ it "returns to starred channels tab when clicking back from a regular channel" do+ visit("/")+ chat_page.open_from_header+ drawer_page.click_starred_channels++ find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click+ expect(drawer_page).to have_open_channel(channel_1)++ find(".c-navbar__back-button").click+ expect(drawer_page).to have_open_starred_channels+ end++ it "returns to starred channels tab when clicking back from a DM" do+ visit("/")+ chat_page.open_from_header+ drawer_page.click_starred_channels++ find(".chat-channel-row[data-chat-channel-id='#{dm_channel_1.id}']").click+ expect(drawer_page).to have_open_channel(dm_channel_1)++ find(".c-navbar__back-button").click+ expect(drawer_page).to have_open_starred_channels+ end+ endenddiff --git a/plugins/chat/spec/system/starred_channels_spec.rb b/plugins/chat/spec/system/starred_channels_spec.rbindex 8b49f99cf2e..26047540b6e 100644--- a/plugins/chat/spec/system/starred_channels_spec.rb+++ b/plugins/chat/spec/system/starred_channels_spec.rb@@ -368,4 +368,45 @@ RSpec.describe "Starred channels", type: :system do)endend++ context "when navigating from starred channels on mobile", mobile: true do+ fab!(:user_1, :user)+ fab!(:channel_1) { Fabricate(:category_channel, name: "Channel A") }+ fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }++ before do+ channel_1.add(current_user)+ channel_1.membership_for(current_user).update!(starred: true)+ dm_channel_1.membership_for(current_user).update!(starred: true)+ end++ it "returns to starred channels when clicking back from a regular channel" do+ visit("/")+ chat_page.open_from_header++ expect(page).to have_css("#c-footer-starred")+ find("#c-footer-starred").click+ expect(page).to have_current_path("/chat/starred-channels")++ find(".chat-channel-row[data-chat-channel-id='#{channel_1.id}']").click+ expect(page).to have_current_path(%r{/chat/c/.*/#{channel_1.id}})++ find(".c-navbar__back-button").click+ expect(page).to have_current_path("/chat/starred-channels")+ end++ it "returns to starred channels when clicking back from a DM" do+ visit("/")+ chat_page.open_from_header++ find("#c-footer-starred").click+ expect(page).to have_current_path("/chat/starred-channels")++ find(".chat-channel-row[data-chat-channel-id='#{dm_channel_1.id}']").click+ expect(page).to have_current_path(%r{/chat/c/.*/#{dm_channel_1.id}})++ find(".c-navbar__back-button").click+ expect(page).to have_current_path("/chat/starred-channels")+ end+ endend