diff --git a/src/components/PaginationNav/PaginationNav.module.css b/src/components/PaginationNav/PaginationNav.module.css new file mode 100644 index 000000000..30449c9ad --- /dev/null +++ b/src/components/PaginationNav/PaginationNav.module.css @@ -0,0 +1,7 @@ +.paginationContainer{ + position: relative; +} + +.itemsPerPageContainer{ + display: inline; +} \ No newline at end of file diff --git a/src/components/PaginationNav/PaginationNav.tsx b/src/components/PaginationNav/PaginationNav.tsx new file mode 100644 index 000000000..37e46e2de --- /dev/null +++ b/src/components/PaginationNav/PaginationNav.tsx @@ -0,0 +1,48 @@ +import React from 'react'; + +import type { SelectChangeEvent } from '@mui/material'; +import { InputLabel, MenuItem, Pagination, Select } from '@mui/material'; + +import styles from './PaginationNav.module.css'; + +interface PaginationNavProps { + page: number; + itemsPerPage: number; + totalItems: number; + handlePage: (_: React.ChangeEvent, value: number) => void; + handleItemsPerPage: (e: SelectChangeEvent) => void; +} + +const PaginationNav = ({ page, itemsPerPage, totalItems, handlePage, handleItemsPerPage }: PaginationNavProps) => { + return ( +
+
+ + Activités par page + + +
+ {totalItems > itemsPerPage && ( + + )} +
+ ); +}; +export default PaginationNav; diff --git a/src/components/accueil/Accueil.tsx b/src/components/accueil/Accueil.tsx index 6bb3c5a54..64d2bc485 100644 --- a/src/components/accueil/Accueil.tsx +++ b/src/components/accueil/Accueil.tsx @@ -97,7 +97,7 @@ export const Accueil = () => {

Dernières activités

- + ) : (
diff --git a/src/components/activities/List.tsx b/src/components/activities/List.tsx index 40a55188e..a1331c4fd 100644 --- a/src/components/activities/List.tsx +++ b/src/components/activities/List.tsx @@ -1,7 +1,9 @@ import React, { useState } from 'react'; -import { Button, Pagination, Stack } from '@mui/material'; +import type { SelectChangeEvent } from '@mui/material'; +import { Button } from '@mui/material'; +import PaginationNav from '../PaginationNav/PaginationNav'; import { ActivityCard } from './ActivityCard'; import { isAnthem } from 'src/activity-types/anyActivity'; import { UserContext } from 'src/contexts/userContext'; @@ -15,11 +17,12 @@ import type { Activity } from 'types/activity.type'; interface ActivitiesProps { activities: Activity[]; withLinks?: boolean; + withPagination?: boolean; noButtons?: boolean; onSelect?: (index: number) => void; } -export const Activities = ({ activities, noButtons = false, withLinks = false, onSelect }: ActivitiesProps) => { +export const Activities = ({ activities, noButtons = false, withLinks = false, withPagination = false, onSelect }: ActivitiesProps) => { const [{ selectedActivityId, responseActivityId }, setResponseActivityId] = React.useState<{ selectedActivityId: number | null; responseActivityId?: number | null; @@ -39,11 +42,21 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, o [users], ); const [page, setPage] = useState(1); + const [activitiesPerPage, setActivitiesPerPage] = React.useState(25); + + React.useEffect(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }, [page, activitiesPerPage]); + const handlePage = (_: React.ChangeEvent, value: number) => { setPage(value); - window.scrollTo({ top: 0, behavior: 'smooth' }); }; - const activitiesPerPage = 25; + + const handleActivitiesPerPage = (e: SelectChangeEvent) => { + setPage(1); + setActivitiesPerPage(parseInt(e.target.value)); + }; + const startIdx = (page - 1) * activitiesPerPage; const endIdx = startIdx + activitiesPerPage; @@ -148,9 +161,15 @@ export const Activities = ({ activities, noButtons = false, withLinks = false, o } return card; })} - - - + {withPagination && ( + + )}
); }; diff --git a/src/pages/reagir-a-une-activite/1.tsx b/src/pages/reagir-a-une-activite/1.tsx index ecb12fb25..a8a646d13 100644 --- a/src/pages/reagir-a-une-activite/1.tsx +++ b/src/pages/reagir-a-une-activite/1.tsx @@ -87,7 +87,7 @@ const ReactionStep1 = () => { value={selectedActivity.type === type ? selectedActivity.id : null} onChange={onChange} onSelect={onNext} - style={{ margin: '1rem 0 0 0' }} + style={{ margin: '1rem 0 0 0', overflowX: 'hidden' }} label={`Réagir à ${DESC[type]}`} type={type} />