Skip to content

Commit

Permalink
Define an explicit hasZoomControl prop for Map components instead o…
Browse files Browse the repository at this point in the history
…f dealing with `type`
  • Loading branch information
dtrucs committed Jul 24, 2023
1 parent b124543 commit 6428471
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Map/DetailsMap/DetailsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type PropsType = {
trekGeoJSON?: string;
pointsReference?: Coordinate2D[] | null;
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl: boolean;
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: Coordinate2D;
Expand Down Expand Up @@ -159,7 +159,7 @@ export const DetailsMap: React.FC<PropsType> = props => {
minZoom={
navigator.onLine ? undefined : Math.min(...(mapConfig?.zoomAvailableOffline ?? []))
}
zoomControl={props.type === 'DESKTOP'}
zoomControl={props.hasZoomControl}
whenCreated={setMapInstance}
bounds={bounds}
>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Map/SearchMap/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { Map } from 'leaflet';

interface Props {
whenCreated: (map: Map) => void;
type: string;
hasZoomControl?: boolean;
children: React.ReactNode;
}

const MapContainer: React.FC<Props> = ({ children, whenCreated, type }) => {
const MapContainer: React.FC<Props> = ({ children, whenCreated, hasZoomControl = false }) => {
const mapConfig = getMapConfig();

return (
<LeafMapContainer
className="w-full h-full"
center={mapConfig.searchMapCenter as [number, number]}
zoom={mapConfig.searchMapZoom}
maxZoom={mapConfig.maximumZoomLevel}
whenCreated={whenCreated}
scrollWheelZoom
style={{ height: '100%', width: '100%' }}
zoomControl={type === 'DESKTOP'}
zoomControl={hasZoomControl}
id="search_map"
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useListAndMapContext } from '../../../modules/map/ListAndMapContext';
export type PropsType = {
segments?: { x: number; y: number }[];
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: { x: number; y: number };
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Map/SearchMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import TileLayerManager from '../components/TileLayerManager';
export type PropsType = {
segments?: { x: number; y: number }[];
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl?: boolean;
openFilterMenu?: () => void;
hasFilters?: boolean;
arrivalLocation?: { x: number; y: number };
Expand All @@ -37,7 +37,7 @@ const SearchMap: React.FC<PropsType> = props => {
const { setMapInstance } = useTileLayer();

return (
<MapContainer whenCreated={setMapInstance} type={props.type}>
<MapContainer whenCreated={setMapInstance} hasZoomControl={props.hasZoomControl}>
{props.onMove && <MoveHandler onMove={props.onMove} />}
<TileLayerManager />
<BackButton icon={<ArrowLeft size={24} />} onClick={hideMap} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface TouristicContentGeometryNullable {
export type PropsType = {
touristicContentGeometry: TouristicContentGeometryNullable;
hideMap?: () => void;
type: 'DESKTOP' | 'MOBILE';
hasZoomControl: boolean;
bbox: Bbox;
};

Expand All @@ -63,6 +63,7 @@ export const TouristicContentMap: React.FC<PropsType> = props => {
return (
<>
<MapContainer
className="w-full h-full"
scrollWheelZoom
maxZoom={
navigator.onLine
Expand All @@ -72,9 +73,8 @@ export const TouristicContentMap: React.FC<PropsType> = props => {
minZoom={
navigator.onLine ? undefined : Math.min(...(mapConfig?.zoomAvailableOffline ?? []))
}
style={{ height: '100%', width: '100%' }}
whenCreated={setMapInstance}
zoomControl={props.type === 'DESKTOP'}
zoomControl={props.hasZoomControl}
bounds={center}
attributionControl={false}
>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export const DetailsUIWithoutContext: React.FC<Props> = ({ slug, parentId, langu
)}
>
<DetailsMapDynamicComponent
type={isMobile ? 'MOBILE' : 'DESKTOP'}
hasZoomControl={!isMobile}
hideMap={hideMobileMap}
title={details.title}
arrivalLocation={details.trekArrival}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/pages/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const SearchUI: React.FC<Props> = ({ language }) => {
<Loader loaded={!isMapLoading} className="absolute inset-0 z-map" />
{!isMobile && (
<SearchMapDynamicComponent
type="DESKTOP"
hasZoomControl
onMove={handleMoveMap}
shouldUseClusters
shouldUsePopups
Expand All @@ -279,7 +279,6 @@ export const SearchUI: React.FC<Props> = ({ language }) => {
>
<SearchMapDynamicComponent
hideMap={hideMobileMap}
type="MOBILE"
openFilterMenu={displayMenu}
hasFilters={numberSelected > 0}
shouldUseClusters
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/site/OutdoorCourseUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export const OutdoorCourseUIWithoutContext: React.FC<Props> = ({ outdoorCourseUr
)}
>
<DetailsMapDynamicComponent
type={isMobile ? 'MOBILE' : 'DESKTOP'}
hasZoomControl={!isMobile}
outdoorGeometry={{
geometry: outdoorCourseContent.geometry,
pictogramUri: '',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/site/OutdoorSiteUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ const OutdoorSiteUIWithoutContext: React.FC<Props> = ({ outdoorSiteUrl, language
<DetailsMapDynamicComponent
courses={outdoorSiteContent?.courses}
experiences={outdoorSiteContent?.children}
type={isMobile ? 'MOBILE' : 'DESKTOP'}
hasZoomControl={!isMobile}
outdoorGeometry={{
geometry: outdoorSiteContent.geometry,
pictogramUri: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const TouristicContentUI: React.FC<TouristicContentUIProps> = ({
)}
>
<TouristicContentMapDynamicComponent
type={isMobile ? 'MOBILE' : 'DESKTOP'}
hasZoomControl={!isMobile}
bbox={touristicContent.bbox}
touristicContentGeometry={{
geometry: touristicContent.geometry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export const TouristicEventUIWithoutContext: React.FC<Props> = ({
)}
>
<DetailsMapDynamicComponent
type={isMobile ? 'MOBILE' : 'DESKTOP'}
hasZoomControl={!isMobile}
eventGeometry={{
geometry: touristicEventContent.geometry,
pictogramUri: touristicEventContent.category.pictogramUri,
Expand Down

0 comments on commit 6428471

Please sign in to comment.