import copy from '../js/data/copy.json'; import {isNotNullNorUndefined} from '../js/data/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'; class Card extends React.Component { constructor(props) { super(props); this.state = { isHighlighted: false }; } toggle() { this.setState({ isHighlighted: !this.state.isHighlighted }, () => { if (this.state.isHighlighted) { this.props.highlight(this.props.event); } else { this.props.highlight(); } }); } getCategoryColorClass(category) { if (category) return this.props.getCategoryGroup(category); return 'other'; } makeTimelabel(timestamp) { if (timestamp === null) return null; const parsedTimestamp = this.props.tools.parser(timestamp); const timelabel = this.props.tools.formatterWithYear(parsedTimestamp); return timelabel; } renderCategory() { const categoryTitle = copy[this.props.language].cardstack.category; const colorType = this.getCategoryColorClass(this.props.event.category); const categoryLabel = this.props.getCategoryLabel(this.props.event.category); return ( ); } renderSummary() { return ( ) } renderTags() { return ( ) } renderLocation() { return ( ) } renderSource() { return ( ) } // NB: should be internaionalized. renderTimestamp() { return ( this.makeTimelabel(timestamp)} language={this.props.language} timestamp={this.props.event.timestamp} /> ); } renderNarrative() { const links = this.props.getNarrativeLinks(this.props.event); if (links !== null) { return ( this.props.select([event])} makeTimelabel={(timestamp) => this.makeTimelabel(timestamp)} next={links.next} prev={links.prev} /> ) } } renderLoadingCard() { return (
  • ); } renderHeader() { return (
    {this.renderCategory()} {this.renderTimestamp()} {this.renderSummary()}
    ); } renderContent() { if (!this.state.isHighlighted) { return (
    ); } else { return (
    {this.renderLocation()} {this.renderTags()} {this.renderSource()} {this.renderNarrative()}
    ); } } renderCaret() { return ( this.toggle()} isHighlighted={this.state.isHighlighted} /> ) } render() { if (this.props.isLoading) { return this.renderLoadingCard(); } else { return (
  • {this.renderHeader()} {this.renderContent()} {this.renderCaret()}
  • ); } } } export default Card;