render sources collectively in card

This commit is contained in:
Lachlan Kermode
2018-12-14 12:01:09 +00:00
parent e350a0c60f
commit f53c8e0225
3 changed files with 34 additions and 27 deletions

View File

@@ -87,16 +87,23 @@ class Card extends React.Component {
}
renderSources() {
return this.props.event.sources.map(source => (
<CardSource
isLoading={this.props.isLoading}
language={this.props.language}
source={{
...source,
error: this.props.sourceError
}}
/>
))
if (this.props.sourceError) {
return <div>ERROR: something went wrong loading sources, TODO:</div>
}
const source_lang = copy[this.props.language].cardstack.sources
return (
<div>
<h4>{source_lang}: </h4>
{this.props.event.sources.map(source => (
<CardSource
isLoading={this.props.isLoading}
language={this.props.language}
source={source}
/>
))}
</div>
)
}
// NB: should be internaionalized.

View File

@@ -3,28 +3,28 @@ import Spinner from './Spinner'
import copy from '../../js/data/copy.json'
function renderSource(source) {
return source.error ? (
<div><small>{source.error}</small></div>
) : (
<div>
<p>{source.id}</p>
</div>
)
}
const CardSource = ({ source, language, isLoading, error }) => {
const source_lang = copy[language].cardstack.source
function renderContent() {
return isLoading
? <Spinner/>
: renderSource(source)
if (isLoading) {
return <Spinner/>
} else if (source.error) {
return (
<div><small>{source.error}</small></div>
)
} else {
/* source with no errors */
return (
<div>
<p>{source.id}</p>
<i className="material-icons md-36">photo</i>
</div>
)
}
}
return (
<div className="card-row card-cell source">
<h4>{source_lang}: </h4>
{renderContent()}
</div>
)

View File

@@ -63,7 +63,7 @@
"incident_type": "Tipo de acción",
"description": "Hechos",
"people": "Personas en el evento",
"source": "Fuente",
"sources": "Fuentes",
"category": "Según el testimonio de",
"communication": "Comunicación",
"transmitter": "Transmisor",
@@ -138,7 +138,7 @@
"description": "Summary",
"tags": "Tags",
"notags": "No known tags for this event.",
"source": "Source",
"sources": "Sources",
"unknown_source": "The information for this source could not be retrieved.",
"category": "Category",
"communication": "Communication",