A platform for community discussion. Free, open, simple.
UX: add all topics link to category cards (#43830)
Kris7f9c3bcfd5c8
diff --git a/app/assets/stylesheets/common/components/category-card.scss b/app/assets/stylesheets/common/components/category-card.scssindex 8986e02f760..088f97e6925 100644--- a/app/assets/stylesheets/common/components/category-card.scss+++ b/app/assets/stylesheets/common/components/category-card.scss@@ -83,7 +83,6 @@display: inline-flex;align-items: center;gap: var(--space-half);- color: var(--primary-medium);font-size: var(--font-down-1);.d-icon {@@ -107,6 +106,13 @@font-size: var(--font-down-1);}+ &__view-all {+ display: block;+ padding-top: var(--space-1);+ border-top: 1px solid var(--content-border-color);+ font-size: var(--font-down-1);+ }+&__topics {display: flex;flex-direction: column;diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 0d53de3f05d..8b239a85e24 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5572,6 +5572,7 @@ en:no_description: "Please add a description for this category."change_in_category_topic: "Edit description"latest_topics: "Latest topics"+ view_all_topics: "View all topics (%{number})"description_updated: "Description updated"description_expand: "Show more"description_collapse: "Show less"diff --git a/frontend/discourse/app/components/category-card-contents.gjs b/frontend/discourse/app/components/category-card-contents.gjsindex dc9f14f775a..942ba408545 100644--- a/frontend/discourse/app/components/category-card-contents.gjs+++ b/frontend/discourse/app/components/category-card-contents.gjs@@ -11,6 +11,7 @@ import FeaturedTopic from "discourse/components/topic-list/featured-topic";import categoryVariables from "discourse/helpers/category-variables";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";+import { number } from "discourse/lib/formatter";import { wantsNewWindow } from "discourse/lib/intercept-click";import { applyValueTransformer } from "discourse/lib/transformer";import DiscourseURL from "discourse/lib/url";@@ -125,6 +126,16 @@ export default class CategoryCardContents extends CardContentsBase {);}+ @computed("category.totalTopicCount")+ get topicCount() {+ return this.category?.totalTopicCount ?? 0;+ }++ @computed("topicCount")+ get showViewAll() {+ return this.topicCount > LATEST_TOPICS_COUNT;+ }+didInsertElement() {super.didInsertElement(...arguments);this.appEvents.on("dom:clean", this, this._close);@@ -357,6 +368,14 @@ export default class CategoryCardContents extends CardContentsBase {<li><FeaturedTopic @topic={{topic}} /></li>{{/each}}</ul>+ {{#if this.showViewAll}}+ <a class="category-card__view-all" href={{this.category.url}}>+ {{i18n+ "category.view_all_topics"+ number=(number this.topicCount)+ }}+ </a>+ {{/if}}</div>{{else if (eq this.latestTopics null)}}<DSkeleton class="card-row category-card__latest" @count={{3}} />diff --git a/frontend/discourse/tests/integration/components/category-card-contents-test.gjs b/frontend/discourse/tests/integration/components/category-card-contents-test.gjsindex c1c29583aad..c6f4ad18d82 100644--- a/frontend/discourse/tests/integration/components/category-card-contents-test.gjs+++ b/frontend/discourse/tests/integration/components/category-card-contents-test.gjs@@ -422,6 +422,7 @@ module("Integration | Component | CategoryCardContents", function (hooks) {id: 12355,name: "Busy",slug: "busy",+ topic_count: 1234,topic_url: "/t/about-the-busy-category/700",},],@@ -485,6 +486,10 @@ module("Integration | Component | CategoryCardContents", function (hooks) {"About the Busy category","leaves out the about topic");+ assert+ .dom(".category-card__view-all")+ .hasAttribute("href", "/c/busy/12355")+ .hasText("View all topics (1.2k)");assert.strictEqual(latestRequests[0]?.per_page,"4",@@ -499,6 +504,52 @@ module("Integration | Component | CategoryCardContents", function (hooks) {.exists({ count: 2 }, "the reopened card lists the topics");assert.strictEqual(latestRequests.length, 1, "the list is cached");});++ test("omits the view all link when every topic is already listed", async function (assert) {+ this.site.set("lazy_load_categories", true);++ pretender.get("/categories/find", () =>+ response({+ categories: [+ { id: 12356, name: "Quiet", slug: "quiet", topic_count: 3 },+ ],+ })+ );+ pretender.get("/c/quiet/12356/l/latest.json", () =>+ response({+ topic_list: {+ topics: [+ {+ id: 801,+ slug: "only-topic",+ fancy_title: "Only topic",+ bumped_at: "2026-09-01T00:00:00.000Z",+ posters: [],+ },+ ],+ },+ })+ );++ await render(+ <template>+ <div id="main-outlet">+ <a+ class="hashtag-cooked"+ data-id="12356"+ data-type="category"+ href="/c/quiet/12356"+ >#quiet</a>+ </div>+ <CategoryCardContents />+ </template>+ );++ await click('a.hashtag-cooked[data-type="category"]');++ assert.dom(".category-card__topics .featured-topic").exists({ count: 1 });+ assert.dom(".category-card__view-all").doesNotExist();+ });});module(