Interactive interface for browsing global, full-resolution satellite imagery
categories in requests
Jason Kentaecf2e0060b9
diff --git a/web/js/components/sidebar/events-filter.js b/web/js/components/sidebar/events-filter.jsindex a87e866bf..dd7cd3a11 100644--- a/web/js/components/sidebar/events-filter.js+++ b/web/js/components/sidebar/events-filter.js@@ -22,13 +22,13 @@ function EventsFilter (props) {const [allNone, setAllNone] = useState(!!selectedCategories.length);const [categories, setCategories] = useState(selectedCategories);- const toggleCategory = (categoryTitle) => {- const isActive = categories.includes(categoryTitle);+ const toggleCategory = (category) => {+ const isActive = categories.some(({ id }) => id === category.id);let newCategories;if (isActive) {- newCategories = categories.filter((category) => category !== categoryTitle);+ newCategories = categories.filter(({ id }) => id !== category.id);} else {- newCategories = [categoryTitle].concat(categories);+ newCategories = [category].concat(categories);}setCategories(newCategories);};@@ -42,7 +42,7 @@ function EventsFilter (props) {if (allNone) {setCategories([]);} else {- setCategories(eventCategories.map(({ title }) => title));+ setCategories(eventCategories);}setAllNone(!allNone);};@@ -81,7 +81,7 @@ function EventsFilter (props) {{eventCategories.map((category) => {const { id, title, description } = category;const switchId = `${id}-switch`;- const isActive = categories.includes(title);+ const isActive = categories.some((c) => c.title === title);return (<Switchid={switchId}@@ -89,7 +89,7 @@ function EventsFilter (props) {label={title}active={isActive}tooltip={description}- toggle={() => toggleCategory(title)}+ toggle={() => toggleCategory(category)}/>);})}diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 7711ff4ed..097258c4f 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -68,8 +68,8 @@ function Events(props) {</div><div className="filter-icons">- {selectedCategories.map((category) => (- <EventIcon id="filter-" category={category} title={category} />+ {selectedCategories.map(({ title }) => (+ <EventIcon id="filter-" category={title} title={title} />))}</div></div>@@ -213,8 +213,8 @@ const mapStateToProps = (state, ownProps) => {isEmbedModeActive,isAnimatingToEvent: events.isAnimatingToEvent,selectedCategories,- selectedStartDate: util.toISOStringDate(new Date(selectedStartDate)),- selectedEndDate: util.toISOStringDate(new Date(selectedEndDate)),+ selectedStartDate: util.toISOStringDate(selectedStartDate),+ selectedEndDate: util.toISOStringDate(selectedEndDate),selectedDate: util.toISOStringDate(getSelectedDate(state)),};};diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.jsindex 3acfd1e8f..bbe7d2891 100644--- a/web/js/map/natural-events/util.js+++ b/web/js/map/natural-events/util.js@@ -7,14 +7,18 @@ import { getCenter, boundingExtent, containsCoordinate } from 'ol/extent';import moment from 'moment';import util from '../../util/util';-export function getEventsRequestURL (baseUrl, startDate, endDate) {+export function getEventsRequestURL (baseUrl, startDate, endDate, categories = []) {const params = {status: 'all',+ limit: 50,};if (startDate && endDate) {params.start = moment.utc(startDate).format('YYYY-MM-DD');params.end = moment.utc(endDate).format('YYYY-MM-DD');}+ if (categories.length) {+ params.category = categories.map(({ id }) => id).join(',');+ }return `${baseUrl}/events${util.toQueryString(params)}`;}diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsindex 3ceee502a..6acb3c50e 100644--- a/web/js/modules/core/actions.js+++ b/web/js/modules/core/actions.js@@ -5,6 +5,7 @@ export function requestAction(mimeType,id,options,+ state,) {dispatch(startRequest(actionName, id));return new Promise((resolve, reject) => fetch(url, options)@@ -13,7 +14,7 @@ export function requestAction(: response.text())).then((data) => {- dispatch(fetchSuccess(actionName, data, id));+ dispatch(fetchSuccess(actionName, data, id, state));resolve(data);}).catch((error) => {@@ -32,12 +33,13 @@ export function startRequest(actionName, id) {export function fetchSuccess(actionName, response, id) {return (dispatch, getState) => {const state = getState();- dispatch({+ const action = {type: `${actionName}_SUCCESS`,response,...!!id && { id },- state,- });+ };+ if (state) action.state = state;+ dispatch(action);};}diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex 5758bf448..f992fc482 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -1,6 +1,7 @@import {get as lodashGet,} from 'lodash';+import { _ } from 'core-js';import {REQUEST_EVENTS,REQUEST_SOURCES,@@ -35,12 +36,18 @@ export function requestSources(location) {}export function requestCategories(location) {- return (dispatch) => requestAction(- dispatch,- REQUEST_CATEGORIES,- location,- 'application/json',- );+ return (dispatch, getState) => {+ const state = getState();+ return requestAction(+ dispatch,+ REQUEST_CATEGORIES,+ location,+ 'application/json',+ null,+ null,+ state,+ );+ };}export function selectEvent(id, eventDate) {@@ -67,7 +74,7 @@ export function setEventsFilter(categories, startDate, endDate) {return (dispatch, getState) => {const { config } = getState();const baseUrl = lodashGet(config, 'features.naturalEvents.host');- const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate);+ const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate, categories);dispatch(requestEvents(requestUrl));dispatch({type: SET_EVENTS_FILTER,diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex c8f66d382..8de404d19 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -26,9 +26,8 @@ import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../sidebar/constants';* @param {*} categories* @returns*/-const sortEvents = function(events, categories) {+const sortEvents = function(events) {return events- .filter((e) => e.categories.some(({ title }) => categories.includes(title))).map((e) => {e.geometry = lodashOrderBy(e.geometry, 'date', 'desc');// Discard duplicate geometry dates@@ -70,7 +69,7 @@ export const eventsReducerState = {showAll: true,isAnimatingToEvent: false,selectedCategories: [],- selectedStartDate: new Date().setDate(endDate.getDate() - 60),+ selectedStartDate: new Date(new Date().setDate(endDate.getDate() - 60)),selectedEndDate: new Date(),};@@ -100,8 +99,7 @@ export function eventsReducer(state = eventsReducerState, action) {return {...state,selectedCategories: categories- .filter(({ title }) => !skipCategories.includes(title))- .map(({ title }) => title),+ .filter(({ title }) => !skipCategories.includes(title)),};}