import copy from '../js/data/copy.json' import { isNotNullNorUndefined, parseDate, formatterWithYear } from '../js/utilities' import React from 'react' import Spinner from './presentational/Spinner' import CardTimestamp from './presentational/Card/Timestamp' import CardLocation from './presentational/Card/Location' import CardCaret from './presentational/Card/Caret' import CardTags from './presentational/Card/Tags' import CardSummary from './presentational/Card/Summary' import CardSource from './presentational/Card/Source' import CardCategory from './presentational/Card/Category' import CardNarrative from './presentational/Card/Narrative' class Card extends React.Component { constructor(props) { super(props) this.state = { isOpen: false } } toggle() { this.setState({ isOpen: !this.state.isOpen }) } makeTimelabel(timestamp) { 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) return null // return ( // // ) } renderSummary() { return ( ) } renderTags() { if (!this.props.tags || (this.props.tags && this.props.tags.length === 0)) { return null } return ( ) } renderLocation() { return ( ) } renderSources() { if (this.props.sourceError) { return
ERROR: something went wrong loading sources, TODO:
} const source_lang = copy[this.props.language].cardstack.sources return (

{source_lang}:

{this.props.event.sources.map(source => ( this.props.onViewSource(source)} /> ))}
) } // 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.onSelect([event])} makeTimelabel={(timestamp) => this.makeTimelabel(timestamp)} next={links.next} prev={links.prev} /> ) } } renderMain() { return (
{this.renderTimestamp()} {this.renderLocation()}
{this.renderCategory()} {this.renderSummary()}
) } renderExtra() { return (
{this.renderTags()} {this.renderSources()} {this.renderNarrative()}
) } renderCaret() { return ( this.toggle()} isOpen={this.state.isOpen} /> ) } render() { const { isSelected } = this.props return (
  • {this.renderMain()} {this.state.isOpen ? this.renderExtra() : null} {isSelected ? this.renderCaret() : null}
  • ) } } export default Card