diff --git a/src/components/Card.jsx b/src/components/Card.jsx index ee269d5..7829616 100644 --- a/src/components/Card.jsx +++ b/src/components/Card.jsx @@ -1,28 +1,28 @@ -import copy from '../js/data/copy.json'; +import copy from '../js/data/copy.json' import { isNotNullNorUndefined, parseDate, formatterWithYear -} from '../js/utilities'; -import React from 'react'; +} from '../js/utilities' +import React from 'react' -import Spinner from './presentational/Spinner'; -import CardTimestamp from './presentational/CardTimestamp'; -import CardLocation from './presentational/CardLocation'; -import CardCaret from './presentational/CardCaret'; -import CardTags from './presentational/CardTags'; -import CardSummary from './presentational/CardSummary'; -import CardSource from './presentational/CardSource'; -import CardCategory from './presentational/CardCategory'; -import CardNarrative from './presentational/CardNarrative'; +import Spinner from './presentational/Spinner' +import CardTimestamp from './presentational/CardTimestamp' +import CardLocation from './presentational/CardLocation' +import CardCaret from './presentational/CardCaret' +import CardTags from './presentational/CardTags' +import CardSummary from './presentational/CardSummary' +import CardSource from './presentational/CardSource' +import CardCategory from './presentational/CardCategory' +import CardNarrative from './presentational/CardNarrative' class Card extends React.Component { constructor(props) { - super(props); + super(props) this.state = { isHighlighted: false - }; + } } toggle() { @@ -30,24 +30,24 @@ class Card extends React.Component { isHighlighted: !this.state.isHighlighted }, () => { if (!this.state.isHighlighted) { - this.props.onHighlight(this.props.event); + this.props.onHighlight(this.props.event) } else { - this.props.onHighlight(null); + this.props.onHighlight(null) } - }); + }) } makeTimelabel(timestamp) { - if (timestamp === null) return null; - const parsedTimestamp = parseDate(timestamp); - const timelabel = formatterWithYear(parsedTimestamp); - return timelabel; + if (timestamp === null) return null + const parsedTimestamp = parseDate(timestamp) + const timelabel = formatterWithYear(parsedTimestamp) + return timelabel } renderCategory() { - const categoryTitle = copy[this.props.language].cardstack.category; - const categoryLabel = this.props.event.category; - const color = this.props.getCategoryColor(this.props.event.category); + const categoryTitle = copy[this.props.language].cardstack.category + const categoryLabel = this.props.event.category + const color = this.props.getCategoryColor(this.props.event.category) return ( - ); + ) } renderSummary() { @@ -117,11 +117,11 @@ class Card extends React.Component { language={this.props.language} timestamp={this.props.event.timestamp} /> - ); + ) } renderNarrative() { - const links = this.props.getNarrativeLinks(this.props.event); + const links = this.props.getNarrativeLinks(this.props.event) if (links !== null) { @@ -147,7 +147,7 @@ class Card extends React.Component {
{this.renderSummary()} - ); + ) } renderContent() { @@ -180,8 +180,8 @@ class Card extends React.Component { {this.renderContent()} {this.renderCaret()} - ); + ) } } -export default Card; +export default Card diff --git a/src/components/CardStack.jsx b/src/components/CardStack.jsx index 6c04976..f25e68a 100644 --- a/src/components/CardStack.jsx +++ b/src/components/CardStack.jsx @@ -1,44 +1,47 @@ -import React from 'react'; +import React from 'react' import { connect } from 'react-redux' import * as selectors from '../selectors' -import Card from './Card.jsx'; -import copy from '../js/data/copy.json'; +import Card from './Card.jsx' +import copy from '../js/data/copy.json' import { isNotNullNorUndefined -} from '../js/utilities.js'; +} from '../js/utilities.js' class CardStack extends React.Component { - - constructor(props) { - super(props); + renderCards(events) { + return events.map(event => ( + + )) } - renderCards() { - if (this.props.selected.length > 0) { - return this.props.selected.map((event) => { - return ( - - ); - }); + renderSelectedCards() { + const { selected } = this.props + if (selected.length > 0) { + return this.renderCards(selected) } - return ''; + return null + } + + renderNarrativeCards() { + const { narrative } = this.props + return this.renderCards(narrative.steps) } renderCardStackHeader() { - const header_lang = copy[this.props.language].cardstack.header; + const header_lang = copy[this.props.language].cardstack.header return (
    - {this.renderCards()} + {this.renderSelectedCards()}
- ); + ) + } + + renderNarrativeContent() { + return ( +
+
    + {this.renderNarrativeCards()} +
+
+ ) } render() { - const { isCardstack, isNarrative, selected } = this.props + const { isCardstack, selected, narrative } = this.props + if (selected.length > 0) { - return ( -
- {this.renderCardStackHeader()} - {this.renderCardStackContent()} -
- ); + } + > + {this.renderCardStackHeader()} + {this.renderCardStackContent()} + + ) + } else { + return ( +
+ {this.renderNarrativeContent()} +
+ ) + } } - return
; + + return
} } function mapStateToProps(state) { return { + narrative: selectors.selectActiveNarrative(state), selected: selectors.selectSelected(state), sourceError: state.app.errors.source, language: state.app.language, diff --git a/src/components/Dashboard.jsx b/src/components/Dashboard.jsx index 370de79..abc68c2 100644 --- a/src/components/Dashboard.jsx +++ b/src/components/Dashboard.jsx @@ -127,7 +127,6 @@ class Dashboard extends React.Component { }} />