Skip to content

Commit

Permalink
when a location is focused, open the popup for the marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mattroseman committed Jun 21, 2020
1 parent 38142b5 commit 6c96206
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
2 changes: 2 additions & 0 deletions client/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export {
SET_MAP_MARKERS,
HIGHLIGHT_MARKER,
UNHIGHLIGHT_MARKER,
FOCUS_LOCATION,

setMapViewport,
setMapBounds,
fetchMapMarkers,
highlightMarker,
unhighlightMarker,
focusLocation,
} from './map-actions.js';

export {
Expand Down
8 changes: 8 additions & 0 deletions client/actions/map-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const REQUEST_SPECIFIC_MOVIE_LOCATION_CLUSTERS = 'REQUEST_SPECIFIC_MOVIE_
export const SET_MAP_MARKERS = 'SET_MAP_MARKERS';
export const HIGHLIGHT_MARKER = 'HIGHLIGHT_MARKER';
export const UNHIGHLIGHT_MARKER = 'UNHIGHLIGHT_MARKER';
export const FOCUS_LOCATION = 'FOCUS_LOCATION';

/*
* ACTION CREATORS
Expand Down Expand Up @@ -106,3 +107,10 @@ export function unhighlightMarker() {
type: UNHIGHLIGHT_MARKER
};
}

export function focusLocation(movieLocation) {
return {
type: FOCUS_LOCATION,
movieLocation
};
}
4 changes: 2 additions & 2 deletions client/components/MovieInfo/MovieCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
hideMovieInfo,
highlightMarker,
unhighlightMarker,
setMapViewport,
focusLocation,
} from '../../actions';


Expand All @@ -30,7 +30,7 @@ export default function MovieCard(props) {
className='movie-card-location'
onMouseEnter={() => dispatch(highlightMarker(movieLocation.id))}
onMouseLeave={() => dispatch(unhighlightMarker())}
onClick={() => dispatch(setMapViewport({center: movieLocation.point, zoom: 19}))}
onClick={() => dispatch(focusLocation(movieLocation))}
>
<h4 className='movie-card-location-name'>{movieLocation.locationString}</h4>

Expand Down
42 changes: 35 additions & 7 deletions client/components/MovieMap/LocationMarker.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import { useSelector } from 'react-redux';

import { Marker, Popup } from 'react-leaflet';


function LocationMarker(props) {
let popup;
const marker = useRef(null);
const popup = useRef(null);

useEffect(() => {
marker.current.leafletElement.bindPopup(popup.current.leafletElement);
}, []);

// if this location is focused open the popup
const focusedLocation = useSelector(state => state.map.focusedLocation);
useEffect(() => {
// console.log(focusedLocation);
if (focusedLocation === props.marker.locations[0].id) {
marker.current.leafletElement.openPopup();
}
}, [focusedLocation]);

let popupElement;

if (props.marker.locations[0].placeId != null) {
popup = (
<Popup className="location-marker-popup" autoPan={false}>
popupElement = (
<Popup
ref={popup}
className="location-marker-popup"
autoPan={false}
// TODO onClose={() => dispatch(unfocusLocation())}
>
<div className="location-marker-popup-content">
<div className="location-marker-popup__location-string">
{props.marker.locations[0].locationString}
Expand All @@ -27,15 +49,21 @@ function LocationMarker(props) {
</Popup>
);
} else {
popup = (
<Popup className="location-marker-popup" autoPan={false}>
popupElement = (
<Popup
ref={popup}
className="location-marker-popup"
autoPan={false}
// TODO onClose={() => dispatch(unfocusLocation())}
>
{props.marker.locations[0].locationString}
</Popup>
);
}

return (
<Marker
ref={marker}
position={props.marker.coordinate}
icon={L.divIcon({
html: '<i class="fa fa-map-marker fa-3x" aria-hidden="true"></i>',
Expand All @@ -44,7 +72,7 @@ function LocationMarker(props) {
})}
onClick={() => console.log(props.marker.locations[0].locationString)}
>
{popup}
{popupElement}
</Marker>
);
}
Expand Down
12 changes: 11 additions & 1 deletion client/reducers/map-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default function map(state=initialState.map, action) {
count: cluster.numLocations,
coordinate: cluster.center,
locations: cluster.locations,
highlighted: false
highlighted: false,
focused: false
};
}

Expand Down Expand Up @@ -58,6 +59,15 @@ export default function map(state=initialState.map, action) {
...state,
highlightedMarker: null
};
case actions.FOCUS_LOCATION:
return {
...state,
viewport: {
center: action.movieLocation.point,
zoom: 19
},
focusedLocation: action.movieLocation.id,
};
default:
return state;
}
Expand Down
3 changes: 2 additions & 1 deletion client/state/initial-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const initialState = {
},
geohashesShowing: [],
markers: {},
highlightedMarker: null
highlightedMarker: null,
focusedLocation: null,
},
movieInfo: {
showing: false,
Expand Down

0 comments on commit 6c96206

Please sign in to comment.