diff --git a/src/actions/recomputeReduxState.js b/src/actions/recomputeReduxState.js index d613cdb43..0a4583630 100644 --- a/src/actions/recomputeReduxState.js +++ b/src/actions/recomputeReduxState.js @@ -703,6 +703,7 @@ export const createStateFromQueryOrJSONs = ({ only displaying the page number (e.g. ?n=3), but we can look up what (hidden) URL query this page defines via this information */ if (narrativeBlocks) { + addEndOfNarrativeBlock(narrativeBlocks); narrative = narrativeBlocks; let n = parseInt(query.n, 10) || 0; /* If the query has defined a block which doesn't exist then default to n=0 */ @@ -830,3 +831,12 @@ export const createTreeTooState = ({ // } return {tree, treeToo, controls}; }; + +function addEndOfNarrativeBlock(narrativeBlocks) { + const lastContentSlide = narrativeBlocks[narrativeBlocks.length-1]; + const endOfNarrativeSlide = Object.assign({}, lastContentSlide, { + __html: undefined, + isEndOfNarrativeSlide: true + }); + narrativeBlocks.push(endOfNarrativeSlide); +} diff --git a/src/components/narrative/MobileNarrativeDisplay.js b/src/components/narrative/MobileNarrativeDisplay.js index 4e8fcee38..65cc4b5ec 100644 --- a/src/components/narrative/MobileNarrativeDisplay.js +++ b/src/components/narrative/MobileNarrativeDisplay.js @@ -55,7 +55,6 @@ class MobileNarrativeDisplay extends React.Component { constructor(props) { super(props); this.state = { - showingEndOfNarrativePage: false, bannerHeight: BANNER_HEIGHT, contentHeight: window.innerHeight - 2*BANNER_HEIGHT }; @@ -65,11 +64,8 @@ class MobileNarrativeDisplay extends React.Component { }; this.goToNextPage = () => { - if (this.state.showingEndOfNarrativePage) return; // no-op - if (this.props.currentInFocusBlockIdx+1 === this.props.blocks.length) { - this.setState({showingEndOfNarrativePage: true}); - return; + return; // no-op } this._goToPage(this.props.currentInFocusBlockIdx+1); @@ -81,7 +77,6 @@ class MobileNarrativeDisplay extends React.Component { }; this._goToPage = (idx) => { - this.setState({ showingEndOfNarrativePage: false }); // TODO: this `if` statement should be moved to the `changePage` function or similar if (this.props.blocks[idx] && this.props.blocks[idx].mainDisplayMarkdown) { @@ -237,8 +232,7 @@ class MobileNarrativeDisplay extends React.Component { style={{height: `${progressHeight}px`}} > {this.props.blocks.map((b, i) => { - const d = (!this.state.showingEndOfNarrativePage) && - this.props.currentInFocusBlockIdx === i ? + const d = this.props.currentInFocusBlockIdx === i ? "14px" : "6px"; return ( { this.props.dispatch(changePage({ path: this.props.blocks[0].dataset, query: true })); }; this.changeAppStateViaBlock = (reactPageScrollerIdx) => { - const idx = reactPageScrollerIdx-1; - if (idx === this.props.blocks.length) { - this.setState({showingEndOfNarrativePage: true}); - return; - } - - if (this.state.showingEndOfNarrativePage) { - this.setState({showingEndOfNarrativePage: false}); - } + const idx = reactPageScrollerIdx-1; // now same coords as `blockIdx` if (this.props.blocks[idx].mainDisplayMarkdown) { this.props.dispatch(EXPERIMENTAL_showMainDisplayMarkdown({ @@ -72,7 +63,7 @@ class Narrative extends React.Component { }; this.goToNextSlide = () => { - if (this.state.showingEndOfNarrativePage) return; // no-op + if (this.props.currentInFocusBlockIdx === this.props.blocks.length-1) return; // no-op this.reactPageScroller.goToPage(this.props.currentInFocusBlockIdx+1); }; this.goToPreviousSlide = () => { @@ -123,8 +114,7 @@ class Narrative extends React.Component { role="navigation" > {this.props.blocks.map((b, i) => { - const d = (!this.state.showingEndOfNarrativePage) && - this.props.currentInFocusBlockIdx === i ? + const d = this.props.currentInFocusBlockIdx === i ? "14px" : "6px"; return ( { + return this.props.blocks.map((b, i) => { + + if (b.isEndOfNarrativeSlide) { + return ( + +

END OF NARRATIVE

+ this.reactPageScroller.goToPage(0)} + > + Scroll back to the beginning + +
+ + Leave the narrative & explore the data yourself + +
+ ); + } const __html = i === 0 ? explanationParagraph + b.__html : // inject explanation to opening block @@ -157,23 +166,6 @@ class Narrative extends React.Component { /> ); }); - ret.push(( - -

END OF NARRATIVE

- this.reactPageScroller.goToPage(0)} - > - Scroll back to the beginning - -
- - Leave the narrative & explore the data yourself - -
- )); - return ret; } render() { if (!this.props.loaded) {return null;} @@ -186,7 +178,7 @@ class Narrative extends React.Component { {this.props.currentInFocusBlockIdx !== 0 ? this.renderChevron(true) : null} - {!this.state.showingEndOfNarrativePage ? this.renderChevron(false) : null} + {this.props.currentInFocusBlockIdx !== this.props.blocks.length-1 ? this.renderChevron(false) : null} {this.reactPageScroller = c;}} containerHeight={this.props.height-progressHeight}