Skip to content

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

UX: Minor chat browse improvements (#41793)

Martin Brennan4c7a4f637f6c
diff --git a/plugins/chat/assets/javascripts/discourse/components/browse-channels.gjs b/plugins/chat/assets/javascripts/discourse/components/browse-channels.gjs
index 33d4277ba89..12a532b3b0e 100644
--- a/plugins/chat/assets/javascripts/discourse/components/browse-channels.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/browse-channels.gjs
@@ -11,6 +11,7 @@ import { INPUT_DELAY } from "discourse/lib/environment";
import { eq } from "discourse/truth-helpers";
import DEmptyState from "discourse/ui-kit/d-empty-state";
import DFilterInput from "discourse/ui-kit/d-filter-input";
+import DSelect from "discourse/ui-kit/d-select";
import { i18n } from "discourse-i18n";
import List from "discourse/plugins/chat/discourse/components/chat/list";
import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message";
@@ -28,11 +29,39 @@ export default class BrowseChannels extends Component {
@service siteSettings;
@tracked filter = "";
+ @tracked selectedJoinedFilter = "all";
get currentTab() {
return this.args.currentTab ?? ALL;
}
+ get joinedFilters() {
+ return [
+ { label: i18n("chat.browse.filter_joined_all"), value: "all" },
+ { label: i18n("chat.browse.filter_joined_joined"), value: "joined" },
+ {
+ label: i18n("chat.browse.filter_joined_not_joined"),
+ value: "not-joined",
+ },
+ ];
+ }
+
+ @action
+ setJoinedFilter(value) {
+ this.selectedJoinedFilter = value;
+ }
+
+ @action
+ filterChannelsByJoined(listItems) {
+ if (this.selectedJoinedFilter === "joined") {
+ return listItems.filter((channel) => channel.isFollowing);
+ } else if (this.selectedJoinedFilter === "not-joined") {
+ return listItems.filter((channel) => !channel.isFollowing);
+ } else {
+ return listItems;
+ }
+ }
+
@cached
get channelsCollection() {
return this.chatApi.channels({
@@ -89,18 +118,34 @@ export default class BrowseChannels extends Component {
</ul>
</nav>
- <DFilterInput
- {{didInsert this.focusFilterInput}}
- @filterAction={{this.setFilter}}
- @icons={{hash right="magnifying-glass"}}
- placeholder={{i18n "chat.browse.filter_input_placeholder"}}
- />
+ <div class="chat-browse-view__filter-controls">
+ <DSelect
+ @value={{this.selectedJoinedFilter}}
+ @onChange={{this.setJoinedFilter}}
+ @includeNone={{false}}
+ class="chat-browse-view__filter-select"
+ as |select|
+ >
+ {{#each this.joinedFilters as |filter|}}
+ <select.Option @value={{filter.value}}>
+ {{filter.label}}
+ </select.Option>
+ {{/each}}
+ </DSelect>
+ <DFilterInput
+ {{didInsert this.focusFilterInput}}
+ @filterAction={{this.setFilter}}
+ @icons={{hash right="magnifying-glass"}}
+ placeholder={{i18n "chat.browse.filter_input_placeholder"}}
+ />
+ </div>
</div>
<div class="chat-browse-view__content_wrapper">
<div class="chat-browse-view__content">
<List
@collection={{this.channelsCollection}}
+ @filterFn={{this.filterChannelsByJoined}}
class="chat-browse-view__cards"
as |list|
>
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-card.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-card.gjs
index e0c7aebcd66..1f0ba20d5ce 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-card.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-card.gjs
@@ -3,6 +3,7 @@ import { LinkTo } from "@ember/routing";
import { trustHTML } from "@ember/template";
import { gt } from "discourse/truth-helpers";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
+import dEmoji from "discourse/ui-kit/helpers/d-emoji";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";
import { i18n } from "discourse-i18n";
@@ -28,6 +29,9 @@ export default <template>
class="chat-channel-card__name-container"
>
<span class="chat-channel-card__name">
+ {{#if @channel.emoji}}
+ {{dEmoji @channel.emoji}}
+ {{/if}}
{{dReplaceEmoji @channel.title}}
</span>
{{#if @channel.chatable.read_restricted}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/list/index.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/list/index.gjs
index 44d08c5ef2b..d6f768fd5f2 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/list/index.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/list/index.gjs
@@ -37,6 +37,17 @@ export default class List extends Component {
return this.args.itemComponent ?? Item;
}
+ get collectionItemsMaybeFiltered() {
+ const collection = this.args.collection;
+ const filterFn = this.args.filterFn;
+
+ if (filterFn) {
+ return filterFn(collection.items);
+ } else {
+ return collection.items;
+ }
+ }
+
@action
loadCollection() {
discourseDebounce(this, this.debouncedLoadCollection, INPUT_DELAY);
@@ -53,7 +64,7 @@ export default class List extends Component {
{{this.fill}}
...attributes
>
- {{#each @collection.items as |item|}}
+ {{#each this.collectionItemsMaybeFiltered as |item|}}
{{yield (hash Item=(component this.itemComponent item=item))}}
{{else}}
{{#if @collection.fetchedOnce}}
diff --git a/plugins/chat/assets/stylesheets/common/chat-browse.scss b/plugins/chat/assets/stylesheets/common/chat-browse.scss
index 27240a91389..b55af045496 100644
--- a/plugins/chat/assets/stylesheets/common/chat-browse.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-browse.scss
@@ -34,15 +34,16 @@
&__actions {
display: flex;
- justify-content: space-between;
- align-items: end;
+ align-items: center;
+ gap: 1rem;
.c-drawer-routes.--browse & {
flex-direction: column;
gap: 1rem;
align-items: flex-start;
- .filter-input {
+ .chat-browse-view__filter-controls,
+ .filter-input-container {
width: 100%;
}
}
@@ -50,15 +51,46 @@
@include viewport.until(md) {
flex-direction: column;
- .filter-input-container {
+ .chat-browse-view__filter-controls {
margin-top: 1rem;
}
+ .chat-browse-view__filter-controls,
.filter-input-container,
nav {
width: 100%;
}
}
+
+ .chat-browse-view__filter-controls {
+ .filter-input,
+ .filter-input:focus {
+ width: 100%;
+ }
+ }
+ }
+
+ &__filter-controls {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ flex: 0 1 32rem;
+ margin-inline-start: auto;
+ min-width: 0;
+
+ .filter-input-container {
+ width: 100%;
+ min-width: 0;
+ }
+
+ @include viewport.until(sm) {
+ flex-direction: column;
+ }
+ }
+
+ &__filter-select,
+ &__filter-controls .filter-input-container {
+ flex: 1 1 0;
}
&__filters {
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index e838a811818..1879ef8c536 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -382,6 +382,9 @@ en:
filter_closed: Closed
filter_archived: Archived
filter_input_placeholder: Search channel by name
+ filter_joined_all: "All"
+ filter_joined_joined: "Joined"
+ filter_joined_not_joined: "Not joined"
chat_message_separator:
today: Today
diff --git a/plugins/chat/lib/chat/channel_fetcher.rb b/plugins/chat/lib/chat/channel_fetcher.rb
index a3ffc9abdd5..e568aef500f 100644
--- a/plugins/chat/lib/chat/channel_fetcher.rb
+++ b/plugins/chat/lib/chat/channel_fetcher.rb
@@ -192,6 +192,7 @@ module Chat
end
else
channels = channels.select("chat_channels.*, #{MATCH_QUALITY_PARTIAL} AS match_quality")
+ channels = channels.order("LOWER(chat_channels.name) ASC")
end
if options.key?(:slugs)
diff --git a/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb b/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb
index 8b99805242c..7dd42f6e9dd 100644
--- a/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb
+++ b/plugins/chat/spec/lib/chat/channel_fetcher_spec.rb
@@ -229,6 +229,16 @@ describe Chat::ChannelFetcher do
).to match_array([category_channel.id])
end
+ it "orders channels by lower-cased name by default" do
+ category_channel.update!(name: "Support")
+ Fabricate(:category_channel, name: "banana")
+ Fabricate(:category_channel, name: "Apple")
+
+ channels = described_class.secured_public_channels(guardian, following: following)
+
+ expect(channels.map(&:name)).to eq(%w[Apple banana Support])
+ end
+
context "with match_quality when filtering" do
fab!(:exact_channel) { Fabricate(:category_channel, name: "dev") }
fab!(:prefix_channel) { Fabricate(:category_channel, name: "devops") }