diff --git a/src/components/SourceOverlay.jsx b/src/components/SourceOverlay.jsx index ea94e2d..393576c 100644 --- a/src/components/SourceOverlay.jsx +++ b/src/components/SourceOverlay.jsx @@ -6,27 +6,36 @@ import Spinner from './presentational/Spinner' import NoSource from './presentational/NoSource' // TODO: move render functions into presentational components -function SourceOverlay ({ source, onCancel }) { - function renderError() { +class SourceOverlay extends React.Component { + + constructor() { + super() + + this.state = { + idx: 0 + } + } + + renderError() { return ( ) } - function renderImage(path) { + renderImage(path) { return (
} - unloader={} + unloader={} /> ) } - function renderVideo(path) { + renderVideo(path) { // NB: assume only one video return (
@@ -39,26 +48,26 @@ function SourceOverlay ({ source, onCancel }) { ) } - function renderText(path) { + renderText(path) { return (
} - unloader={renderError()} + unloader={() => this.renderError()} />
) } - function renderNoSupport(ext) { + renderNoSupport(ext) { return ( ) } - function toMedia(path) { + toMedia(path) { let type; switch (true) { case /\.(png|jpg)$/.test(path): @@ -73,7 +82,7 @@ function SourceOverlay ({ source, onCancel }) { return { type, path } } - function getTypeCounts(media) { + getTypeCounts(media) { let counts = { Image: 0, Video: 0, Text: 0 } media.forEach(m => { counts[m.type] += 1 @@ -81,21 +90,21 @@ function SourceOverlay ({ source, onCancel }) { return counts } - function _renderPath(media) { + _renderPath(media) { const { path, type } = media switch (type) { case 'Image': - return renderImage(path) + return this.renderImage(path) case 'Video': - return renderVideo(path) + return this.renderVideo(path) case 'Text': - return renderText(path) + return this.renderText(path) default: - return renderNoSupport(path.split('.')[1]) + return this.renderNoSupport(path.split('.')[1]) } } - function _renderCounts(counts) { + _renderCounts(counts) { const strFor = type => counts[type] > 0 ? `${counts[type]} ${type.toLowerCase()}${counts[type] > 1 ? 's': ''}` @@ -113,52 +122,72 @@ function SourceOverlay ({ source, onCancel }) { ) } - function _renderContent(media) { + _renderContent(media) { + const el = document.querySelector(`.source-media-gallery`); + const shiftW = (!!el) ? el.getBoundingClientRect().width : 0; return ( - - {media.map(_renderPath)} - +
+ {media.map((m) => this._renderPath(m))} +
) } - if (typeof(source) !== 'object') { - return renderError() + onShiftGallery(shift) { + if (this.state.idx === 0 && shift === -1) return; + if (this.state.idx - 1 === this.props.source.paths.length && shift === 1) return + this.setState({ idx: this.state.idx+shift }); } - const {id, url, title, paths, date, type, desc} = source - const media = paths.map(toMedia) - const counts = getTypeCounts(media) + _renderControls() { + return ( + +
this.onShiftGallery(-1)}>
+
this.onShiftGallery(1)}>
+
+ ); + } - return ( -
-
{ e.stopPropagation(); }}> -
-
- + render () { + if (typeof(this.props.source) !== 'object') { + return this.renderError() + } + const {id, url, title, paths, date, type, desc} = this.props.source + const media = paths.map(this.toMedia) + const counts = this.getTypeCounts(media) + + return ( +
+
{ e.stopPropagation(); }}> +
+
+ +
+
{this.props.source.title}
-
{source.title}
-
-
- {_renderContent(media)} -
-
-
- {title?

{title}

: null} -
{_renderCounts(counts)}
-
- {type ?

Media type

: null} - {type ?

perm_media{type}

: null} - {date ?

Date

: null} - {date ?

today{date}

: null} - {url ?

Link

: null} - {url ? linkLink to original URL : null} - {desc ?
: null} - {desc ?
{desc}
: null} +
+ {(media.length > 1) ? this._renderControls() : ''} + {this._renderContent(media)} +
+
+
+

{`${this.state.idx+1} / ${paths.length}`}

+ {title?

{title}

: null} +
{this._renderCounts(counts)}
+ {type ?

Media type

: null} + {type ?

perm_media{type}

: null} + {date ?

Date

: null} + {date ?

today{date}

: null} + {url ?

Link

: null} + {url ? linkLink to original URL : null} + {desc ?
: null} + {desc ?
{desc}
: null} +
-
- ) + ) + + } } export default SourceOverlay diff --git a/src/scss/mediaoverlay.scss b/src/scss/mediaoverlay.scss index d48a851..47b2093 100644 --- a/src/scss/mediaoverlay.scss +++ b/src/scss/mediaoverlay.scss @@ -65,6 +65,19 @@ $header-inset: 10px; padding-right: $padding; font-family: "Lato", Helvetica, sans-serif; } + .back, .next { + position: absolute; + width: 30px; + height: 30px; + background: $darkgrey; + color: $offwhite; + cursor: pointer; + box-shadow: 0 19px 19px rgba(0, 0, 0, 0.3), 0 15px 12px rgba(0, 0, 0, 0.22); + svg path { fill: $offwhite; } + } + + .back { left: 10px; svg path { transform: translate(17px,15px)rotate(-90deg)} } + .next { right: 10px; svg path { transform: translate(17px,15px)rotate(90deg)} } } .mo-header { @@ -95,11 +108,16 @@ $header-inset: 10px; .mo-media-container { background-color: rgba(239, 239, 239, 0.9); + flex: 1; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + overflow-x: hidden; box-sizing: border-box; - min-width: 100%; + width: 100%; max-height: 60vh; padding: 20px; - overflow-y: auto; font-family: "Lato", Helvetica, sans-serif; .media-player { @@ -223,16 +241,34 @@ $header-inset: 10px; } } -.source-image-container, .source-text-container { - padding: $padding; - display: inline-block; +.source-media-gallery { + display: flex; + flex-direction: row; + height: 100%; + transition: transform 0.6s ease 0s; +} + +.source-text-container { + padding: 0 10em; + display: flex; + justify-content: center; align-items: center; } +.source-image-container, .media-player { + display: flex; + justify-content: center; + width: calc(100% - 20px); + height: 100%; + min-width: calc(100% - 20px); + margin: 0 10px; + background: $lightwhite; + border-radius: 2px; +} + .source-image, .source-video { max-width: calc(100% - 20px); - max-height: 350px !important; - // height: 100%; + max-height: calc(100% - 20px); padding: 10px; }