Skip to content

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

UX: view count in topic map should always be at least 1 (#28447)

Kris6c159241c977
diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
index 0979302d0d1..189f2a71b4f 100644
--- a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
+++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs
@@ -98,6 +98,10 @@ export default class TopicMapSummary extends Component {
return [this.hasLikes, this.hasUsers, this.hasLinks].every(Boolean);
}
+ get minViewsCount() {
+ return Math.max(this.args.topic.views, 1);
+ }
+
get shouldShowViewsChart() {
return this.views.stats.length > 2;
}
@@ -249,9 +253,9 @@ export default class TopicMapSummary extends Component {
@onShow={{this.fetchViews}}
>
<:trigger>
- {{number @topic.views noTitle="true"}}
+ {{number this.minViewsCount noTitle="true"}}
<span class="topic-map__stat-label">
- {{i18n "views_lowercase" [email protected]}}
+ {{i18n "views_lowercase" count=this.minViewsCount}}
</span>
</:trigger>
<:content>
diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-views.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-views.gjs
index 254a9135964..93e6118d178 100644
--- a/app/assets/javascripts/discourse/app/components/topic-map/topic-views.gjs
+++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-views.gjs
@@ -58,6 +58,11 @@ export default class TopicViews extends Component {
};
});
+ // today should always have at least 1 view
+ // because it's being viewed right now
+ const lastStat = stats[stats.length - 1];
+ lastStat.views = Math.max(lastStat.views, 1);
+
return stats;
}