diff --git a/src/components/presentational/CardSource.js b/src/components/presentational/CardSource.js index b81661e..9eab0af 100644 --- a/src/components/presentational/CardSource.js +++ b/src/components/presentational/CardSource.js @@ -1,11 +1,11 @@ import React from 'react' import PropTypes from 'prop-types' import Spinner from './Spinner' +import Img from 'react-image' import copy from '../../js/data/copy.json' const CardSource = ({ source, isLoading, onClickHandler }) => { - function renderIconText(type) { switch(type) { case 'Eyewitness Testimony': @@ -34,16 +34,31 @@ const CardSource = ({ source, isLoading, onClickHandler }) => { ) } + + let thumbnail = source.thumbnail + if (!thumbnail || thumbnail === '') { + // default to first image in paths, null if no images + const imgs = source.paths.filter(p => p.match(/\.(jpg|png)$/)) + thumbnail = imgs.length > 0 ? imgs[0] : null + } + + console.log(!!thumbnail) + console.log(thumbnail) + return (
{isLoading ? : (
onClickHandler(source)}> - - {renderIconText(source.type)} - -

{source.id}

+ {!!thumbnail ? ( + + ) : ( + + {renderIconText(source.type)} + + )} +

{source.id}

)}
diff --git a/src/reducers/schema/sourceSchema.js b/src/reducers/schema/sourceSchema.js index 1e8730e..c465ba5 100644 --- a/src/reducers/schema/sourceSchema.js +++ b/src/reducers/schema/sourceSchema.js @@ -2,6 +2,7 @@ import Joi from 'joi'; const sourceSchema = Joi.object().keys({ id: Joi.string().required(), + thumbnail: Joi.string().allow(''), paths: Joi.array().required(), type: Joi.string().allow(''), affil_1: Joi.string().allow(''),