Interactive interface for browsing global, full-resolution satellite imagery
restore event state on sidebar collapse/expand
Jason Kent6c5febb555f1
diff --git a/web/js/components/sidebar/event.js b/web/js/components/sidebar/event.jsindex 8ac8b8180..fbdeaea2a 100644--- a/web/js/components/sidebar/event.js+++ b/web/js/components/sidebar/event.js@@ -1,4 +1,4 @@-import React, { useEffect } from 'react';+import React, { useCallback } from 'react';import PropTypes from 'prop-types';import lodashFind from 'lodash/find';import googleTagManager from 'googleTagManager';@@ -16,7 +16,6 @@ function Event (props) {sources,isVisible,} = props;- const ref = React.createRef();const eventDate = util.parseDateUTC(event.geometry[0].date);let dateString = `${util.giveWeekDay(eventDate)}, ${util.giveMonth(eventDate)} ${eventDate.getUTCDate()}`;if (eventDate.getUTCFullYear() !== util.today().getUTCFullYear()) {@@ -29,13 +28,14 @@ function Event (props) {? 'selectorItem item': 'selectorItem item hidden';- useEffect(() => {- if (isSelected) {- ref.current.scrollIntoView();+ const refCallback = useCallback((node) => {+ if (node && isSelected) {+ setTimeout(() => {+ node.scrollIntoView();+ });}}, [isSelected]);-/**** @param {String} date | Date of event clicked@@ -131,7 +131,7 @@ function Event (props) {return (<liid={`sidebar-event-${util.encodeId(event.id)}`}- ref={ref}+ ref={refCallback}className={itemClass}onClick={(e) => {e.stopPropagation();diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 5b7aae397..68d3a9b5d 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -12,7 +12,9 @@ import {requestSources as requestSourcesActionCreator,selectEvent as selectEventActionCreator,deselectEvent as deselectEventActionCreator,+ selectCategory as selectCategoryActionCreator,} from '../../modules/natural-events/actions';+import { ALL_CATEGORY } from '../../modules/natural-events/constants';import { getEventsWithinExtent } from '../../map/natural-events/util';import { collapseSidebar } from '../../modules/sidebar/actions';import { selectDate } from '../../modules/date/actions';@@ -32,6 +34,8 @@ function Events(props) {isLoading,selectEvent,selected,+ selectCategory,+ selectedCategory,prevSelected,visibleWithinMapExtent,visibleEvents,@@ -46,8 +50,7 @@ function Events(props) {const [dropdownOpen, setDropdownOpen] = useState(false);const toggle = () => setDropdownOpen((prevState) => !prevState);- const ALL_CATEGORY = 'All Event Categories';- const [selectedCategory, selectCategory] = useState(ALL_CATEGORY);+const dropdownHeight = 34;const scrollbarMaxHeight = height - dropdownHeight;let showInactiveEventAlert = selected.id && !selected.date;@@ -191,6 +194,9 @@ const mapDispatchToProps = (dispatch) => ({deselectEvent: () => {dispatch(deselectEventActionCreator());},+ selectCategory: (category) => {+ dispatch(selectCategoryActionCreator(category));+ },requestEvents: (url) => {dispatch(requestEventsActionCreator(url));},@@ -207,7 +213,9 @@ const mapStateToProps = (state) => {proj,browser,} = state;- const { selected, prevSelected, showAll } = state.events;+ const {+ selected, prevSelected, showAll, category,+ } = state.events;const apiURL = lodashGet(state, 'config.features.naturalEvents.host');const isLoading = requestedEvents.isLoading|| requestedEventSources.isLoading;@@ -253,6 +261,7 @@ const mapStateToProps = (state) => {config,isMobile: browser.lessThan.medium,selectedDate: getSelectedDate(state).toISOString().split('T')[0],+ selectedCategory: category,};};export default connect(@@ -277,6 +286,8 @@ Events.propTypes = {selected: PropTypes.object,selectedDate: PropTypes.string,selectEvent: PropTypes.func,+ selectCategory: PropTypes.func,+ selectedCategory: PropTypes.string,showAlert: PropTypes.bool,sources: PropTypes.array,visibleEvents: PropTypes.object,diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 30e4e6234..8ae929f00 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -5,6 +5,7 @@ import {SELECT_EVENT,DESELECT_EVENT,SHOW_ALL_EVENTS,+ SELECT_CATEGORY,ONLY_SHOW_VISIBLE,TOGGLE_SHOW_ALL,FINISHED_ANIMATING_TO_EVENT,@@ -55,6 +56,14 @@ export function showAll() {type: SHOW_ALL_EVENTS,};}++export function selectCategory(category) {+ return {+ type: SELECT_CATEGORY,+ category,+ };+}+export function toggleListAll() {return {type: TOGGLE_SHOW_ALL,diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.jsindex 1a1b8a2ff..9d36f7996 100644--- a/web/js/modules/natural-events/constants.js+++ b/web/js/modules/natural-events/constants.js@@ -16,6 +16,9 @@ export const REQUEST_CATEGORIES_SUCCESS = 'EVENTS/REQUEST_CATEGORIES_SUCCESS';export const DESELECT_EVENT = 'EVENTS/DESELECT_EVENT';export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';export const SHOW_ALL_EVENTS = 'EVENTS/SHOW_ALL_EVENTS';+export const SELECT_CATEGORY = 'EVENTS/SELECT_CATEGORY';export const ONLY_SHOW_VISIBLE = 'EVENTS/ONLY_SHOW_VISIBLE';export const TOGGLE_SHOW_ALL = 'EVENTS/TOGGLE_SHOW_ALL';export const FINISHED_ANIMATING_TO_EVENT = 'EVENTS/FINISHED_ANIMATING_TO_EVENT';++export const ALL_CATEGORY = 'All Event Categories';diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex 4e9132fc6..aeb304752 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -4,11 +4,13 @@ import {uniqBy as lodashUniqBy,} from 'lodash';import {+ ALL_CATEGORY,REQUEST_EVENTS,REQUEST_SOURCES,REQUEST_CATEGORIES,SELECT_EVENT,DESELECT_EVENT,+ SELECT_CATEGORY,SHOW_ALL_EVENTS,ONLY_SHOW_VISIBLE,TOGGLE_SHOW_ALL,@@ -55,6 +57,7 @@ export const eventsReducerState = {active: false,showAll: true,isAnimatingToEvent: false,+ category: ALL_CATEGORY,};export function eventsReducer(state = eventsReducerState, action) {@@ -77,6 +80,11 @@ export function eventsReducer(state = eventsReducerState, action) {date: null,},};+ case SELECT_CATEGORY:+ return {+ ...state,+ category: action.category,+ };case SHOW_ALL_EVENTS:return {...state,