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

This commit is contained in:
Kris 2024-08-20 17:26:09 -04:00 committed by GitHub
parent 10ae7ef44a
commit 6c159241c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -98,6 +98,10 @@ export default class TopicMapSummary extends Component {
return [this.hasLikes, this.hasUsers, this.hasLinks].every(Boolean); return [this.hasLikes, this.hasUsers, this.hasLinks].every(Boolean);
} }
get minViewsCount() {
return Math.max(this.args.topic.views, 1);
}
get shouldShowViewsChart() { get shouldShowViewsChart() {
return this.views.stats.length > 2; return this.views.stats.length > 2;
} }
@ -249,9 +253,9 @@ export default class TopicMapSummary extends Component {
@onShow={{this.fetchViews}} @onShow={{this.fetchViews}}
> >
<:trigger> <:trigger>
{{number @topic.views noTitle="true"}} {{number this.minViewsCount noTitle="true"}}
<span class="topic-map__stat-label"> <span class="topic-map__stat-label">
{{i18n "views_lowercase" count=@topic.views}} {{i18n "views_lowercase" count=this.minViewsCount}}
</span> </span>
</:trigger> </:trigger>
<:content> <:content>

View File

@ -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; return stats;
} }