import copy from '../common/data/copy.json' import React from 'react' import CardCustomField from './presentational/Card/CustomField' import CardTime from './presentational/Card/Time' import CardLocation from './presentational/Card/Location' import CardCaret from './presentational/Card/Caret' import CardSummary from './presentational/Card/Summary' import CardSource from './presentational/Card/Source' import { makeNiceDate } from '../common/utilities' class Card extends React.Component { constructor (props) { super(props) this.state = { isOpen: false } } toggle () { this.setState({ isOpen: !this.state.isOpen }) } makeTimelabel (datetime) { return makeNiceDate(datetime) } handleCardSelect (e) { if (!e.target.className.includes('arrow-down')) { const selectedEventFormat = this.props.idx > 0 ? [this.props.event] : this.props.event this.props.onSelect(selectedEventFormat, this.props.idx) } } renderSummary () { return ( ) } renderLocation () { return ( ) } renderSources () { if (this.props.sourceError) { return
ERROR: something went wrong loading sources, TODO:
} const sourceLang = copy[this.props.language].cardstack.sources return (

{sourceLang}:

{this.props.event.sources.map(source => ( this.props.onViewSource(source)} /> ))}
) } // NB: should be internaionalized. renderTime () { let timelabel = this.makeTimelabel(this.props.event.datetime) // let precision = this.props.event.time_display // if (precision === '_date_only') { // precision = '' // timelabel = timelabel.substring(0, 11) // } else if (precision === '_approximate_date_only') { // precision = ' (Approximate date)' // timelabel = timelabel.substring(0, 11) // } else if (precision === '_approximate_datetime') { // precision = ' (Approximate datetime)' // } else { // timelabel = timelabel.substring(0, 11) // } return ( ) } renderCustomFields () { return this.props.features.CUSTOM_EVENT_FIELDS .map(field => { const value = this.props.event[field.key] return value ? ( ) : null }) } renderMain () { return (
{this.renderTime()} {this.renderLocation()}
{this.renderSummary()} {this.renderCustomFields()}
) } renderExtra () { return (
{this.renderSources()}
) } renderCaret () { return this.props.features.USE_SOURCES ? ( this.toggle()} isOpen={this.state.isOpen} /> ) : null } render () { const { isSelected, idx } = this.props return (
  • this.handleCardSelect(e)} > {this.renderMain()} {this.state.isOpen ? this.renderExtra() : null} {this.renderCaret()}
  • ) } } // The ref to each card will be used in CardStack for programmatic scrolling export default React.forwardRef((props, ref) => )