Skip to content

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

UX: Switch My Posts link in sidebar to My Drafts when drafts are present (#20491)

Osama Sayegh82a84241ca6b
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js
index 82fceb4bd0e..4ff88f4cd9c 100644
--- a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js
+++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js
@@ -55,10 +55,17 @@ export default class MyPostsSectionLink extends BaseSectionLink {
}
get text() {
- return I18n.t("sidebar.sections.community.links.my_posts.content");
+ if (this._hasDraft && this.currentUser?.new_new_view_enabled) {
+ return I18n.t("sidebar.sections.community.links.my_posts.content_drafts");
+ } else {
+ return I18n.t("sidebar.sections.community.links.my_posts.content");
+ }
}
get badgeText() {
+ if (this._hasDraft && this.currentUser?.new_new_view_enabled) {
+ return this.draftCount.toString();
+ }
if (this._hasDraft && !this.hideCount) {
return I18n.t("sidebar.sections.community.links.my_posts.draft_count", {
count: this.draftCount,
@@ -71,6 +78,9 @@ export default class MyPostsSectionLink extends BaseSectionLink {
}
get prefixValue() {
+ if (this._hasDraft && this.currentUser?.new_new_view_enabled) {
+ return "pencil-alt";
+ }
return "user";
}
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js
index 41756649fe8..d032ca38351 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js
@@ -583,6 +583,39 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
);
});
+ test("my posts changes its text when drafts are present and new new view experiment is enabled", async function (assert) {
+ updateCurrentUser({
+ sidebar_list_destination: "unread_new",
+ new_new_view_enabled: true,
+ });
+ await visit("/");
+
+ assert.strictEqual(
+ query(".sidebar-section-link-my-posts").textContent.trim(),
+ I18n.t("sidebar.sections.community.links.my_posts.content"),
+ "displays the default text when no drafts are present"
+ );
+
+ await publishToMessageBus(`/user-drafts/${loggedInUser().id}`, {
+ draft_count: 1,
+ });
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-my-posts .sidebar-section-link-content-text"
+ ).textContent.trim(),
+ I18n.t("sidebar.sections.community.links.my_posts.content_drafts"),
+ "displays the text that's appropriate for when drafts are present"
+ );
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-my-posts .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "1",
+ "displays the draft count with no text"
+ );
+ });
+
test("visiting top route", async function (assert) {
await visit("/top");
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 1ddf02dd2d2..2fcce585138 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4438,6 +4438,7 @@ en:
title: "List of all users"
my_posts:
content: "My Posts"
+ content_drafts: "My Drafts"
title: "My recent topic activity"
title_drafts: "My unposted drafts"
draft_count: