Commit fc26c2bd authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Show singular 'update' in notification when there's only one

parent fe46a6ce
/**
* Naive simple English pluralization
*/
export function pluralize(count: number, singular: string, plural: string) {
return count === 1 ? singular : plural;
}
import { pluralize } from '../pluralize';
describe('pluralize', () => {
[
{ count: 0, expectedResult: 'people' },
{ count: 1, expectedResult: 'person' },
{ count: 2, expectedResult: 'people' },
{ count: 10, expectedResult: 'people' },
].forEach(({ count, expectedResult }) => {
it('returns expected form', () => {
assert.equal(pluralize(count, 'person', 'people'), expectedResult);
});
});
});
......@@ -2,6 +2,7 @@ import { Button, DownloadIcon } from '@hypothesis/frontend-shared';
import classnames from 'classnames';
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
import { pluralize } from '../../shared/pluralize';
import { useShortcut } from '../../shared/shortcut';
import { withServices } from '../service-context';
import type { StreamerService } from '../services/streamer';
......@@ -74,7 +75,8 @@ function PendingUpdatesNotification({
>
{!collapsed && (
<span data-testid="full-notification" className="whitespace-nowrap">
Load <span className="font-bold">{pendingUpdateCount}</span> updates{' '}
Load <span className="font-bold">{pendingUpdateCount}</span>{' '}
{pluralize(pendingUpdateCount, 'update', 'updates')}{' '}
<span className="sr-only">by pressing l</span>
</span>
)}
......
......@@ -9,6 +9,7 @@ import {
import { useCallback, useId, useMemo, useState } from 'preact/hooks';
import { downloadFile } from '../../../shared/download-file';
import { pluralize } from '../../../shared/pluralize';
import type { APIAnnotationData } from '../../../types/api';
import { annotationDisplayName } from '../../helpers/annotation-user';
import type { UserAnnotations } from '../../helpers/annotations-by-user';
......@@ -256,11 +257,6 @@ function ExportAnnotations({
return <LoadingSpinner />;
}
// Naive simple English pluralization
const pluralize = (count: number, singular: string, plural: string) => {
return count === 1 ? singular : plural;
};
return (
<form
className="space-y-3"
......
......@@ -9,6 +9,7 @@ import {
import classnames from 'classnames';
import type { ComponentChildren } from 'preact';
import { pluralize } from '../../shared/pluralize';
import type { SidebarSettings } from '../../types/config';
import type { TabName } from '../../types/sidebar';
import { applyTheme } from '../helpers/theme';
......@@ -127,11 +128,6 @@ function SidebarTabs({
const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0;
// Naive simple English pluralization
const pluralize = (count: number, singular: string, plural: string) => {
return count === 1 ? singular : plural;
};
const tabCountsSummaryPieces = [];
if (annotationCount > 0) {
const term = pluralize(annotationCount, 'annotation', 'annotations');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment