Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
DysphoricUnicorn committed Dec 4, 2024
1 parent e22acd2 commit fbe9e51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 16 additions & 10 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 | ButterflyMapPropsWithPagination) => {
const ButterflyMap = (props: ButterflyMapProps) => {
const localStrings = completeLocalStrings(props.localStrings);
const [position, setPosition] = React.useState(props.center);
const [reduceMotion, setReduceMotion] = React.useState<boolean>(() => {
Expand All @@ -40,6 +40,15 @@ const ButterflyMap = (props: ButterflyMapProps | ButterflyMapPropsWithPagination
});
const updateUserPositionInterval = React.useRef<number>();

React.useEffect(() => {
let found = props.paginationPage === undefined;
for (const serverSideField of [props.setPaginationPage, props.entriesPerPage, props.setEntriesPerPage]) {
if ((serverSideField === undefined) !== found) {
throw new Error('react butterfly map error: When one of the server side pagination props is set, all of them have to be.');
}
}
}, []);

React.useEffect(() => {
window.addEventListener('scroll', () => {
setLocationBlocked(false);
Expand Down Expand Up @@ -174,8 +183,8 @@ const ButterflyMap = (props: ButterflyMapProps | ButterflyMapPropsWithPagination
setPage={props.setPaginationPage ?? setPaginationPage}
displayPoints={sortedPointsOfInterest}
handlePoiClick={handlePoiClick}
entriesPerPage={entriesPerPage}
setEntriesPerPage={setEntriesPerPage}
entriesPerPage={props.entriesPerPage}
setEntriesPerPage={props.setEntriesPerPage}
/>}
</ThemeProvider>;
};
Expand All @@ -189,13 +198,10 @@ type ButterflyMapProps = {
theme?: PartialTheme,
localStrings?: PartialLocalStrings,
customFilters?: CustomFilter[],
}

type ButterflyMapPropsWithPagination = ButterflyMapProps & {
entriesPerPage: number,
setEntriesPerPage: () => void,
paginationPage: number,
setPaginationPage: () => void,
entriesPerPage?: number,
setEntriesPerPage?: React.Dispatch<React.SetStateAction<number>>,
paginationPage?: number,
setPaginationPage?: React.Dispatch<React.SetStateAction<number>>,
}

export default ButterflyMap;
2 changes: 2 additions & 0 deletions src/js/components/PointBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type PointBarProps = {
handlePoiClick: handlePoiClick,
userPosition?: Position,
localStrings: LocalStrings,
entriesPerPage?: number,
setEntriesPerPage?: React.Dispatch<React.SetStateAction<number>>,
}

type PointBarPropsWithPage = PointBarProps & {
Expand Down

0 comments on commit fbe9e51

Please sign in to comment.