Skip to content

Commit

Permalink
Merge pull request #1063 from nextstrain/end-of-narrative-block
Browse files Browse the repository at this point in the history
Add "end of narrative" slide to blocks.
  • Loading branch information
jameshadfield authored Apr 19, 2020
2 parents 2e78b0e + 18190a5 commit ce54603
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 46 deletions.
10 changes: 10 additions & 0 deletions src/actions/recomputeReduxState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
20 changes: 6 additions & 14 deletions src/components/narrative/MobileNarrativeDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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 (
<ProgressButton
Expand All @@ -253,14 +247,12 @@ class MobileNarrativeDisplay extends React.Component {

render() {

if (this.state.showingEndOfNarrativePage) {
return this.renderEndOfNarrative();

} else if (this.props.currentInFocusBlockIdx === 0) {
if (this.props.currentInFocusBlockIdx === 0) {
return this.renderStartOfNarrative();
} else if (this.props.currentInFocusBlockIdx !== this.props.blocks.length-1) {
return this.renderMiddleOfNarrative();
}

return this.renderMiddleOfNarrative();
return this.renderEndOfNarrative();
}
}

Expand Down
56 changes: 24 additions & 32 deletions src/components/narrative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,11 @@ const explanationParagraph=`
class Narrative extends React.Component {
constructor(props) {
super(props);
this.state = {showingEndOfNarrativePage: false};
this.exitNarrativeMode = () => {
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({
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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 (<ProgressButton
key={i}
Expand All @@ -136,7 +126,26 @@ class Narrative extends React.Component {
);
}
renderBlocks() {
const ret = this.props.blocks.map((b, i) => {
return this.props.blocks.map((b, i) => {

if (b.isEndOfNarrativeSlide) {
return (
<EndOfNarrative key="EON" id="EndOfNarrative">
<h1>END OF NARRATIVE</h1>
<a style={{...linkStyles}}
onClick={() => this.reactPageScroller.goToPage(0)}
>
Scroll back to the beginning
</a>
<br />
<a style={{...linkStyles}}
onClick={this.exitNarrativeMode}
>
Leave the narrative & explore the data yourself
</a>
</EndOfNarrative>
);
}

const __html = i === 0 ?
explanationParagraph + b.__html : // inject explanation to opening block
Expand All @@ -157,23 +166,6 @@ class Narrative extends React.Component {
/>
);
});
ret.push((
<EndOfNarrative key="EON" id="EndOfNarrative">
<h1>END OF NARRATIVE</h1>
<a style={{...linkStyles}}
onClick={() => this.reactPageScroller.goToPage(0)}
>
Scroll back to the beginning
</a>
<br />
<a style={{...linkStyles}}
onClick={this.exitNarrativeMode}
>
Leave the narrative & explore the data yourself
</a>
</EndOfNarrative>
));
return ret;
}
render() {
if (!this.props.loaded) {return null;}
Expand All @@ -186,7 +178,7 @@ class Narrative extends React.Component {
<OpacityFade position="top" topHeight={narrativeNavBarHeight + progressHeight}/>
<OpacityFade position="bottom"/>
{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}
<ReactPageScroller
ref={(c) => {this.reactPageScroller = c;}}
containerHeight={this.props.height-progressHeight}
Expand Down

0 comments on commit ce54603

Please sign in to comment.