Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Map should fit better to Slovenia on initial load #96 #98

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/Doctors/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useEffect, useMemo, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useMediaQuery } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import PropTypes from 'prop-types';

import { filterContext } from 'context';
import DoctorCard from 'components/DoctorCard';
Expand Down Expand Up @@ -46,12 +49,17 @@ const Doctors = function Doctors({ itemsPerPage = 10 }) {
map.flyTo([lat, lon], MAP.MAX_ZOOM);
};

const zoom = state?.zoom ?? MAP.ZOOM;
const theme = useTheme();
const matches = useMediaQuery(theme.breakpoints.up('sm'));

const breakpointDefaultZoom = matches ? MAP.ZOOM : MAP.ZOOM_BELOW_SMALL;

const zoom = state?.zoom ?? breakpointDefaultZoom;
const center = state?.center ?? MAP.GEO_LOCATION.SL_CENTER;

return (
<Styled.Wrapper>
<MainMap whenCreated={setMap} doctors={doctors} center={center} zoom={zoom} />
<MainMap key={matches} whenCreated={setMap} doctors={doctors} center={center} zoom={zoom} />
<Styled.WrapperInfinite id="scrollableDiv">
<Styled.InfiniteScroll
id="infiniteScroll"
Expand All @@ -74,6 +82,14 @@ const Doctors = function Doctors({ itemsPerPage = 10 }) {
);
};

Doctors.defaultProps = {
itemsPerPage: 10,
};

Doctors.propTypes = {
itemsPerPage: PropTypes.number,
};

export default Doctors;

export function getCenter(doctors) {
Expand Down
3 changes: 2 additions & 1 deletion src/const/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * as SIZES from './sizes';
export * as CSV_URL from './csvURL';
export { default as THEME } from './theme';

const ZOOM_BELOW_SMALL = 7;
const ZOOM = 8;
const MIN_ZOOM = 6;
const MAX_ZOOM = 16;
Expand All @@ -21,4 +22,4 @@ const BOUNDS = {
},
};

export const MAP = { ZOOM, MIN_ZOOM, MAX_ZOOM, GEO_LOCATION, BOUNDS };
export const MAP = { ZOOM, ZOOM_BELOW_SMALL, MIN_ZOOM, MAX_ZOOM, GEO_LOCATION, BOUNDS };