import React from 'react'; import { connect } from 'react-redux' class NarrativeCard extends React.Component { constructor() { super(); this.state = { step: 0 } } goToPrevKeyFrame() { if (this.state.step > 0) { this.setState({ step: this.state.step - 1 }); } } goToNextKeyFrame() { if (this.state.step < this.props.narrative.steps.length - 1) { this.setState({ step: this.state.step + 1 }); } } componentDidUpdate() { if (this.props.narrative !== null) { const step = this.props.narrative.steps[this.state.step]; this.props.onSelect([step]); } } renderClose() { return ( ) } render() { if (this.props.narrative !== null && this.props.narrative.steps[this.state.step]) { const steps = this.props.narrative.steps; const step = steps[this.state.step]; return (
{this.renderClose()}
{this.props.narrative.label}

{this.props.narrative.description}

{this.state.step + 1}/{steps.length}. {step.location}

this.goToPrevKeyFrame()}>←
= this.props.narrative.steps.length - 1) ? 'disabled ' : ''} action`} onClick={() => this.goToNextKeyFrame()}>→
); } return (
); } } function mapStateToProps(state) { return { narrative: state.app.narrative } } export default connect(mapStateToProps)(NarrativeCard);