Interactive interface for browsing global, full-resolution satellite imagery
update event marker when date changed
Jason Kent8a2c4cc0abdd
diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 7cc966a9a..6c14f1982 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -21,6 +21,7 @@ import { selectDate } from '../../modules/date/actions';import getSelectedDate from '../../modules/date/selectors';import { getEventCategories } from '../../modules/natural-events/selectors';import AlertUtil from '../../components/util/alert';+import util from '../../util/util';function Events(props) {const {@@ -28,15 +29,15 @@ function Events(props) {requestEvents,apiURL,config,- events,+ eventsData,eventCategories,sources,+ isPlaying,isLoading,selectEvent,selected,selectCategory,selectedCategory,- prevSelected,visibleWithinMapExtent,visibleEvents,height,@@ -45,7 +46,8 @@ function Events(props) {isMobile,showAlert,selectedDate,- proj,+ updateEventSelect,+ isAnimatingToEvent,} = props;const [dropdownOpen, setDropdownOpen] = useState(false);@@ -57,7 +59,7 @@ function Events(props) {// init requestsuseEffect(() => {- if (!isLoading && !hasRequestError && !events) {+ if (!isLoading && !hasRequestError && !eventsData) {let eventsRequestURL = `${apiURL}/events`;let sourceRequestURL = `${apiURL}/sources`;@@ -81,19 +83,20 @@ function Events(props) {// Deselect event if it's not visible in the map extentuseEffect(() => {- if (selected.id && selected.date && !visibleWithinMapExtent[selected.id] && events && events.length) {+ if (selected.id && selected.date && !visibleWithinMapExtent[selected.id] && eventsData && eventsData.length) {deselectEvent();}});- // When switching between projections, select an event that was previous selected- // if user had switched to projection where it was not visible then back to one where- // it is visible+ // If the date was changed to one that this event has, re-select it to move the markeruseEffect(() => {- if (!selected.id && prevSelected && visibleWithinMapExtent[prevSelected.id]) {- selectEvent(prevSelected.id, prevSelected.date, isMobile);+ if (isPlaying || isAnimatingToEvent) return;+ const geometry = selected.eventObject && selected.eventObject.geometry;+ const geometryForDate = (geometry || []).find((g) => g.date.split('T')[0] === selectedDate);+ if (geometryForDate) {+ updateEventSelect(selected.id, selectedDate);}- }, [proj]);+ }, [selectedDate]);const errorOrLoadingText = isLoading? 'Loading...'@@ -101,7 +104,7 @@ function Events(props) {? 'There has been an ERROR retrieving events from the EONET events API': '';- const eventsForSelectedCategory = !isLoading && (events || []).filter((event) => {+ const eventsForSelectedCategory = !isLoading && (eventsData || []).filter((event) => {if (selectedCategory === ALL_CATEGORY) return event;if (event.categories.find((category) => category.title === selectedCategory)) {return event;@@ -194,6 +197,9 @@ const mapDispatchToProps = (dispatch) => ({dispatch(selectDate(new Date(dateStr)));}},+ updateEventSelect: (id, dateStr) => {+ dispatch(selectEventActionCreator(id, dateStr));+ },deselectEvent: () => {dispatch(deselectEventActionCreator());},@@ -210,29 +216,31 @@ const mapDispatchToProps = (dispatch) => ({const mapStateToProps = (state) => {const {+ animation,requestedEvents,requestedEventSources,config,proj,browser,+ events,} = state;const {- selected, prevSelected, showAll, category,- } = state.events;+ selected, showAll, category,+ } = events;const apiURL = lodashGet(state, 'config.features.naturalEvents.host');const isLoading = requestedEvents.isLoading|| requestedEventSources.isLoading;const hasRequestError = requestedEvents.error|| requestedEventSources.error;let visibleEvents = {};- const events = lodashGet(requestedEvents, 'response');+ const eventsData = lodashGet(requestedEvents, 'response');const sources = lodashGet(requestedEventSources, 'response');const mapExtent = lodashGet(state, 'map.extent');let visibleWithinMapExtent = {};- if (events && mapExtent) {+ if (eventsData && mapExtent) {visibleWithinMapExtent = getEventsWithinExtent(- events,+ eventsData,selected,proj.selected.maxExtent,proj.selected,@@ -240,7 +248,7 @@ const mapStateToProps = (state) => {);const extent = showAll ? proj.selected.maxExtent : mapExtent;visibleEvents = getEventsWithinExtent(- events,+ eventsData,selected,extent,proj.selected,@@ -249,21 +257,21 @@ const mapStateToProps = (state) => {}return {- events,+ eventsData,eventCategories: getEventCategories(state),sources,showAll,isLoading,hasRequestError,selected,- prevSelected,- proj,visibleWithinMapExtent,visibleEvents,apiURL,config,+ isPlaying: animation.isPlaying,isMobile: browser.lessThan.medium,- selectedDate: getSelectedDate(state).toISOString().split('T')[0],+ isAnimatingToEvent: events.isAnimatingToEvent,+ selectedDate: util.toISOStringDate(getSelectedDate(state)),selectedCategory: category,};};@@ -277,13 +285,13 @@ Events.propTypes = {eventCategories: PropTypes.array,config: PropTypes.object,deselectEvent: PropTypes.func,- events: PropTypes.array,+ eventsData: PropTypes.array,hasRequestError: PropTypes.bool,height: PropTypes.number,+ isPlaying: PropTypes.bool,isLoading: PropTypes.bool,isMobile: PropTypes.bool,- prevSelected: PropTypes.object,- proj: PropTypes.object,+ isAnimatingToEvent: PropTypes.bool,requestEvents: PropTypes.func,requestSources: PropTypes.func,selected: PropTypes.object,@@ -293,6 +301,7 @@ Events.propTypes = {selectedCategory: PropTypes.string,showAlert: PropTypes.bool,sources: PropTypes.array,+ updateEventSelect: PropTypes.func,visibleEvents: PropTypes.object,visibleWithinMapExtent: PropTypes.object,};diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 769fecb6b..0cce537b8 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -29,11 +29,17 @@ export function requestSources(location) {);}-export function selectEvent(id, date) {- return {- type: SELECT_EVENT,- id,- date,+export function selectEvent(id, eventDate) {+ return (dispatch, getState) => {+ const { requestedEvents } = getState();+ const eventObject = requestedEvents.response.find((e) => e.id === id);++ dispatch({+ type: SELECT_EVENT,+ id,+ date: eventDate,+ eventObject,+ });};}diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex 920c266c2..9eff316e1 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -48,10 +48,11 @@ const formatResponse = function(item, ignored) {};export const eventsReducerState = {- prevSelected: null,selected: {id: '',date: null,+ eventObject: null,+ geometryForDate: null,},active: false,showAll: true,@@ -61,23 +62,24 @@ export const eventsReducerState = {export function eventsReducer(state = eventsReducerState, action) {switch (action.type) {- case SELECT_EVENT:+ case SELECT_EVENT: {+ const {+ id, date, eventObject,+ } = action;return {...state,selected: {- id: action.id,- date: action.date,+ id,+ date,+ eventObject,},isAnimatingToEvent: true,};+ }case DESELECT_EVENT:return {...state,- prevSelected: state.selected,- selected: {- id: '',- date: null,- },+ selected: eventsReducerState.selected,};case SELECT_CATEGORY:return {