feat(app): collapsible sheet filters on phone, one empty announcement

This commit is contained in:
bchanot committed 2026-11-16 20:30:27 +01:00
1 parent 5014a45053
commit 9efc7b7647
4 files changed
+220 -5

No files matched your search

@@ -99,7 +99,24 @@ function useListView() {
const [filters, setFilters] = useState<SheetFilters>(NO_FILTER)
const [sort, setSort] = useState<SheetSort>('modified')
const search = useSearch()
return { filters, setFilters, sort, setSort, ...search }
const [open, setOpen] = useState(false)
const toggleRef = useRef<HTMLButtonElement>(null)
/** The reset button disappears with the last filter: the focus moves to the toggle. */
const resetFilters = () => {
setFilters(NO_FILTER)
toggleRef.current?.focus()
}
return {
...search,
filters,
setFilters,
sort,
setSort,
open,
setOpen,
toggleRef,
resetFilters,
}
}
type ListView = ReturnType<typeof useListView>
@@ -255,7 +272,7 @@ const STATUS_FILTERS = [
] as const
/** The four filters of §11.1, unchanged; species offered are those of the loaded list. */
function Filters({ sheets, species, view }: ResultsProps) {
function FilterGrid({ sheets, species, view }: ResultsProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const speciesOptions = [...new Set(sheets.map((s) => s.species_id))].map(
@@ -285,6 +302,84 @@ function Filters({ sheets, species, view }: ResultsProps) {
)
}
const FILTERS_PANEL_ID = 'admin-sheets-filters'
/** Phone only: « Filtres » or « Filtres (n) », n the filters that are not empty. */
function FiltersToggle({ view }: { view: ListView }) {
const t = useT()
const active = Object.values(view.filters).filter(Boolean).length
return (
<Button
ref={view.toggleRef}
type="button"
variant="secondary"
aria-expanded={view.open}
aria-controls={FILTERS_PANEL_ID}
onClick={() => view.setOpen((o) => !o)}
className="min-h-11 w-full justify-between sm:hidden"
>
{active === 0
? t('admin.sheets.filters')
: t('admin.sheets.filters_active').replace('{count}', String(active))}
<Icon
name="chevron-down"
size={16}
className={
'transition-transform motion-reduce:transition-none ' +
(view.open ? 'rotate-180' : '')
}
/>
</Button>
)
}
/** Phone only, inside the panel, while at least one filter is not empty. */
function ResetFilters({ view }: { view: ListView }) {
const t = useT()
if (!Object.values(view.filters).some(Boolean)) return null
return (
<Button
type="button"
variant="secondary"
onClick={view.resetFilters}
className="mt-3 min-h-11 w-full sm:hidden"
>
<Icon name="close" size={14} className="mr-1" />
{t('admin.sheets.filters_reset')}
</Button>
)
}
// A closed panel is collapsed (grid row 0fr) and invisible, so nothing in it takes
// focus or a tap; visibility changes with the transition. `sm:` keeps the grid as
// it was on a desktop: always shown, no button.
const PANEL =
'grid transition-[grid-template-rows,visibility] duration-200 ' +
'motion-reduce:transition-none sm:block'
/** The filters: a collapsible panel on a phone (closed by default), the grid from `sm`. */
function Filters(props: ResultsProps) {
const { view } = props
const state = view.open
? 'max-sm:mt-3 max-sm:grid-rows-[1fr]'
: 'max-sm:grid-rows-[0fr] max-sm:invisible'
return (
<div>
<FiltersToggle view={view} />
<div
id={FILTERS_PANEL_ID}
data-open={view.open}
className={`${PANEL} ${state}`}
>
<div className="-m-1 min-h-0 overflow-hidden p-1 sm:overflow-visible">
<FilterGrid {...props} />
<ResetFilters view={view} />
</div>
</div>
</div>
)
}
/** « {n} fiches » when everything is shown, « {n} fiches sur {total} » otherwise. */
function CountLine({ shown, total }: { shown: number; total: number }) {
const plural = usePlural()
@@ -298,9 +393,16 @@ function CountLine({ shown, total }: { shown: number; total: number }) {
)
}
function EmptyLine({ text }: { text: string }) {
/** `announce` false when the count line already speaks for the empty result. */
function EmptyLine({
text,
announce = true,
}: {
text: string
announce?: boolean
}) {
return (
<p role="status" className={EMPTY_LINE}>
<p role={announce ? 'status' : undefined} className={EMPTY_LINE}>
{text}
</p>
)
@@ -359,7 +461,7 @@ function Results({ sheets, species, view }: ResultsProps) {
<CountLine shown={shown.length} total={sheets.length} />
{shown.length === 0 &&
(filtering ? (
<EmptyLine text={t('admin.sheets.no_match')} />
<EmptyLine text={t('admin.sheets.no_match')} announce={false} />
) : (
<SearchNoResult view={view} />
))}
+3
View File
@@ -1038,6 +1038,9 @@ export const en: Dict = {
'admin.sheets.count_of_one': '{count} sheet of {total}',
'admin.sheets.count_of_other': '{count} sheets of {total}',
'admin.sheets.modified': 'Modified on {date}',
'admin.sheets.filters': 'Filters',
'admin.sheets.filters_active': 'Filters ({count})',
'admin.sheets.filters_reset': 'Reset filters',
'admin.sheets.no_result': 'No sheet name contains “{q}”.',
'admin.sheet_form.lede': 'The sheet starts empty: views, annotations and findings are entered later in the editor.',
'admin.sheet_form.species': 'Species',
+3
View File
@@ -1069,6 +1069,9 @@ export const fr: Dict = {
'admin.sheets.count_of_one': '{count} fiche sur {total}',
'admin.sheets.count_of_other': '{count} fiches sur {total}',
'admin.sheets.modified': 'Modifiée le {date}',
'admin.sheets.filters': 'Filtres',
'admin.sheets.filters_active': 'Filtres ({count})',
'admin.sheets.filters_reset': 'Réinitialiser les filtres',
'admin.sheets.no_result': 'Aucune fiche ne contient « {q} » dans son nom.',
'admin.sheet_form.lede': "La fiche démarre vide : vues, annotations et constats se saisissent ensuite dans l'éditeur.",
'admin.sheet_form.species': 'Espèce',