Skip to content

Commit 25a04f5

Browse files
committed
feat(search): allow selecting specific page instead of just having prev/next choices
1 parent a79b3a8 commit 25a04f5

1 file changed

Lines changed: 57 additions & 16 deletions

File tree

src/app/(public)/initiatives/InitiativeListPage.tsx

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import Grid, { GridProps } from '@mui/material/Grid';
1313
import IconButton from '@mui/material/IconButton';
1414
import InputAdornment from '@mui/material/InputAdornment';
1515
import Link from '@mui/material/Link';
16+
import MenuItem from '@mui/material/MenuItem';
17+
import Pagination from '@mui/material/Pagination';
1618
import Stack from '@mui/material/Stack';
17-
import TablePagination from '@mui/material/TablePagination';
1819
import TextField from '@mui/material/TextField';
1920
import ToggleButton from '@mui/material/ToggleButton';
2021
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
@@ -349,21 +350,61 @@ export function InitiativeListPage(props: InitiativeListPageProps) {
349350
</Grid>
350351
</Grid>
351352
)}
352-
<Grid container justifyContent="end" sx={reusableCentering}>
353-
<TablePagination
354-
component="div"
355-
rowsPerPageOptions={possiblePageSizes}
356-
count={totalCount}
357-
rowsPerPage={pageSize}
358-
page={params.page - 1}
359-
onPageChange={(event, pageNumber) => {
360-
setParams({ page: pageNumber + 1 });
361-
}}
362-
onRowsPerPageChange={(event) => {
363-
setPageSize(event.target.value as unknown as PaginationSize);
364-
}}
365-
sx={{ mt: 3 }}
366-
/>
353+
<Grid container justifyContent="space-between" alignItems="center" rowSpacing={2} sx={{ ...reusableCentering, mt: 3 }}>
354+
<Grid item>
355+
<Stack direction="row" spacing={2} alignItems="center">
356+
{totalCount >= 0 && (
357+
<Typography variant="body2" color="text.secondary">
358+
{totalCount}&nbsp;initiative{totalCount > 1 ? 's' : ''}
359+
</Typography>
360+
)}
361+
<TextField
362+
select
363+
size="small"
364+
label="Par page"
365+
value={pageSize}
366+
onChange={(event) => {
367+
setPageSize(event.target.value as unknown as PaginationSize);
368+
setParams({ page: 1 }); // a bigger page size shrinks the total pages, so go back to a guaranteed-valid page
369+
}}
370+
sx={{ minWidth: 110 }}
371+
>
372+
{possiblePageSizes.map((size) => (
373+
<MenuItem key={size} value={size}>
374+
{size}
375+
</MenuItem>
376+
))}
377+
</TextField>
378+
</Stack>
379+
</Grid>
380+
<Grid item>
381+
<Pagination
382+
count={pagesCount ?? 1}
383+
page={params.page}
384+
onChange={(event, pageNumber) => {
385+
setParams({ page: pageNumber });
386+
}}
387+
color="primary"
388+
showFirstButton
389+
showLastButton
390+
siblingCount={1}
391+
boundaryCount={1}
392+
getItemAriaLabel={(type, page) => {
393+
switch (type) {
394+
case 'first':
395+
return 'première page';
396+
case 'last':
397+
return 'dernière page';
398+
case 'previous':
399+
return 'page précédente';
400+
case 'next':
401+
return 'page suivante';
402+
default:
403+
return `page ${page}`;
404+
}
405+
}}
406+
/>
407+
</Grid>
367408
</Grid>
368409
</Grid>
369410
</Grid>

0 commit comments

Comments
 (0)