refactor(app): sheet list hooks split, rows memoised, phone clear button
- useSearch holds the query, its field and clearSearch; useListView keeps the filters and the sort (8 bindings down to 5) - the search term is folded once per search (sheetNameMatcher beside matchesSheetName, whose signature and behaviour stay), each date read once before the sort, the shown rows memoised on list, filters, search, sort and language - long className strings hoisted into module constants, no class changed - the no-result block's clear button takes the page's 44 px phone height - labels.ts: the SheetSummary alias removed; ResultsProps declared first No test changed: the existing unit suites are the oracle.
This commit is contained in:
1 parent
374e300895
commit
1758276087
4 files changed
+99
-53
No files matched your search
@@ -126,10 +126,11 @@ export function formatShortParisDateTime(iso: string, locale: Locale): string {
|
||||
return SHORT_DATE_TIME[locale].format(new Date(iso))
|
||||
}
|
||||
|
||||
type SheetSummary = OfficialSheetAdminSummary
|
||||
|
||||
/** « version publiée 3 » or « aucune version publiée », then « brouillon version 4 » if any. */
|
||||
function versionParts(t: Translate, sheet: SheetSummary): string[] {
|
||||
function versionParts(
|
||||
t: Translate,
|
||||
sheet: OfficialSheetAdminSummary,
|
||||
): string[] {
|
||||
const number = (key: string, value: number) =>
|
||||
t(key).replace('{number}', String(value))
|
||||
const current = sheet.current_version
|
||||
@@ -145,7 +146,7 @@ function versionParts(t: Translate, sheet: SheetSummary): string[] {
|
||||
}
|
||||
|
||||
/** « revue n° 2 : À relire » when the sheet has a round. */
|
||||
function roundPart(t: Translate, sheet: SheetSummary): string[] {
|
||||
function roundPart(t: Translate, sheet: OfficialSheetAdminSummary): string[] {
|
||||
if (!sheet.latest_round) return []
|
||||
return [
|
||||
t('admin.sheets.latest_round')
|
||||
@@ -157,7 +158,7 @@ function roundPart(t: Translate, sheet: SheetSummary): string[] {
|
||||
/** The detail line of a sheet row: « Cheval · Active · version publiée 3 · … » (board 28). */
|
||||
export function sheetDetails(
|
||||
t: Translate,
|
||||
sheet: SheetSummary,
|
||||
sheet: OfficialSheetAdminSummary,
|
||||
species: readonly CatalogSpecies[],
|
||||
locale: Locale,
|
||||
): string {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { OfficialSheetAdminSummary } from '@faunosteo/supabase'
|
||||
import { matchesSheetName } from '@/catalogue/useCatalogue'
|
||||
import { sheetNameMatcher } from '@/catalogue/useCatalogue'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
|
||||
// shortcut: search and sort run in the browser on the whole list; they move to
|
||||
@@ -13,7 +13,8 @@ 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))
|
||||
const matches = sheetNameMatcher(query)
|
||||
return sheets.filter((sheet) => matches(sheet.name))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,8 +28,15 @@ export function sortSheets(
|
||||
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 collator = new Intl.Collator(locale, {
|
||||
sensitivity: 'base',
|
||||
numeric: true,
|
||||
})
|
||||
// Each date read once, before the sort, rather than twice per comparison.
|
||||
const times = new Map(
|
||||
sheets.map((sheet) => [sheet, Date.parse(sheet.last_modified_at)]),
|
||||
)
|
||||
const time = (sheet: Sheet) => times.get(sheet) ?? 0
|
||||
const byName = (a: Sheet, b: Sheet) =>
|
||||
collator.compare(a.name[locale], b.name[locale]) ||
|
||||
a.sheet_id.localeCompare(b.sheet_id)
|
||||
|
||||
Reference in new issue
Block a user