Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

debug date picker flashing previous props date, WIP

Edward Platob5fe6aef356c
diff --git a/web/js/components/date-selector/date-selector.js b/web/js/components/date-selector/date-selector.js
index cb679e4e4..82eb42166 100644
--- a/web/js/components/date-selector/date-selector.js
+++ b/web/js/components/date-selector/date-selector.js
@@ -1,4 +1,4 @@
-import React, { PureComponent } from 'react';
+import React, { Component } from 'react';
import PropTypes from 'prop-types';
import DateInputColumn from './input';
import util from '../../util/util';
@@ -10,10 +10,7 @@ import util from '../../util/util';
*
* @class TimelineRangeSelector
*/
-class DateSelector extends PureComponent {
- /*
- * @constructor
- */
+class DateSelector extends Component {
constructor(props) {
super(props);
this.state = {
@@ -56,9 +53,29 @@ class DateSelector extends PureComponent {
updateDate(date, type) {
this.props.onDateChange(date, this.props.id);
}
+ shouldComponentUpdate(prevProps, prevState) {
+ let {
+ date,
+ hasSubdailyLayers,
+ maxDate,
+ minDate
+ } = this.props;
+
+ let updateCheck = (
+ this.state.tab === prevState.tab &&
+ date.getTime() === prevProps.date.getTime() &&
+ hasSubdailyLayers === prevProps.hasSubdailyLayers &&
+ maxDate.getTime() === prevProps.maxDate.getTime() &&
+ minDate.getTime() === prevProps.minDate.getTime()
+ );
+ if (updateCheck) {
+ return false;
+ }
+ return true;
+ }
renderSubdaily() {
+ const { date } = this.props;
if (this.props.hasSubdailyLayers) {
- let date = this.props.draggerSelected === 'selectedB' ? this.props.dateB : this.props.date;
return (
<React.Fragment>
<DateInputColumn
@@ -103,19 +120,17 @@ class DateSelector extends PureComponent {
}
render() {
const {
+ date,
maxDate,
minDate,
fontSize,
- idSuffix,
- draggerSelected
+ idSuffix
} = this.props;
- let date = draggerSelected === 'selectedB' ? this.props.dateB : this.props.date;
const { tab } = this.state;
return (
<div className="wv-date-selector-widget">
<DateInputColumn
step={1}
- startDate={new Date(2000)}
date={date}
value={date.getUTCFullYear()}
type="year"
@@ -132,7 +147,6 @@ class DateSelector extends PureComponent {
/>
<DateInputColumn
step={1}
- startDate={new Date(2000)}
date={date}
value={util.monthStringArray[date.getUTCMonth()]}
type="month"
@@ -149,7 +163,6 @@ class DateSelector extends PureComponent {
/>
<DateInputColumn
step={1}
- startDate={new Date(2000)}
date={date}
type="day"
updateDate={this.updateDate}
diff --git a/web/js/components/date-selector/input.js b/web/js/components/date-selector/input.js
index 1f242d74c..18f9c1967 100644
--- a/web/js/components/date-selector/input.js
+++ b/web/js/components/date-selector/input.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { Component } from 'react';
import PropTypes from 'prop-types';
import util from '../../util/util';
@@ -9,10 +9,7 @@ import util from '../../util/util';
*
* @class TimelineRangeSelector
*/
-class DateInputColumn extends React.Component {
- /*
- * @constructor
- */
+class DateInputColumn extends Component {
constructor(props) {
super(props);
this.state = {
@@ -29,14 +26,12 @@ class DateInputColumn extends React.Component {
this.onClickUp = this.onClickUp.bind(this);
this.onClickDown = this.onClickDown.bind(this);
}
- componentDidUpdate(prevProps) {
+ componentDidUpdate(prevProps, prevState) {
if (this.props.focused) {
this.inputs[this.props.tabIndex].focus();
}
if (this.props.value !== prevProps.value) {
- this.setState({
- value: this.props.value
- });
+ this.updateValue();
}
}
componentWillMount() {
@@ -53,6 +48,10 @@ class DateInputColumn extends React.Component {
this.size = size;
}
componentDidMount() {
+ this.updateValue();
+ }
+ // update input value
+ updateValue = () => {
this.setState({
value: this.props.value
});
@@ -115,7 +114,7 @@ class DateInputColumn extends React.Component {
break;
}
if (newDate) {
- this.props.updateDate(newDate, this.props.type, null);
+ this.props.updateDate(newDate, this.props.type);
if (entered) {
if (shiftTab) {
// shift-tabbed - move backward
diff --git a/web/js/components/timeline/timeline-axis/timeline-axis.js b/web/js/components/timeline/timeline-axis/timeline-axis.js
index dc59035c2..1d78b1ed3 100644
--- a/web/js/components/timeline/timeline-axis/timeline-axis.js
+++ b/web/js/components/timeline/timeline-axis/timeline-axis.js
@@ -116,7 +116,6 @@ class TimelineAxis extends Component {
let draggerVisible = false;
let isBetween = getIsBetween(draggerDateActual, frontDate, backDate);
if (isBetween) {
- console.log
draggerPosition = Math.abs(frontDate.diff(draggerDateActual, timeScale, true) * gridWidth);
if (this.props.compareModeActive || this.props.draggerSelected === 'selected') {
draggerVisible = true;
@@ -960,7 +959,7 @@ class TimelineAxis extends Component {
timeScale,
compareModeActive,
hasSubdailyLayers,
- parentOffset,
+ // parentOffset,
timelineEndDateLimit,
transformX,
frontDate,
@@ -975,7 +974,7 @@ class TimelineAxis extends Component {
nextProps.timeScale === timeScale &&
nextProps.compareModeActive === compareModeActive &&
nextProps.hasSubdailyLayers === hasSubdailyLayers &&
- nextProps.parentOffset === parentOffset &&
+ // nextProps.parentOffset === parentOffset &&
nextProps.timelineEndDateLimit === timelineEndDateLimit &&
nextProps.transformX === transformX &&
nextProps.frontDate === frontDate &&
@@ -1106,8 +1105,7 @@ TimelineAxis.propTypes = {
compareModeActive: PropTypes.bool,
draggerSelected: PropTypes.string,
hasSubdailyLayers: PropTypes.bool,
- onChangeSelectedDragger: PropTypes.func,
- parentOffset: PropTypes.number,
+ // parentOffset: PropTypes.number,
dateA: PropTypes.string,
dateB: PropTypes.string,
startDate: PropTypes.string,
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index 03ba6d221..b3f0a3677 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -454,6 +454,7 @@ class Timeline extends React.Component {
// handle draggerTimeState updates if date changes
if (this.props.dateA !== prevProps.dateA && this.props.dateA !== this.state.draggerTimeState) {
+ console.log(this.props.dateA ,prevProps.dateA ,this.state.draggerTimeState)
this.setState({
draggerTimeState: this.props.dateA
});
@@ -502,7 +503,6 @@ class Timeline extends React.Component {
timelineEndDateLimit,
timelineStartDateLimit,
timeScaleChangeUnit,
- parentOffset,
animStartLocationDate,
animEndLocationDate,
isAnimationWidgetOpen,
@@ -510,6 +510,7 @@ class Timeline extends React.Component {
hideTimeline,
timeScale
} = this.props;
+ let selectedDate = draggerSelected === 'selected' ? this.state.draggerTimeState : this.state.draggerTimeStateB;
return this.state.initialLoadComplete ? (
<ErrorBoundary>
<section id="timeline" className="timeline-inner clearfix">
@@ -518,12 +519,8 @@ class Timeline extends React.Component {
>
<div id="date-selector-main">
<DateSelector
- // onDateChange={this.props.changeDate}
onDateChange={this.changeDate}
- // date={new Date(dateA)}
- date={new Date(this.state.draggerTimeState)}
- // dateB={new Date(dateB)}
- dateB={new Date(this.state.draggerTimeStateB)}
+ date={new Date(selectedDate)}
hasSubdailyLayers={hasSubdailyLayers}
draggerSelected={draggerSelected}
maxDate={new Date(timelineEndDateLimit)}
@@ -561,31 +558,22 @@ class Timeline extends React.Component {
>
{/* Timeline */}
<TimelineAxis
-
- frontDate={this.state.frontDate}
- backDate={this.state.backDate}
- // {...this.props}
+ frontDate={this.state.frontDate}
+ backDate={this.state.backDate}
isTimelineDragging={this.state.isTimelineDragging}
moved={this.state.moved}
axisWidth={axisWidth}
dateA={dateA}
dateB={dateB}
- // changeDate={this.props.changeDate}
hasSubdailyLayers={hasSubdailyLayers}
- parentOffset={parentOffset}
changeTimeScale={this.changeTimeScale}
compareModeActive={compareModeActive}
draggerSelected={draggerSelected}
onChangeSelectedDragger={this.onChangeSelectedDragger}
timelineStartDateLimit={timelineStartDateLimit}
timelineEndDateLimit={timelineEndDateLimit}
- // changeAnimStartAndEndDate={this.props.changeStartAndEndDate}
- // changeAnimStartAndEndDate={this.updateAnimationDateAndLocation}
- // changeAnimStartDate={this.props.changeStartDate}
- // changeAnimEndDate={this.props.changeEndDate}
animStartLocationDate={animStartLocationDate}
animEndLocationDate={animEndLocationDate}
- isAnimationWidgetOpen={isAnimationWidgetOpen}
isAnimationDraggerDragging={this.state.isAnimationDraggerDragging}
updateDraggerDatePosition={this.updateDraggerDatePosition}
draggerTimeState={this.state.draggerTimeState}
@@ -602,15 +590,11 @@ class Timeline extends React.Component {
animationStartLocation={this.state.animationStartLocation}
animationEndLocation={this.state.animationEndLocation}
timeScale={timeScale}
- // displayDate={this.displayDate}
showHoverOn={this.showHoverOn}
showHoverOff={this.showHoverOff}
- // toggleShowDraggerTime={this.toggleShowDraggerTime}
showHover={this.showHover}
leftOffset={this.state.leftOffset}
- showDraggerTime={this.state.showDraggerTime}
hoverTime={this.state.hoverTime}
- showHoverLine={this.state.showHoverLine}
isDraggerDragging={this.state.isDraggerDragging}
/>
@@ -664,8 +648,6 @@ class Timeline extends React.Component {
width={axisWidth}
setDraggerVisibility={this.setDraggerVisibility}
toggleShowDraggerTime={this.toggleShowDraggerTime}
- // handleDragDragger={this.handleDragDragger}
- // selectDragger={this.selectDragger}
onChangeSelectedDragger={this.onChangeSelectedDragger}
updateDraggerDatePosition={this.updateDraggerDatePosition}
compareModeActive={compareModeActive}