diff --git a/src/renderer/src/components/Library/ClipCard.vue b/src/renderer/src/components/Library/ClipCard.vue index 75ae18f..b2cce2e 100644 --- a/src/renderer/src/components/Library/ClipCard.vue +++ b/src/renderer/src/components/Library/ClipCard.vue @@ -273,7 +273,11 @@ function handleCardClick(event: MouseEvent) { - + -
+
Published + +
- diff --git a/src/renderer/src/utils/viewCount.ts b/src/renderer/src/utils/viewCount.ts index 75dbe20..adbe53f 100644 --- a/src/renderer/src/utils/viewCount.ts +++ b/src/renderer/src/utils/viewCount.ts @@ -1,7 +1,8 @@ import { pluralize } from './pluralize'; /** - * What a library card says about how often a published clip has been watched. + * How often a published clip has been watched, as the figure on its card's + * chip beside Published: `37`, `1,234`. Empty means the chip is not drawn. * * **Null says nothing.** It means nobody has counted: a publisher older than * the counter, or no sync yet. A number there would be invented. @@ -13,8 +14,14 @@ import { pluralize } from './pluralize'; * * Grouped digits because a clip that went round a Discord can reach four. */ -export function viewCountLabel(views: number | null | undefined): string { +export function viewCountFigure(views: number | null | undefined): string { if (views == null || !Number.isFinite(views) || views <= 0) return ''; - const whole = Math.floor(views); - return `${whole.toLocaleString('en-US')} ${pluralize(whole, 'view')}`; + return Math.floor(views).toLocaleString('en-US'); +} + +/** The same count in words, for a screen reader: the chip itself is an eye and a number. */ +export function viewCountLabel(views: number | null | undefined): string { + const figure = viewCountFigure(views); + if (!figure) return ''; + return `${figure} ${pluralize(Math.floor(views as number), 'view')}`; } diff --git a/tests/unit/renderer/viewCount.spec.ts b/tests/unit/renderer/viewCount.spec.ts index e939766..90276cd 100644 --- a/tests/unit/renderer/viewCount.spec.ts +++ b/tests/unit/renderer/viewCount.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { viewCountLabel } from '../../../src/renderer/src/utils/viewCount'; +import { viewCountFigure, viewCountLabel } from '../../../src/renderer/src/utils/viewCount'; /** * The view count on a library card. @@ -31,3 +31,16 @@ describe('viewCountLabel', () => { expect(viewCountLabel(1234)).toBe('1,234 views'); }); }); + +describe('viewCountFigure', () => { + it('is empty wherever the label is, so the chip and its words agree', () => { + for (const views of [null, undefined, 0, -3, Number.NaN]) { + expect(viewCountFigure(views)).toBe(''); + } + }); + + it('is the grouped number alone', () => { + expect(viewCountFigure(1)).toBe('1'); + expect(viewCountFigure(1234)).toBe('1,234'); + }); +});