feat(app): search, sort and date format of the admin sheet list

This commit is contained in:
bchanot committed 2026-11-16 16:45:23 +01:00
1 parent d5852f5f8e
commit f3b58abe70
5 files changed
+121 -5

No files matched your search

+21
View File
@@ -5,6 +5,7 @@ import type {
SheetFailureKind,
} from '@faunosteo/supabase'
import type { Locale } from '@/i18n/types'
import { PARIS_TIME_ZONE } from '@/lib/dates'
type Translate = (key: string) => string
@@ -104,6 +105,26 @@ export function formatDay(
})
}
function shortDateTime(tag: string): Intl.DateTimeFormat {
return new Intl.DateTimeFormat(tag, {
day: 'numeric',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
timeZone: PARIS_TIME_ZONE,
})
}
const SHORT_DATE_TIME: Record<Locale, Intl.DateTimeFormat> = {
fr: shortDateTime('fr-FR'),
en: shortDateTime('en-GB'),
}
/** « 9 nov. 2026, 12:06 » / « 9 Nov 2026, 12:06 », in Paris time (A8). */
export function formatShortParisDateTime(iso: string, locale: Locale): string {
return SHORT_DATE_TIME[locale].format(new Date(iso))
}
/**
* The round's state (§3). A failed verification names its cause only when
* the server recorded one (`failure_outcome`, BDR-095): the title of that
+38
View File
@@ -0,0 +1,38 @@
import type { OfficialSheetAdminSummary } from '@faunosteo/supabase'
import { matchesSheetName } from '@/catalogue/useCatalogue'
import type { Locale } from '@/i18n/types'
// shortcut: search and sort run in the browser on the whole list; they move to
// the server with the list's paging (RR-13, TODO.md).
/** The display orders of the admin list; `modified` is the default (D7). */
export const SHEET_SORTS = ['modified', 'name'] as const
export type SheetSort = (typeof SHEET_SORTS)[number]
type Sheet = OfficialSheetAdminSummary
/** Search on the sheet name only, as the catalogue does (D7). */
export function searchSheets(sheets: readonly Sheet[], query: string): Sheet[] {
return sheets.filter((sheet) => matchesSheetName(sheet.name, query))
}
/**
* Display order only: a new array, the input untouched. `modified` puts the
* newest `last_modified_at` first; equal dates, and `name`, follow the name in
* the interface language, then the id, so the order never depends on the
* server's.
*/
export function sortSheets(
sheets: readonly Sheet[],
sort: SheetSort,
locale: Locale,
): Sheet[] {
const collator = new Intl.Collator(locale, { sensitivity: 'base', numeric: true })
const time = (sheet: Sheet) => Date.parse(sheet.last_modified_at)
const byName = (a: Sheet, b: Sheet) =>
collator.compare(a.name[locale], b.name[locale]) ||
a.sheet_id.localeCompare(b.sheet_id)
return [...sheets].sort(
(a, b) => (sort === 'modified' ? time(b) - time(a) : 0) || byName(a, b),
)
}