Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Pass dynamic JSON data to children components

ZachTRice070dbe01d8ea
diff --git a/web/css/tour.css b/web/css/tour.css
index e512deae4..c205e6b42 100644
--- a/web/css/tour.css
+++ b/web/css/tour.css
@@ -207,6 +207,7 @@
.tour-in-progress .modal-content {
min-width: 248px;
+ max-height: 357px;
background-color: rgba(255, 255, 255, 0.85);
border-radius: 8px 0 0 8px;
}
diff --git a/web/js/components/tour/modal-in-progress.js b/web/js/components/tour/modal-in-progress.js
index c9d8f202d..6bc870ca3 100644
--- a/web/js/components/tour/modal-in-progress.js
+++ b/web/js/components/tour/modal-in-progress.js
@@ -19,25 +19,28 @@ class ModalInProgress extends React.Component {
}
componentDidMount() {
- let step = this.props.steps;
- this.fetchMetadata(step);
+ var tourId = this.props.tourId;
+ var stepIndex = this.props.steps;
+ this.fetchMetadata(tourId, stepIndex);
}
componentWillReceiveProps(nextProps) {
+ var tourIndex = this.props.tourIndex;
+ var tourId = this.props.tourId;
if (nextProps.steps !== this.props.steps) {
- let step = nextProps.steps;
- this.fetchMetadata(step);
- this.stepLink(step);
+ var stepIndex = nextProps.steps;
+ this.fetchMetadata(tourId, stepIndex);
+ this.stepLink(tourIndex, stepIndex);
}
}
- fetchMetadata(step) {
- step = step.toString().padStart(3, '0');
+ fetchMetadata(tourId, stepIndex) {
+ stepIndex = stepIndex.toString().padStart(3, '0');
this.setState({ isLoading: true });
var { origin, pathname } = window.location;
var errorMessage = '<p>There was an error loading this description.</p>';
- var uri = `${origin}${pathname}stories/larsen_c_ice_shelf_iceberg_a68a_july_2017/step${step}.html`;
+ var uri = `${origin}${pathname}stories/${tourId}/step${stepIndex}.html`;
fetch(uri)
.then(res => (res.ok ? res.text() : errorMessage))
.then(body => {
@@ -51,10 +54,10 @@ class ModalInProgress extends React.Component {
}).catch(error => this.setState({ error, isLoading: false }));
}
- stepLink(step) {
+ stepLink(tourIndex, stepIndex) {
var models, config, ui, stepLink, state, projection, layersA, layersB, timeA, timeB, view, zoom, comparisonOn;
- step = (step - 1).toString().padStart(0, '0');
- stepLink = this.props.data[0].steps[`${step}`].stepLink;
+ stepIndex = (stepIndex - 1).toString().padStart(0, '0');
+ stepLink = this.props.tourSteps[`${stepIndex}`].stepLink;
models = this.props.models;
config = this.props.config;
ui = this.props.ui;
@@ -69,7 +72,6 @@ class ModalInProgress extends React.Component {
);
}
state = util.fromQueryString(location.search);
- // console.log(state);
comparisonOn = state.ca;
timeA = state.t;
timeB = state.t1;
@@ -126,17 +128,17 @@ class ModalInProgress extends React.Component {
render() {
var { description, metaLoaded } = this.state;
-
+ var tourIndex = this.props.tourIndex;
var modalStarted = this.props.modalInProgress;
if (modalStarted && !metaLoaded) {
this.setState({ metaLoaded: true });
- this.stepLink(1);
+ this.stepLink(tourIndex, 1);
}
return (
<div>
- <Modal isOpen={this.props.modalInProgress} toggle={this.props.toggleModalInProgress} wrapClassName='tour tour-in-progress' className={this.props.className + ' iceberg'} backdrop={false}>
- <ModalHeader toggle={this.props.toggleModalInProgress} charCode="">{this.state.title}<i className="modal-icon" aria-hidden="true"></i></ModalHeader>
+ <Modal isOpen={this.props.modalInProgress} toggle={this.props.toggleModalInProgress} wrapClassName='tour tour-in-progress' className={this.props.className + ' ' + this.props.tourType} backdrop={false}>
+ <ModalHeader toggle={this.props.toggleModalInProgress} charCode="">{this.props.tourTitle}<i className="modal-icon" aria-hidden="true"></i></ModalHeader>
<ModalBody>
<div dangerouslySetInnerHTML={{ __html: description }} />
</ModalBody>
diff --git a/web/js/components/tour/modal-start.js b/web/js/components/tour/modal-start.js
index 8a3ef8313..ed92121b3 100644
--- a/web/js/components/tour/modal-start.js
+++ b/web/js/components/tour/modal-start.js
@@ -5,21 +5,17 @@ import TourBoxes from './tour-boxes';
class ModalStart extends React.Component {
render() {
- if (this.props.data) {
- return (
- <div>
- <Modal isOpen={this.props.modalStart} toggle={this.props.toggleModalStart} wrapClassName='tour tour-start' className={this.props.className} backdrop={true}>
- <ModalHeader toggle={this.props.toggleModalStart} charCode="">Welcome to Worldview!</ModalHeader>
- <ModalBody>
- <TourIntro toggleModalStart={this.props.toggleModalStart}></TourIntro>
- <TourBoxes data={this.props.data} startTour={this.props.startTour}></TourBoxes>
- </ModalBody>
- </Modal>
- </div>
- );
- } else {
- return null;
- }
+ return (
+ <div>
+ <Modal isOpen={this.props.modalStart} toggle={this.props.toggleModalStart} wrapClassName='tour tour-start' className={this.props.className} backdrop={true}>
+ <ModalHeader toggle={this.props.toggleModalStart} charCode="">Welcome to Worldview!</ModalHeader>
+ <ModalBody>
+ <TourIntro toggleModalStart={this.props.toggleModalStart}></TourIntro>
+ <TourBoxes data={this.props.data} startTour={this.props.startTour}></TourBoxes>
+ </ModalBody>
+ </Modal>
+ </div>
+ );
}
}
diff --git a/web/js/components/tour/tour.js b/web/js/components/tour/tour.js
index f053f4f11..838cdf8f2 100644
--- a/web/js/components/tour/tour.js
+++ b/web/js/components/tour/tour.js
@@ -17,7 +17,8 @@ class Tour extends React.Component {
steps: 1,
totalSteps: 10,
isLoading: false,
- error: null
+ error: null,
+ tourIndex: 0
};
this.toggleModalStart = this.toggleModalStart.bind(this);
@@ -29,7 +30,7 @@ class Tour extends React.Component {
this.decreaseStep = this.decreaseStep.bind(this);
}
- async componentDidMount() {
+ async componentWillMount() {
try {
const response = await fetch('../stories/stories.json');
if (!response.ok) {
@@ -63,11 +64,11 @@ class Tour extends React.Component {
});
}
- startTour(event, color) {
- event.preventDefault();
- console.log(color);
+ startTour(e, tourIndex) {
+ e.preventDefault();
this.setState({
steps: 1,
+ tourIndex: tourIndex,
modalStart: false,
modalInProgress: true,
modalComplete: false
@@ -97,41 +98,50 @@ class Tour extends React.Component {
}
render() {
- return (
- <div>
- <TourStart
- data={this.state.data}
- modalStart={this.state.modalStart}
- toggleModalStart={this.toggleModalStart}
- toggleModalInProgress={this.toggleModalInProgress}
- toggleModalComplete={this.toggleModalComplete}
- startTour={this.startTour}
- ></TourStart>
+ if (this.state.data) {
+ return (
+ <div>
+ <TourStart
+ data={this.state.data}
+ modalStart={this.state.modalStart}
+ toggleModalStart={this.toggleModalStart}
+ toggleModalInProgress={this.toggleModalInProgress}
+ toggleModalComplete={this.toggleModalComplete}
+ startTour={this.startTour}
+ ></TourStart>
- <TourInProgress
- models={this.state.models}
- config={this.state.config}
- ui={this.state.ui}
- data={this.state.data}
- modalInProgress={this.state.modalInProgress}
- toggleModalStart={this.toggleModalStart}
- toggleModalInProgress={this.toggleModalInProgress}
- toggleModalComplete={this.toggleModalComplete}
- startTour={this.startTour} steps={this.state.steps}
- totalSteps={this.state.totalSteps}
- incrementStep={this.incrementStep}
- decreaseStep={this.decreaseStep}
- ></TourInProgress>
+ <TourInProgress
+ models={this.state.models}
+ config={this.state.config}
+ ui={this.state.ui}
+ modalInProgress={this.state.modalInProgress}
+ toggleModalStart={this.toggleModalStart}
+ toggleModalInProgress={this.toggleModalInProgress}
+ toggleModalComplete={this.toggleModalComplete}
+ startTour={this.startTour}
+ steps={this.state.steps}
+ totalSteps={this.state.totalSteps}
+ incrementStep={this.incrementStep}
+ decreaseStep={this.decreaseStep}
+ tourIndex={this.state.tourIndex}
+ tourId={this.state.data[this.state.tourIndex].id}
+ tourType={this.state.data[this.state.tourIndex].type}
+ tourTitle={this.state.data[this.state.tourIndex].title}
+ tourSteps={this.state.data[this.state.tourIndex].steps}
+ ></TourInProgress>
- <TourComplete
- modalComplete={this.state.modalComplete}
- toggleModalStart={this.toggleModalStart}
- toggleModalInProgress={this.toggleModalInProgress}
- toggleModalComplete={this.toggleModalComplete}
- restartTour={this.restartTour}
- ></TourComplete>
- </div>
- );
+ <TourComplete
+ modalComplete={this.state.modalComplete}
+ toggleModalStart={this.toggleModalStart}
+ toggleModalInProgress={this.toggleModalInProgress}
+ toggleModalComplete={this.toggleModalComplete}
+ restartTour={this.restartTour}
+ ></TourComplete>
+ </div>
+ );
+ } else {
+ return null;
+ }
}
}