Skip to content

Commit

Permalink
add pagination nav component
Browse files Browse the repository at this point in the history
  • Loading branch information
SimNed committed Mar 5, 2024
1 parent c1fb8c2 commit 1daac2b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
36 changes: 36 additions & 0 deletions src/components/PaginationNav/PaginationNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';

import type { SelectChangeEvent } from '@mui/material';
import { InputLabel, MenuItem, Pagination, Select, Stack } from '@mui/material';

interface PaginationNavProps {
page: number;
itemsPerPage: number;
totalItems: number;
handlePage: (_: React.ChangeEvent<unknown>, value: number) => void;
handleItemsPerPage: (e: SelectChangeEvent<string>) => void;
}

const PaginationNav = ({ page, itemsPerPage, totalItems, handlePage, handleItemsPerPage }: PaginationNavProps) => {
return (
<Stack direction="row" spacing={4} alignItems="center" justifyContent="flex-start">
<Stack direction="row" alignItems="center" justifyContent="center" spacing={2}>
<InputLabel id="activities-per-page-label">Activités par page</InputLabel>
<Select
labelId="activities-per-page-label"
variant="standard"
size="small"
id="demo-simple-select-standard"
value={itemsPerPage.toString()}
onChange={handleItemsPerPage}
>
<MenuItem value={5}>5</MenuItem>
<MenuItem value={10}>10</MenuItem>
<MenuItem value={25}>25</MenuItem>
</Select>
</Stack>
{totalItems > itemsPerPage && <Pagination count={Math.ceil(totalItems / itemsPerPage)} page={page} onChange={handlePage} variant="outlined" />}
</Stack>
);
};
export default PaginationNav;
29 changes: 9 additions & 20 deletions src/components/activities/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React, { useState } from 'react';

import type { SelectChangeEvent } from '@mui/material';
import { InputLabel, Button, MenuItem, Pagination, Select, Stack } from '@mui/material';

Check warning on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'InputLabel' is defined but never used

Check warning on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'MenuItem' is defined but never used

Check warning on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'Pagination' is defined but never used

Check warning on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'Select' is defined but never used

Check warning on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'Stack' is defined but never used

Check failure on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'InputLabel' is declared but its value is never read.

Check failure on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'MenuItem' is declared but its value is never read.

Check failure on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'Pagination' is declared but its value is never read.

Check failure on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'Select' is declared but its value is never read.

Check failure on line 4 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'Stack' is declared but its value is never read.
import { margin } from '@mui/system';

Check warning on line 5 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / lint

'margin' is defined but never used

Check failure on line 5 in src/components/activities/List.tsx

View workflow job for this annotation

GitHub Actions / typescript

'margin' is declared but its value is never read.

import PaginationNav from '../PaginationNav/PaginationNav';
import { ActivityCard } from './ActivityCard';
import { isAnthem } from 'src/activity-types/anyActivity';
import { UserContext } from 'src/contexts/userContext';
Expand Down Expand Up @@ -161,26 +163,13 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, w
return card;
})}
{withPagination && (
<nav>
<InputLabel id="demo-simple-select-helper-label">Activités par page</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
size="small"
id="demo-simple-select-standard"
value={activitiesPerPage.toString()}
onChange={handleActivitiesPerPage}
>
<MenuItem value={5}>5</MenuItem>

<MenuItem value={10}>10</MenuItem>
<MenuItem value={25}>25</MenuItem>
</Select>
{activities.length > activitiesPerPage && (
<Stack spacing={2} alignItems="center">
<Pagination count={Math.ceil(activities.length / activitiesPerPage)} page={page} onChange={handlePage} variant="outlined" />
</Stack>
)}
</nav>
<PaginationNav
page={page}
itemsPerPage={activitiesPerPage}
totalItems={activities.length}
handlePage={handlePage}
handleItemsPerPage={handleActivitiesPerPage}
/>
)}
</div>
);
Expand Down

0 comments on commit 1daac2b

Please sign in to comment.