Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix data-download endless loop #2332

Benjamin King6d1a8d5df2f7
diff --git a/web/js/containers/sidebar/data.js b/web/js/containers/sidebar/data.js
index 02cdf0956..74c4837f9 100644
--- a/web/js/containers/sidebar/data.js
+++ b/web/js/containers/sidebar/data.js
@@ -68,8 +68,7 @@ class Data extends React.Component {
const dataArray = Object.entries(products);
if (dataArray.length > 0 && !selectedProduct && isActive) {
findProductToSelect(activeLayers, selectedProduct);
- }
- if (selectedProduct && !doesSelectedExist(activeLayers, selectedProduct)) {
+ } else if (selectedProduct && !doesSelectedExist(activeLayers, selectedProduct)) {
findProductToSelect(activeLayers, selectedProduct);
}
return (
@@ -124,7 +123,6 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
},
findProductToSelect: (products, selectedProduct) => {
const newSelection = findAvailableProduct(products);
-
if (newSelection) {
dispatch(selectProduct(newSelection));
}
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 7f3421444..75d359719 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import Layers from './layers';
import Events from './events';
import Data from './data';
+import { get as lodashGet } from 'lodash';
import CompareCase from './compare';
import FooterContent from './footer-content';
import { TabContent, TabPane } from 'reactstrap';
@@ -25,7 +26,7 @@ import {
expandSidebar
} from '../../modules/sidebar/actions';
-const getActiveTabs = function(config) {
+const getActiveTabs = function (config) {
const features = config.features;
return {
download: features.dataDownload,
@@ -33,7 +34,7 @@ const getActiveTabs = function(config) {
events: features.naturalEvents
};
};
-const resetWorldview = function(e) {
+const resetWorldview = function (e) {
e.preventDefault();
if (window.location.search === '') return; // Nothing to reset
var msg =
@@ -75,11 +76,11 @@ class Sidebar extends React.Component {
updateDimensions() {
const { subComponentHeight } = this.state;
+ const footerHeight = lodashGet(this, 'footerElement.clientHeight') || 20;
const { isMobile, screenHeight } = this.props;
if (!isMobile && this.iconElement) {
const iconHeight = this.iconElement.clientHeight;
const topOffset = Math.abs(this.iconElement.getBoundingClientRect().top);
- const footerHeight = this.footerElement.clientHeight;
const tabHeight = 32;
const basePadding = 110;
const newHeight =
@@ -96,7 +97,6 @@ class Sidebar extends React.Component {
}
} else {
const tabHeight = 32;
- const footerHeight = this.footerElement.clientHeight;
const newHeight = screenHeight - (tabHeight + footerHeight);
// See note above
if (Math.abs(subComponentHeight - newHeight) > 1) {
@@ -286,7 +286,8 @@ const mapDispatchToProps = dispatch => ({
changeTab: str => {
dispatch(changeTab(str));
},
- onTabClick: str => {
+ onTabClick: (str, activeStr) => {
+ if(str === activeStr) return;
googleTagManager.pushEvent({
event: str + '_tab'
});
diff --git a/web/js/modules/data/actions.js b/web/js/modules/data/actions.js
index 488d1c806..45f320b47 100644
--- a/web/js/modules/data/actions.js
+++ b/web/js/modules/data/actions.js
@@ -8,12 +8,15 @@ import { requestAction } from '../core/actions';
import update from 'immutability-helper';
export function selectProduct(id) {
- return {
- type: SELECT_PRODUCT,
- id: id
- };
+ return (dispatch, getState) => {
+ if (getState().data.selectedProduct !== id) {
+ dispatch({
+ type: SELECT_PRODUCT,
+ id: id
+ });
+ }
+ }
}
-
export function dataQuery(location) {
return (dispatch, getData) => {
return requestAction(dispatch, DATA_QUERY, location, 'application/json');
diff --git a/web/js/modules/sidebar/actions.js b/web/js/modules/sidebar/actions.js
index 6fe70824a..add7d2ebc 100644
--- a/web/js/modules/sidebar/actions.js
+++ b/web/js/modules/sidebar/actions.js
@@ -9,10 +9,14 @@ import {
} from './constants';
export function changeTab(str) {
- return {
- type: CHANGE_TAB,
- activeTab: str
- };
+ return (dispatch, getState) => {
+ if (getState().sidebar.activeTab !== str) {
+ dispatch({
+ type: CHANGE_TAB,
+ activeTab: str
+ });
+ }
+ }
}
export function toggleSidebarCollapse(str) {
return (dispatch, getState) => {