From 43a861ca6f9396041b61d18d9e596ad37a5d16be Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Thu, 3 Jan 2019 12:30:20 +0000 Subject: [PATCH] describe contents of source in overlay --- src/components/Dashboard.jsx | 11 +++++ src/components/SourceOverlay.jsx | 71 +++++++++++++++++++++++------ src/reducers/schema/sourceSchema.js | 1 + src/scss/mediaoverlay.scss | 3 +- 4 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/components/Dashboard.jsx b/src/components/Dashboard.jsx index d734de0..11263d6 100644 --- a/src/components/Dashboard.jsx +++ b/src/components/Dashboard.jsx @@ -154,7 +154,18 @@ function mapDispatchToProps(dispatch) { }; } +function injectSource(id) { + return state => ({ + ...state, + app: { + ...state.app, + source: state.domain.sources[id] + } + }) +} + export default connect( state => state, + // injectSource('src7'), mapDispatchToProps, )(Dashboard); diff --git a/src/components/SourceOverlay.jsx b/src/components/SourceOverlay.jsx index e5a79f6..02f40bf 100644 --- a/src/components/SourceOverlay.jsx +++ b/src/components/SourceOverlay.jsx @@ -64,24 +64,65 @@ function SourceOverlay ({ source, onCancel }) { ) } - function _renderPath(path) { + function toMedia(path) { + let type; switch (true) { case /\.(png|jpg)$/.test(path): - return renderImage(path) + type = 'Image'; break case /\.(mp4)$/.test(path): - return renderVideo(path) + type = 'Video'; break case /\.(md)$/.test(path): + type = 'Text'; break + default: + type = 'Unknown'; break + } + return { type, path } + } + + function getTypeCounts(media) { + let counts = { Image: 0, Video: 0, Text: 0 } + media.forEach(m => { + counts[m.type] += 1 + }) + return counts + } + + function _renderPath(media) { + const { path, type } = media + switch (type) { + case 'Image': + return renderImage(path) + case 'Video': + return renderVideo(path) + case 'Text': return renderText(path) default: - console.log('unsupported extension') return renderNoSupport(path.split('.')[1]) } } - function _renderContent() { + function _renderCounts(counts) { + const strFor = type => + counts[type] > 0 ? + `${counts[type]} ${type.toLowerCase()}${counts[type] > 1 ? 's': ''}` + : '' + const img = strFor('Image') + const vid = strFor('Video') + const txt = strFor('Text') + + return ( +
+ {img ? `${img}, `: ''} + {(vid && txt) ? `${vid}, `: vid} + {txt} +
+ ) + } + + function _renderContent(media) { return ( - {source.paths.map(_renderPath)} + {media.map(_renderPath)} ) } @@ -89,7 +130,11 @@ function SourceOverlay ({ source, onCancel }) { if (typeof(source) !== 'object') { return renderError() } - const {id, url, title, date, type, affil_1, affil_2} = source + const {id, url, title, paths, date, type, desc} = source + const media = paths.map(toMedia) + const counts = getTypeCounts(media) + + return (
@@ -97,20 +142,20 @@ function SourceOverlay ({ source, onCancel }) {
-
{source.id}
+
{source.title}
- {_renderContent()} + {_renderContent(media)}
- {id ?
{id}
: null} {title?
{title}
: null} -
- {type ?
Type: {type}
: null} +
{_renderCounts(counts)}
+ {type ?
{type}
: null} {date ?
Date:{date}
: null} -
{url ?
Link to original URL
: null} +
+ {desc ?
{desc}
: null}
diff --git a/src/reducers/schema/sourceSchema.js b/src/reducers/schema/sourceSchema.js index c465ba5..523bf9d 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(), + title: Joi.string().allow(''), thumbnail: Joi.string().allow(''), paths: Joi.array().required(), type: Joi.string().allow(''), diff --git a/src/scss/mediaoverlay.scss b/src/scss/mediaoverlay.scss index 891280f..ebc4a62 100644 --- a/src/scss/mediaoverlay.scss +++ b/src/scss/mediaoverlay.scss @@ -157,7 +157,6 @@ $header-inset: 10px; .source-image-container { padding: 0 25px; - height: 100%; display: flex; justify-content: center; align-items: center; @@ -166,7 +165,7 @@ $header-inset: 10px; .source-image, .source-video { max-width: calc(100% - 20px); max-height: 350px !important; - height: 100%; + // height: 100%; padding: 10px; }