Skip to content

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

UX: Chat channel empty and not yet joined state redesigns (#41737)

chapoi8759c7f5b9f5
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-preview-card.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-preview-card.gjs
index 25aab0331c9..813f631c5f5 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-preview-card.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-preview-card.gjs
@@ -1,37 +1,107 @@
import Component from "@glimmer/component";
import { hash } from "@ember/helper";
-import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
+import { action } from "@ember/object";
+import { getOwner } from "@ember/owner";
+import { service } from "@ember/service";
+import DButton from "discourse/ui-kit/d-button";
+import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
import ToggleChannelMembershipButton from "./toggle-channel-membership-button";
export default class ChatChannelPreviewCard extends Component {
+ @service currentUser;
+
get showJoinButton() {
return this.args.channel?.isOpen && this.args.channel?.canJoin;
}
- get channelPlaceholder() {
- return i18n("chat.placeholder_channel", {
+ get guestTitle() {
+ return i18n("chat.channel.preview_card.guest_title", {
+ channelName: `#${this.args.channel.title}`,
+ });
+ }
+
+ get noAccessTitle() {
+ return i18n("chat.channel.preview_card.no_access_title", {
channelName: `#${this.args.channel.title}`,
});
}
+ @action
+ showLogin() {
+ getOwner(this).lookup("route:application").send("showLogin");
+ }
+
+ @action
+ showCreateAccount() {
+ getOwner(this).lookup("route:application").send("showCreateAccount");
+ }
+
<template>
- <div
- class={{dConcatClass
- "chat-channel-preview-card"
- (unless this.showJoinButton "-no-button")
- }}
- >
+ {{#if this.currentUser}}
{{#if this.showJoinButton}}
- <div class="chat-channel__placeholder">
- {{this.channelPlaceholder}}
+ <div class="chat-channel-preview-card --logged-in">
+ <div class="chat-channel-preview-card__icon">
+ {{dIcon "lock"}}
+ </div>
+
+ <div class="chat-channel-preview-card__title">
+ {{this.guestTitle}}
+ </div>
+
+ <div class="chat-channel-preview-card__body">
+ {{i18n "chat.channel.preview_card.join_body"}}
+ </div>
+
+ <div class="chat-channel-preview-card__actions">
+ <ToggleChannelMembershipButton
+ @channel={{@channel}}
+ @options={{hash joinClass="btn-primary" labelType="short"}}
+ />
+ </div>
</div>
+ {{else}}
+ <div class="chat-channel-preview-card --logged-in --no-access">
+ <div class="chat-channel-preview-card__icon">
+ {{dIcon "lock"}}
+ </div>
+
+ <div class="chat-channel-preview-card__title">
+ {{this.noAccessTitle}}
+ </div>
- <ToggleChannelMembershipButton
- @channel={{@channel}}
- @options={{hash joinClass="btn-primary" labelType="short"}}
- />
+ <div class="chat-channel-preview-card__body">
+ {{i18n "chat.channel.preview_card.no_access_body"}}
+ </div>
+ </div>
{{/if}}
- </div>
+ {{else}}
+ <div class="chat-channel-preview-card --anon">
+ <div class="chat-channel-preview-card__icon">
+ {{dIcon "lock"}}
+ </div>
+
+ <div class="chat-channel-preview-card__title">
+ {{this.guestTitle}}
+ </div>
+
+ <div class="chat-channel-preview-card__body">
+ {{i18n "chat.channel.preview_card.guest_body"}}
+ </div>
+
+ <div class="chat-channel-preview-card__actions">
+ <DButton
+ @action={{this.showLogin}}
+ @label="chat.channel.preview_card.log_in"
+ class="btn-transparent --primary"
+ />
+ <DButton
+ @action={{this.showCreateAccount}}
+ @label="chat.channel.preview_card.sign_up"
+ class="btn-primary"
+ />
+ </div>
+ </div>
+ {{/if}}
</template>
}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
index 64a0c0e43a2..86de3008dbb 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs
@@ -32,6 +32,7 @@ import {
scrollListToMessage,
} from "discourse/plugins/chat/discourse/lib/scroll-helpers";
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
+import ChatChannelEmptyState from "./chat/channel/empty-state";
import ChatComposerChannel from "./chat/composer/channel";
import ChatScrollToBottomArrow from "./chat/scroll-to-bottom-arrow";
import ChatSelectionManager from "./chat/selection-manager";
@@ -88,6 +89,13 @@ export default class ChatChannel extends Component {
return this.args.channel.messagesManager;
}
+ get isEmpty() {
+ return (
+ this.messagesLoader.fetchedOnce &&
+ this.messagesManager.messages.length === 0
+ );
+ }
+
get currentUserMembership() {
return this.args.channel?.currentUserMembership;
}
@@ -751,6 +759,7 @@ export default class ChatChannel extends Component {
(if this.pane.sending "chat-channel--sending")
(if this.hasSavedScrollPosition "chat-channel--saved-scroll-position")
(if this.messagesLoader.fetchedOnce "--loaded")
+ (if this.isEmpty "is-empty")
}}
{{willDestroy this.teardown}}
{{didInsert this.setup}}
@@ -782,14 +791,20 @@ export default class ChatChannel extends Component {
@context="channel"
/>
{{else}}
- {{#unless this.messagesLoader.fetchedOnce}}
+ {{#if this.messagesLoader.fetchedOnce}}
+ <ChatChannelEmptyState @channel={{@channel}} />
+ {{else}}
<ChatSkeleton />
- {{/unless}}
+ {{/if}}
{{/each}}
</ChatMessagesContainer>
{{! at bottom even if shown at top due to column-reverse }}
- {{#if this.messagesLoader.loadedPast}}
+ {{#if
+ (and
+ this.messagesLoader.loadedPast this.messagesManager.messages.length
+ )
+ }}
<div class="all-loaded-message">
{{i18n "chat.all_loaded"}}
</div>
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/channel/empty-state.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/channel/empty-state.gjs
new file mode 100644
index 00000000000..4b317c88b44
--- /dev/null
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/channel/empty-state.gjs
@@ -0,0 +1,147 @@
+import Component from "@glimmer/component";
+import { cached } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import didInsert from "@ember/render-modifiers/modifiers/did-insert";
+import { service } from "@ember/service";
+import { trustHTML } from "@ember/template";
+import DEmptyState from "discourse/ui-kit/d-empty-state";
+import dAvatar from "discourse/ui-kit/helpers/d-avatar";
+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
+import dIcon from "discourse/ui-kit/helpers/d-icon";
+import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";
+import { i18n } from "discourse-i18n";
+
+const MAX_AVATARS = 5;
+
+export default class ChatChannelEmptyState extends Component {
+ @service chatApi;
+ @service currentUser;
+
+ @cached
+ get memberships() {
+ return this.chatApi.listChannelMemberships(this.args.channel.id);
+ }
+
+ @action
+ loadMemberships() {
+ if (!this.currentUser || !this.memberCount) {
+ return;
+ }
+
+ this.memberships.load({ limit: MAX_AVATARS }).catch(() => {});
+ }
+
+ get otherMemberships() {
+ return this.memberships.items.filter(
+ (membership) => membership.user.id !== this.currentUser?.id
+ );
+ }
+
+ get memberCount() {
+ const total = this.args.channel.membershipsCount ?? 0;
+ const count = this.args.channel.isFollowing ? total - 1 : total;
+ return Math.max(0, count);
+ }
+
+ get channelIcon() {
+ const { emoji, chatable } = this.args.channel;
+ const icon = emoji ? dReplaceEmoji(`:${emoji}:`) : dIcon("d-chat");
+
+ if (!chatable?.color) {
+ return icon;
+ }
+
+ return trustHTML(`<span style="color: #${chatable.color}">${icon}</span>`);
+ }
+
+ get title() {
+ const channelName = `#${this.args.channel.title}`;
+
+ if (this.args.channel.isFollowing) {
+ return i18n("chat.channel.empty_state.joined_title", { channelName });
+ }
+
+ return i18n("chat.channel.empty_state.title", { channelName });
+ }
+
+ get tip() {
+ if (this.args.channel.isFollowing) {
+ return i18n("chat.channel.empty_state.joined_tip");
+ }
+
+ return i18n("chat.channel.empty_state.guest_tip");
+ }
+
+ <template>
+ {{#if this.currentUser}}
+ <DEmptyState
+ @identifier="chat-channel"
+ @svgContent={{this.channelIcon}}
+ @title={{this.title}}
+ @body={{@channel.description}}
+ >
+ <:tip>
+ {{#if this.tip}}
+ <p class="empty-state__tip-text">{{this.tip}}</p>
+ {{/if}}
+
+ <div
+ class={{dConcatClass
+ "empty-state__members-facepile"
+ (if this.otherMemberships.length "--with-avatars")
+ }}
+ {{didInsert this.loadMemberships}}
+ >
+ {{#if this.otherMemberships.length}}
+ <div class="empty-state__members-avatars">
+ {{#each this.otherMemberships as |membership|}}
+ {{dAvatar membership.user imageSize="small"}}
+ {{/each}}
+ </div>
+ {{/if}}
+ <span class="empty-state__members-count">
+ {{#if this.memberCount}}
+ {{trustHTML
+ (i18n
+ "chat.channel.empty_state.members_here"
+ count=this.memberCount
+ )
+ }}
+ {{else}}
+ {{i18n "chat.channel.empty_state.no_other_members"}}
+ {{/if}}
+ </span>
+ </div>
+ </:tip>
+ </DEmptyState>
+ {{/if}}
+ {{#unless this.currentUser}}
+ <DEmptyState
+ @identifier="chat-channel"
+ @svgContent={{this.channelIcon}}
+ @title={{this.title}}
+ @body={{@channel.description}}
+ >
+ <:tip>
+ {{#if this.tip}}
+ <p class="empty-state__tip-text">{{this.tip}}</p>
+ {{/if}}
+ <div class="empty-state__members-facepile">
+ <span class="empty-state__members-count">
+ {{#if this.memberCount}}
+ {{trustHTML
+ (i18n
+ "chat.channel.empty_state.members_here"
+ count=this.memberCount
+ )
+ }}
+ {{else}}
+ {{i18n "chat.channel.empty_state.no_other_members"}}
+ {{/if}}
+ </span>
+ </div>
+ </:tip>
+ </DEmptyState>
+ {{/unless}}
+ </template>
+}
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-empty-state.scss b/plugins/chat/assets/stylesheets/common/chat-channel-empty-state.scss
new file mode 100644
index 00000000000..f22dfe6e33d
--- /dev/null
+++ b/plugins/chat/assets/stylesheets/common/chat-channel-empty-state.scss
@@ -0,0 +1,81 @@
+.chat-channel {
+ &.is-empty .chat-messages-scroller {
+ justify-content: center;
+ }
+
+ .empty-state {
+ max-width: 60ch;
+ display: flex;
+ flex-direction: column;
+ padding: var(--space-4);
+ margin-inline: auto;
+
+ &__image {
+ margin-top: 0; // specific chat overrule for default Emptystate component
+
+ svg,
+ img {
+ width: 4rem;
+ height: 4rem;
+ margin-bottom: var(--space-4);
+ }
+ }
+
+ &__title {
+ font-size: var(--font-up-3);
+ font-weight: 700;
+ }
+
+ &__body {
+ color: var(--primary-high);
+ }
+
+ &__tip {
+ position: relative; // overrule for core component being pos abs
+ bottom: 0; // overrule for core component being pos abs
+ margin: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: var(--space-3);
+ }
+
+ &__tip-text {
+ margin: 0;
+ color: var(--primary-medium);
+ }
+
+ &__members-facepile {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-2);
+ padding: var(--space-1) var(--space-3);
+ border: 1px solid var(--primary-low);
+ border-radius: var(--d-border-radius-pill);
+
+ &.--with-avatars {
+ padding-inline-start: var(--space-1);
+ }
+ }
+
+ &__members-avatars {
+ display: flex;
+
+ .avatar {
+ border: 2px solid var(--secondary);
+
+ &:not(:first-child) {
+ margin-inline-start: -8px;
+ }
+ }
+ }
+
+ &__members-count {
+ font-size: var(--font-down-1-rem);
+
+ strong {
+ color: var(--primary-high);
+ }
+ }
+ }
+}
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss b/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
index 7bf4c5854f4..ae947e28048 100644
--- a/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
@@ -1,17 +1,103 @@
+@use "lib/viewport";
+
.chat-channel-preview-card {
- padding: 0.5rem;
- display: flex;
- flex-direction: row;
+ display: grid;
+ grid-template-columns: auto 1fr auto;
+ grid-template-areas:
+ "icon title title"
+ ". body body"
+ "actions actions actions";
align-items: center;
- justify-content: space-between;
- z-index: 3;
- border: 1px solid var(--d-chat-input-border-color);
- background-color: var(--d-chat-input-bg-color);
+ gap: var(--space-2) var(--space-3);
+ padding: var(--space-4);
+ border: 1px solid var(--tertiary-medium);
+ background: rgb(var(--tertiary-rgb), 0.075);
+ box-shadow: var(--shadow-card);
border-radius: var(--d-border-radius-large);
- margin: 1rem;
- margin-top: 0.25rem;
+ margin: var(--space-4) auto;
+ margin-top: var(--space-1);
+ width: max-content;
+ min-width: 60%;
+ box-sizing: border-box;
+
+ &.--no-access {
+ grid-template-columns: auto 1fr;
+ grid-template-areas:
+ "icon title"
+ "body body";
+ }
+
+ @include viewport.from(sm) {
+ grid-template-areas:
+ "icon title actions"
+ "icon body actions";
+
+ &.--no-access {
+ grid-template-areas:
+ "icon title"
+ "icon body";
+ }
+ }
+
+ .chat-drawer & {
+ margin-inline: var(--space-4);
+ max-width: calc(100% - var(--space-8));
+ }
+
+ .full-page-chat & {
+ @include viewport.until(sm) {
+ margin-inline: var(--space-4);
+ max-width: calc(100% - var(--space-8));
+ }
+ }
+
+ &__icon {
+ grid-area: icon;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex: 0 0 auto;
+ border-radius: 50%;
+ background-color: var(--tertiary);
+ color: var(--secondary);
+ width: 2.5rem;
+ height: 2.5rem;
- .chat-channel__placeholder {
+ @include viewport.until(sm) {
+ width: 2rem;
+ height: 2rem;
+ }
+ }
+
+ &__title {
+ grid-area: title;
+ font-weight: 700;
+ }
+
+ &__body {
+ grid-area: body;
color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
+ &__actions {
+ grid-area: actions;
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+
+ @include viewport.until(sm) {
+ margin-top: var(--space-2);
+ }
+
+ .chat-channel-preview-card.--anon & {
+ justify-content: flex-end;
+ }
+ }
+
+ .toggle-channel-membership-button {
+ @include viewport.until(sm) {
+ width: 100%;
+ }
}
}
diff --git a/plugins/chat/assets/stylesheets/common/index.scss b/plugins/chat/assets/stylesheets/common/index.scss
index 6650c659d44..6d2b7e03748 100644
--- a/plugins/chat/assets/stylesheets/common/index.scss
+++ b/plugins/chat/assets/stylesheets/common/index.scss
@@ -6,6 +6,7 @@
@import "chat-sidebar";
@import "chat-channel";
@import "chat-channel-card";
+@import "chat-channel-empty-state";
@import "chat-channel-icon";
@import "chat-channel-info";
@import "chat-channel-name";
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index fcde0c259ad..15bcee3bbd8 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -461,6 +461,23 @@ en:
memberships_count:
one: "%{count} member"
other: "%{count} members"
+ empty_state:
+ title: "This is the start of %{channelName}"
+ joined_title: "You're the first in %{channelName}"
+ guest_tip: "You're reading along as a guest. The conversation starts the moment members post — join in to be one of them."
+ joined_tip: "Be the first to post and start the conversation."
+ members_here:
+ one: "<strong>%{count} member</strong> here"
+ other: "<strong>%{count} members</strong> here"
+ no_other_members: "No other members yet"
+ preview_card:
+ guest_title: "Join %{channelName} to start chatting"
+ guest_body: "Reading is free for everyone. Sign up to post, react, and reply — it takes about 30 seconds."
+ join_body: "You'll be able to post and reply, and it'll show up in your channel list."
+ no_access_title: "You can't join %{channelName}"
+ no_access_body: "This channel isn't open to new members right now."
+ log_in: "Log in"
+ sign_up: "Sign up"
create_channel:
threading:
diff --git a/plugins/chat/spec/system/anonymous_public_channels_spec.rb b/plugins/chat/spec/system/anonymous_public_channels_spec.rb
index cdd79bab791..74ffd2513a3 100644
--- a/plugins/chat/spec/system/anonymous_public_channels_spec.rb
+++ b/plugins/chat/spec/system/anonymous_public_channels_spec.rb
@@ -37,12 +37,12 @@ RSpec.describe "Anonymous public chat channels" do
id: existing_message.id,
text: "Existing public channel update",
)
- expect(channel_page).to have_join_channel_button
+ expect(channel_page).to have_anonymous_preview_card
expect(channel_page).to have_no_composer
expect(channel_page).to have_no_search_button
expect(channel_page).to have_no_star_button
- channel_page.join_channel
+ channel_page.click_preview_card_login
expect(login_page).to be_open
end
@@ -60,7 +60,7 @@ RSpec.describe "Anonymous public chat channels" do
expect(chat_drawer_page).to have_open_channel(public_channel)
- chat_drawer_page.join_channel
+ chat_drawer_page.click_preview_card_login
expect(login_page).to be_open
end
diff --git a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
index 732531e3fd8..237f664858b 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb
@@ -52,6 +52,13 @@ module PageObjects
find(".toggle-channel-membership-button.-join").click
end
+ def click_preview_card_login
+ find(
+ ".chat-channel-preview-card .btn",
+ text: I18n.t("js.chat.channel.preview_card.log_in"),
+ ).click
+ end
+
def message_by_id_selector(id)
".chat-channel .chat-messages-container .chat-message-container[data-id=\"#{id}\"]"
end
@@ -239,6 +246,10 @@ module PageObjects
has_css?(".toggle-channel-membership-button.-join")
end
+ def has_anonymous_preview_card?
+ has_css?(".chat-channel-preview-card.--anon")
+ end
+
def has_no_composer?
has_no_css?(".chat-composer")
end
diff --git a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
index 91972a977cb..f6d23464a35 100644
--- a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
+++ b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
@@ -70,6 +70,13 @@ module PageObjects
find("#{VISIBLE_DRAWER} .toggle-channel-membership-button.-join").click
end
+ def click_preview_card_login
+ find(
+ "#{VISIBLE_DRAWER} .chat-channel-preview-card .btn",
+ text: I18n.t("js.chat.channel.preview_card.log_in"),
+ ).click
+ end
+
def open_channel_row(channel)
find("#{VISIBLE_DRAWER} .chat-channel-row[data-chat-channel-id='#{channel.id}']").click
has_no_css?(".chat-skeleton")
diff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rb
index 4fd2fd5f668..d2c5891148d 100644
--- a/plugins/chat/spec/system/visit_channel_spec.rb
+++ b/plugins/chat/spec/system/visit_channel_spec.rb
@@ -152,7 +152,7 @@ RSpec.describe "Visit channel" do
it "allows to join it" do
chat.visit_thread(thread)
- expect(page).to have_content(I18n.t("js.chat.channel_settings.join"), count: 2)
+ expect(page).to have_css(".toggle-channel-membership-button.-join", count: 2)
end
end
end