Interactive interface for browsing global, full-resolution satellite imagery
Move setState out of tour-in-progress render
ZachTRice632f0b87d5f3
diff --git a/.stylelintignore b/.stylelintignoreindex 2c024e535..56e36b65b 100644--- a/.stylelintignore+++ b/.stylelintignore@@ -1,6 +1,7 @@# /node_modules/* and /bower_components/* ignored by defaultbuild/*+config/*dist/*etc/*lib/*diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.jsindex 5061e475a..67a4a91b8 100644--- a/web/js/components/tour/modal-tour-in-progress.js+++ b/web/js/components/tour/modal-tour-in-progress.js@@ -30,14 +30,27 @@ class ModalInProgress extends React.Component {componentDidUpdate(prevProps) {var currentStory = this.props.currentStory;var currentStepIndex = this.props.currentStep - 1;+ var modalStarted = this.props.modalInProgress;++ // When restarting tour, reset the MetaLoaded prop+ if (this.props.restartTour) {+ this.props.toggleRestartTour();+ }- if (prevProps.currentStep !== this.props.currentStep) {- let prevStepIndex = prevProps.currentStep - 1;+ // Fetch meta and load link+ if (modalStarted && !this.props.metaLoaded) {+ this.props.toggleMetaLoaded();+ this.fetchMetadata(currentStory, 0);+ this.loadLink(currentStory, currentStepIndex);+ } else {+ if (prevProps.currentStep !== this.props.currentStep) {+ let prevStepIndex = prevProps.currentStep - 1;- // Reset the prevStepIndex when a new tour is selected- if (currentStepIndex === 0 && prevStepIndex !== 1) prevStepIndex = null;- this.fetchMetadata(currentStory, currentStepIndex);- this.loadLink(currentStory, currentStepIndex, prevStepIndex);+ // Reset the prevStepIndex when a new tour is selected+ if (currentStepIndex === 0 && prevStepIndex !== 1) prevStepIndex = null;+ this.fetchMetadata(currentStory, currentStepIndex);+ this.loadLink(currentStory, currentStepIndex, prevStepIndex);+ }}}@@ -57,7 +70,8 @@ class ModalInProgress extends React.Component {);let description = isMetadataSnippet ? body : errorMessage;this.setState({ description: description, isLoading: false });- }).catch(error => this.setState({ error, isLoading: false }));+ }+ ).catch(error => this.setState({ error, isLoading: false }));}loadLink(currentStory, currentStepIndex, prevStepIndex) {@@ -348,22 +362,7 @@ class ModalInProgress extends React.Component {}render() {- var { description, metaLoaded } = this.state;- var currentStory = this.props.currentStory;- var modalStarted = this.props.modalInProgress;-- if (this.props.restartTour) {- this.setState({- metaLoaded: false- });- this.props.toggleRestartTour();- }-- if (modalStarted && !metaLoaded) {- this.setState({ metaLoaded: true });- this.fetchMetadata(currentStory, 0);- this.loadLink(currentStory, 0);- }+ var { description } = this.state;return (<div>@@ -399,6 +398,8 @@ ModalInProgress.propTypes = {showTourAlert: PropTypes.func.isRequired,restartTour: PropTypes.bool.isRequired,toggleRestartTour: PropTypes.func.isRequired,+ toggleMetaLoaded: PropTypes.func.isRequired,+ metaLoaded: PropTypes.bool.isRequired,className: PropTypes.string};diff --git a/web/js/components/tour/tour.js b/web/js/components/tour/tour.jsindex 5c829d86a..b8c5e4724 100644--- a/web/js/components/tour/tour.js+++ b/web/js/components/tour/tour.js@@ -24,13 +24,15 @@ class Tour extends React.Component {currentStoryId: props.currentStoryId,showTourAlert: props.showTourAlert,hideTour: props.hideTour,- restartTour: props.restartTour+ restartTour: props.restartTour,+ metaLoaded: props.metaLoaded};this.toggleModalStart = this.toggleModalStart.bind(this);this.toggleModalInProgress = this.toggleModalInProgress.bind(this);this.toggleModalComplete = this.toggleModalComplete.bind(this);this.toggleRestartTour = this.toggleRestartTour.bind(this);+ this.toggleMetaLoaded = this.toggleMetaLoaded.bind(this);this.incrementStep = this.incrementStep.bind(this);this.decreaseStep = this.decreaseStep.bind(this);}@@ -47,6 +49,7 @@ class Tour extends React.Component {this.setState({modalInProgress: !this.state.modalInProgress});+ this.toggleMetaLoaded();}toggleModalComplete(e) {@@ -58,7 +61,14 @@ class Tour extends React.Component {toggleRestartTour() {this.setState({- restartTour: !this.state.restartTour+ restartTour: !this.state.restartTour,+ metaLoaded: false+ });+ }++ toggleMetaLoaded() {+ this.setState({+ metaLoaded: !this.state.metaLoaded});}@@ -110,7 +120,9 @@ class Tour extends React.Component {currentStory={this.state.currentStory}showTourAlert={this.props.showTourAlert}restartTour={this.state.restartTour}+ metaLoaded={this.state.metaLoaded}toggleRestartTour={this.toggleRestartTour}+ toggleMetaLoaded={this.toggleMetaLoaded}></TourInProgress><TourComplete@@ -151,7 +163,8 @@ Tour.propTypes = {showTourAlert: PropTypes.func.isRequired,hideTour: PropTypes.func.isRequired,showTour: PropTypes.func.isRequired,- restartTour: PropTypes.bool.isRequired+ restartTour: PropTypes.bool.isRequired,+ metaLoaded: PropTypes.bool.isRequired};export default Tour;diff --git a/web/js/tour/ui.js b/web/js/tour/ui.jsindex 4a6bdefc0..8f175a7e5 100644--- a/web/js/tour/ui.js+++ b/web/js/tour/ui.js@@ -47,6 +47,7 @@ export function tourUi(models, ui, config) {startTour: self.startTour,resetTour: self.resetTour,restartTour: false,+ metaLoaded: false,selectTour: self.selectTour,showTourAlert: ui.alert.showTourAlert,hideTour: self.hideTour,@@ -134,6 +135,7 @@ export function tourUi(models, ui, config) {currentStoryIndex: currentStoryIndex,modalStart: false,modalInProgress: true,+ metaLoaded: false,modalComplete: false,currentStory: currentStory,currentStoryId: currentStoryId