Skip to content

Commit

Permalink
Allow passing in pagination props into the Pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
technokatzen committed Dec 3, 2024
1 parent a958cfd commit e22acd2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/js/components/ButterflyMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {completeTheme} from '../Helpers/themeHelpers';
import {completeLocalStrings} from '../Helpers/localisationHelpers';
import Markers from './Markers';

const ButterflyMap = (props: ButterflyMapProps) => {
const ButterflyMap = (props: ButterflyMapProps | ButterflyMapPropsWithPagination) => {
const localStrings = completeLocalStrings(props.localStrings);
const [position, setPosition] = React.useState(props.center);
const [reduceMotion, setReduceMotion] = React.useState<boolean>(() => {
Expand Down Expand Up @@ -170,10 +170,12 @@ const ButterflyMap = (props: ButterflyMapProps) => {
{sortedPointsOfInterest.length > 0 &&
<PointBar userPosition={userPosition}
localStrings={localStrings}
page={paginationPage}
setPage={setPaginationPage}
page={props.paginationPage ?? paginationPage}
setPage={props.setPaginationPage ?? setPaginationPage}
displayPoints={sortedPointsOfInterest}
handlePoiClick={handlePoiClick}
entriesPerPage={entriesPerPage}
setEntriesPerPage={setEntriesPerPage}
/>}
</ThemeProvider>;
};
Expand All @@ -189,4 +191,11 @@ type ButterflyMapProps = {
customFilters?: CustomFilter[],
}

type ButterflyMapPropsWithPagination = ButterflyMapProps & {
entriesPerPage: number,
setEntriesPerPage: () => void,
paginationPage: number,
setPaginationPage: () => void,
}

export default ButterflyMap;
2 changes: 1 addition & 1 deletion src/js/components/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PaginationButtons from './Styled/Pagination/PaginationButtons';

type PaginationProps = {
page: number,
setPage: React.Dispatch<React.SetStateAction<number>>,
setPage: React.Dispatch<React.SetStateAction<number>> | (() => void),
entriesPerPage: number,
setEntriesPerPage: (page: number) => void,
entryCount: number,
Expand Down
16 changes: 12 additions & 4 deletions src/js/components/PointBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ type PointBarProps = {
localStrings: LocalStrings,
}

const PointBar = (props: PointBarProps) => {
type PointBarPropsWithPage = PointBarProps & {
entriesPerPage: number,
setEntriesPerPage: () => void,
}

const PointBar = (props: PointBarProps | PointBarPropsWithPage) => {
const [entriesPerPage, _setEntriesPerPage] = React.useState<number>(window.innerWidth < 1000 ? 4 : 8);
const {page, setPage, displayPoints, localStrings, handlePoiClick, userPosition} = props;

const setEntriesPerPage = (newEntriesPerPage: number) => {
_setEntriesPerPage(newEntriesPerPage);
setPage(1);
};

const {page, setPage, displayPoints, localStrings, handlePoiClick, userPosition} = props;



let paginatedPoints = [];
for (let c = 0; c < entriesPerPage; c++) {
const point = displayPoints[entriesPerPage * (page - 1) + c];
Expand All @@ -47,8 +55,8 @@ const PointBar = (props: PointBarProps) => {
</CardContainer>
<Pagination page={page}
setPage={setPage}
entriesPerPage={entriesPerPage}
setEntriesPerPage={setEntriesPerPage}
entriesPerPage={props.entriesPerPage ?? entriesPerPage}
setEntriesPerPage={props.setEntriesPerPage ?? setEntriesPerPage}
entryCount={displayPoints.length}
localStrings={localStrings}
/>
Expand Down

0 comments on commit e22acd2

Please sign in to comment.