Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fix 'show only events in view' checkbox behavior

Jason Kent5cf975bd7cd8
diff --git a/web/js/components/sidebar/events-filter.js b/web/js/components/sidebar/events-filter.js
index 6c82117e8..cfb38bc8b 100644
--- a/web/js/components/sidebar/events-filter.js
+++ b/web/js/components/sidebar/events-filter.js
@@ -33,6 +33,8 @@ function EventsFilter (props) {
const [dateRange, setDateRange] = useState([parsedStartDate, parsedEndDate]);
const [startDate, endDate] = dateRange || [];
+ const [listAll, setListAll] = useState(showAll);
+
const toggleCategory = (category) => {
const isActive = categories.some(({ id }) => id === category.id);
let newCategories;
@@ -44,23 +46,15 @@ function EventsFilter (props) {
setCategories(newCategories);
};
- const toggleListAllCheckbox = () => {
- toggleListAll();
- if (showAll) {
- googleTagManager.pushEvent({
- event: 'natural_events_current_view_only',
- });
- } else {
- googleTagManager.pushEvent({
- event: 'natural_events_show_all',
- });
- }
- };
-
const applyFilter = () => {
const start = startDate && util.toISOStringDate(startDate);
const end = endDate && util.toISOStringDate(endDate);
setFilter(categories, start, end);
+ if (showAll !== listAll) {
+ toggleListAll();
+ const event = showAll ? 'natural_events_show_all' : 'natural_events_current_view_only';
+ googleTagManager.pushEvent({ event });
+ }
closeModal();
};
@@ -136,8 +130,8 @@ function EventsFilter (props) {
<Checkbox
id="events-footer-checkbox"
label="Only list events in current map view"
- onCheck={toggleListAllCheckbox}
- checked={!showAll}
+ onCheck={() => setListAll(!listAll)}
+ checked={!listAll}
/>
<ModalFooter>
@@ -193,6 +187,8 @@ const mapDispatchToProps = (dispatch) => ({
endDate,
),
);
+ },
+ toggleListAll: () => {
dispatch(toggleListAllAction());
},
});
diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.js
index 57fb17dc8..1cac163b9 100644
--- a/web/js/modules/natural-events/actions.js
+++ b/web/js/modules/natural-events/actions.js
@@ -1,6 +1,8 @@
import {
get as lodashGet,
+ isEqual as lodashEqual,
} from 'lodash';
+
import {
REQUEST_EVENTS,
REQUEST_SOURCES,
@@ -55,9 +57,15 @@ export function showAll() {
export function setEventsFilter(categories, startDate, endDate) {
return (dispatch, getState) => {
- const { config, proj } = getState();
+ const { config, proj, events } = getState();
+ const { selectedCategories, selectedDates } = events;
const baseUrl = lodashGet(config, 'features.naturalEvents.host');
const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate, categories, proj);
+ const sameCategories = lodashEqual(selectedCategories, categories);
+ const sameDates = lodashEqual(selectedDates, { start: startDate, end: endDate });
+ if (sameCategories && sameDates) {
+ return;
+ }
dispatch(requestEvents(requestUrl));
dispatch({
type: SET_EVENTS_FILTER,