Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

wire up custom interval modal open/close state to redux store

Jason Kent68cd6b92c2ed
diff --git a/web/js/components/timeline/custom-interval-selector/interval-selector-widget.js b/web/js/components/timeline/custom-interval-selector/interval-selector-widget.js
index 58d2cdfe0..01d8b8eb5 100644
--- a/web/js/components/timeline/custom-interval-selector/interval-selector-widget.js
+++ b/web/js/components/timeline/custom-interval-selector/interval-selector-widget.js
@@ -6,6 +6,8 @@ import {
timeScaleFromNumberKey,
timeScaleToNumberKey
} from '../../../modules/date/constants';
+import { toggleCustomModal } from '../../../modules/date/actions';
+import { connect } from 'react-redux';
/*
* CustomIntervalSelectorWidget for Custom Interval Selector
@@ -27,9 +29,6 @@ class CustomIntervalSelectorWidget extends PureComponent {
this.props.toggleCustomIntervalModal();
}
}
- closeCustomIntervalModal = () => {
- this.props.toggleCustomIntervalModal(false);
- }
componentDidUpdate(prevProps) {
// handle focus widget on opening
if (this.props.customIntervalModalOpen && !prevProps.customIntervalModalOpen) {
@@ -41,7 +40,8 @@ class CustomIntervalSelectorWidget extends PureComponent {
customIntervalModalOpen,
hasSubdailyLayers,
customDelta,
- customIntervalZoomLevel
+ customIntervalZoomLevel,
+ closeModal
} = this.props;
return customIntervalModalOpen && (
<div
@@ -62,12 +62,23 @@ class CustomIntervalSelectorWidget extends PureComponent {
changeZoomLevel={this.changeZoomLevel}
/>
</div>
- <i className="fa fa-times wv-close" onClick={this.closeCustomIntervalModal}/>
+ <i className="fa fa-times wv-close" onClick={closeModal}/>
</div>
);
}
}
+const mapDispatchToProps = (dispatch) => ({
+ closeModal: () => {
+ dispatch(toggleCustomModal(false, undefined));
+ }
+});
+
+export default connect(
+ null,
+ mapDispatchToProps
+)(CustomIntervalSelectorWidget);
+
CustomIntervalSelectorWidget.propTypes = {
changeCustomInterval: PropTypes.func,
customDelta: PropTypes.number,
@@ -76,5 +87,3 @@ CustomIntervalSelectorWidget.propTypes = {
hasSubdailyLayers: PropTypes.bool,
toggleCustomIntervalModal: PropTypes.func
};
-
-export default CustomIntervalSelectorWidget;
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index a73700fb6..1d91767ac 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -17,11 +17,17 @@ import CustomIntervalSelectorWidget from '../components/timeline/custom-interval
import PlayQueue from '../components/animation-widget/play-queue';
import { Notify } from '../components/image-download/notify';
import { promiseImageryForTime } from '../modules/map/selectors';
-import { selectDate, selectInterval, changeCustomInterval } from '../modules/date/actions';
import GifContainer from './gif';
+import {
+ selectDate,
+ selectInterval,
+ changeCustomInterval,
+ toggleCustomModal
+} from '../modules/date/actions';
import {
timeScaleFromNumberKey,
- timeScaleToNumberKey
+ timeScaleToNumberKey,
+ customModalType
} from '../modules/date/constants';
import { getQueueLength, getMaxQueueLength } from '../modules/animation/util';
import {
@@ -246,15 +252,14 @@ class AnimationWidget extends React.Component {
};
}
/**
- * @desc Toggle showing the custom interval modal
- * @param {Boolean} isOpen
- * @returns {void}
- */
- toggleCustomIntervalModal = (isOpen) => {
- this.setState({
- customIntervalModalOpen: isOpen
- });
- };
+ * @desc show/hide custom interval modal
+ * @param {Boolean} isOpen
+ * @returns {void}
+ */
+ toggleCustomIntervalModal = (isOpen) => {
+ const { toggleCustomModal } = this.props;
+ toggleCustomModal(isOpen, customModalType.ANIMATION);
+ };
/**
* @desc handle SET of custom time scale panel
* @param {Number} delta
@@ -266,7 +271,6 @@ class AnimationWidget extends React.Component {
};
render() {
- const { customIntervalModalOpen } = this.state;
const {
looping,
isPlaying,
@@ -292,6 +296,7 @@ class AnimationWidget extends React.Component {
customSelected,
customDelta,
customInterval,
+ animationCustomModalOpen,
hasSubdailyLayers
} = this.props;
if (!isActive) {
@@ -420,8 +425,7 @@ class AnimationWidget extends React.Component {
<CustomIntervalSelectorWidget
customDelta={customDelta}
customIntervalZoomLevel={customInterval}
- toggleCustomIntervalModal={this.toggleCustomIntervalModal}
- customIntervalModalOpen={customIntervalModalOpen}
+ customIntervalModalOpen={animationCustomModalOpen}
changeCustomInterval={this.changeCustomInterval}
hasSubdailyLayers={hasSubdailyLayers}
/>
@@ -446,7 +450,15 @@ function mapStateToProps(state) {
browser
} = state;
let { startDate, endDate, speed, loop, isPlaying, isActive, gifActive } = animation;
- let { customSelected, interval, delta, customInterval, customDelta, appNow } = date;
+ let {
+ customSelected,
+ interval,
+ delta,
+ customInterval,
+ customDelta,
+ appNow,
+ animationCustomModalOpen
+ } = date;
const activeStr = compare.activeString;
const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
const hasSubdailyLayers = hasSubDailySelector(layers[activeStr]);
@@ -477,6 +489,7 @@ function mapStateToProps(state) {
const subDailyMode = subDailyInterval && hasSubdailyLayers;
return {
+ animationCustomModalOpen,
customSelected,
startDate,
endDate,
@@ -554,6 +567,9 @@ const mapDispatchToProps = dispatch => ({
toggleGif: () => {
dispatch(toggleComponentGifActive());
},
+ toggleCustomModal: (open, toggleBy) => {
+ dispatch(toggleCustomModal(open, toggleBy));
+ },
onSlide: num => {
dispatch(changeFrameRate(num));
},
@@ -585,6 +601,7 @@ RangeHandle.propTypes = {
value: PropTypes.number
};
AnimationWidget.propTypes = {
+ animationCustomModalOpen: PropTypes.bool,
changeCustomInterval: PropTypes.func,
currentDate: PropTypes.object,
customDelta: PropTypes.number,
@@ -623,5 +640,6 @@ AnimationWidget.propTypes = {
speed: PropTypes.number,
startDate: PropTypes.object,
subDailyMode: PropTypes.bool,
+ toggleCustomModal: PropTypes.func,
toggleGif: PropTypes.func
};
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index ec00bda89..8a5493802 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -40,7 +40,8 @@ import {
changeTimeScale,
selectInterval,
changeCustomInterval,
- updateAppNow
+ updateAppNow,
+ toggleCustomModal
} from '../../modules/date/actions';
import { toggleActiveCompareState } from '../../modules/compare/actions';
import {
@@ -53,7 +54,8 @@ import {
import {
timeScaleFromNumberKey,
timeScaleToNumberKey,
- timeScaleOptions
+ timeScaleOptions,
+ customModalType
} from '../../modules/date/constants';
const ANIMATION_DELAY = 500;
@@ -90,7 +92,6 @@ class Timeline extends React.Component {
initialLoadComplete: false,
timelineHidden: false,
hasMoved: false,
- customIntervalModalOpen: false,
rangeSelectorMax: { end: false, start: false, startOffset: -50, width: 50000 }
};
// left/right arrows
@@ -412,9 +413,8 @@ class Timeline extends React.Component {
* @returns {void}
*/
toggleCustomIntervalModal = (isOpen) => {
- this.setState({
- customIntervalModalOpen: isOpen
- });
+ const { toggleCustomModal } = this.props;
+ toggleCustomModal(isOpen, customModalType.TIMELINE);
};
/**
@@ -790,7 +790,8 @@ class Timeline extends React.Component {
toggleActiveCompareState,
parentOffset,
isTourActive,
- isDataDownload
+ isDataDownload,
+ timelineCustomModalOpen
} = this.props;
let {
initialLoadComplete,
@@ -815,7 +816,6 @@ class Timeline extends React.Component {
isTimelineDragging,
isDraggerDragging,
isAnimationDraggerDragging,
- customIntervalModalOpen,
showHoverLine,
showDraggerTime,
hoverLinePosition,
@@ -1013,9 +1013,8 @@ class Timeline extends React.Component {
<CustomIntervalSelectorWidget
customDelta={customIntervalValue}
customIntervalZoomLevel={customIntervalZoomLevel}
- toggleCustomIntervalModal={this.toggleCustomIntervalModal}
- customIntervalModalOpen={customIntervalModalOpen}
changeCustomInterval={this.changeCustomInterval}
+ customIntervalModalOpen={timelineCustomModalOpen}
hasSubdailyLayers={hasSubdailyLayers}
/>
</div>
@@ -1066,7 +1065,8 @@ function mapStateToProps(state) {
delta,
customInterval,
customDelta,
- appNow
+ appNow,
+ timelineCustomModalOpen
} = date;
const { screenWidth, lessThan } = browser;
const { isCompareA, activeString } = compare;
@@ -1155,7 +1155,8 @@ function mapStateToProps(state) {
compare.active,
isDataDownload: sidebar.activeTab === 'download',
isAnimationPlaying: animation.isPlaying,
- isGifActive: animation.gifActive
+ isGifActive: animation.gifActive,
+ timelineCustomModalOpen
};
}
@@ -1180,6 +1181,9 @@ const mapDispatchToProps = dispatch => ({
selectInterval: (delta, timeScale, customSelected) => {
dispatch(selectInterval(delta, timeScale, customSelected));
},
+ toggleCustomModal: (open, toggleBy) => {
+ dispatch(toggleCustomModal(open, toggleBy));
+ },
openAnimation: () => {
dispatch(openAnimation());
},
@@ -1245,11 +1249,13 @@ Timeline.propTypes = {
selectedDate: PropTypes.object,
selectInterval: PropTypes.func,
startDate: PropTypes.string,
+ timelineCustomModalOpen: PropTypes.bool,
timelineEndDateLimit: PropTypes.string,
timelineStartDateLimit: PropTypes.string,
timeScale: PropTypes.string,
timeScaleChangeUnit: PropTypes.string,
toggleActiveCompareState: PropTypes.func,
+ toggleCustomModal: PropTypes.func,
updateAppNow: PropTypes.func
};
diff --git a/web/js/modules/date/actions.js b/web/js/modules/date/actions.js
index 825c0d52a..aa8ab8c07 100644
--- a/web/js/modules/date/actions.js
+++ b/web/js/modules/date/actions.js
@@ -3,7 +3,8 @@ import {
CHANGE_CUSTOM_INTERVAL,
CHANGE_INTERVAL,
SELECT_DATE,
- UPDATE_APP_NOW
+ UPDATE_APP_NOW,
+ TOGGLE_CUSTOM_MODAL
} from './constants';
export function changeTimeScale(num) {
@@ -45,3 +46,10 @@ export function selectInterval(delta, interval, customSelected) {
customSelected
};
}
+export function toggleCustomModal(open, toggleBy) {
+ return {
+ type: TOGGLE_CUSTOM_MODAL,
+ value: open,
+ toggleBy
+ };
+}
diff --git a/web/js/modules/date/constants.js b/web/js/modules/date/constants.js
index 3dac7bc73..0e583874a 100644
--- a/web/js/modules/date/constants.js
+++ b/web/js/modules/date/constants.js
@@ -3,6 +3,7 @@ export const CHANGE_INTERVAL = 'DATE/CHANGE_INTERVAL';
export const CHANGE_TIME_SCALE = 'DATE/CHANGE_TIME_SCALE';
export const SELECT_DATE = 'DATE/SELECT_DATE';
export const UPDATE_APP_NOW = 'DATE/UPDATE_APP_NOW';
+export const TOGGLE_CUSTOM_MODAL = 'DATE/TOGGLE_CUSTOM_MODAL';
export const timeScaleFromNumberKey = {
'0': 'custom',
@@ -64,3 +65,7 @@ export const timeScaleOptions = {
}
}
};
+export const customModalType = {
+ TIMELINE: 'timeline',
+ ANIMATION: 'animation'
+};
diff --git a/web/js/modules/date/reducers.js b/web/js/modules/date/reducers.js
index 5cb5581a9..6bf91d085 100644
--- a/web/js/modules/date/reducers.js
+++ b/web/js/modules/date/reducers.js
@@ -3,7 +3,9 @@ import {
CHANGE_CUSTOM_INTERVAL,
CHANGE_INTERVAL,
SELECT_DATE,
- UPDATE_APP_NOW
+ UPDATE_APP_NOW,
+ TOGGLE_CUSTOM_MODAL,
+ customModalType
} from './constants';
import util from '../../util/util';
import { assign as lodashAssign } from 'lodash';
@@ -15,6 +17,8 @@ export const dateReducerState = {
customSelected: false,
customDelta: undefined,
customInterval: undefined,
+ timelineCustomModalOpen: false,
+ animationCustomModalOpen: false,
testNow: undefined
};
@@ -48,6 +52,13 @@ export function dateReducer(state = dateReducerState, action) {
return lodashAssign({}, state, {
[action.activeString]: action.value
});
+ case TOGGLE_CUSTOM_MODAL:
+ const timelineToggle = action.toggleBy === customModalType.TIMELINE;
+ const animationToggle = action.toggleBy === customModalType.ANIMATION;
+ return lodashAssign({}, state, {
+ timelineCustomModalOpen: animationToggle ? false : action.value,
+ animationCustomModalOpen: timelineToggle ? false : action.value
+ });
case UPDATE_APP_NOW:
return lodashAssign({}, state, {
appNow: action.value