From c1c0f40be126b223358cceac29cff9cf356a7997 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Fri, 16 Aug 2019 16:43:18 +0100 Subject: [PATCH] cleaner declaration for cover translations --- src/components/Overlay/Media.js | 18 ++++++++++++++++-- src/components/TemplateCover.js | 11 +++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/Overlay/Media.js b/src/components/Overlay/Media.js index e9a2cb1..c22ddd4 100644 --- a/src/components/Overlay/Media.js +++ b/src/components/Overlay/Media.js @@ -94,8 +94,22 @@ class SourceOverlay extends React.Component { renderIntlContent () { const { langIdx } = this.state - const source = langIdx === 0 ? this.props.source : this.props.translations[langIdx - 1] - return this.renderContent(source) + const { translations, source } = this.props + let translated = null + if (translations && translations.length && langIdx > 0) { + translated = translations[langIdx - 1] + } + if (translated) { + translated = { + ...translated, + poster: source.poster, + // NOTE: this is to allow a slightly nicer syntax when using the Media + // overlay in cover videos. + paths: translated.file ? [translated.file] : translated.paths + } + } + + return this.renderContent(langIdx === 0 ? source : translated) } render () { diff --git a/src/components/TemplateCover.js b/src/components/TemplateCover.js index ae360a3..aa5e45e 100644 --- a/src/components/TemplateCover.js +++ b/src/components/TemplateCover.js @@ -43,11 +43,18 @@ class TemplateCover extends React.Component { renderFeature () { const { featureVideo } = this.props.cover const { featureLang } = this.state - const source = featureLang === 0 ? featureVideo : featureVideo.translations[featureLang - 1] + const { translations } = featureVideo + const source = featureLang === 0 + ? featureVideo + : { + ...translations[featureLang - 1], + poster: featureVideo.poster + } + return (
- {featureVideo.translations && featureVideo.translations.map((trans, idx) => { + {translations && translations.map((trans, idx) => { const langIdx = idx + 1 // default lang idx is 0 if (featureLang !== langIdx) { return
this.setState({ featureLang: langIdx })} className='trans-button'>{trans.code}