cleaner declaration for cover translations

This commit is contained in:
Lachlan Kermode
2019-08-16 16:43:18 +01:00
parent a6b69ff61d
commit c1c0f40be1
2 changed files with 25 additions and 4 deletions

View File

@@ -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 () {

View File

@@ -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 (
<div>
<div className='banner-trans right-overlay'>
{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 <div onClick={() => this.setState({ featureLang: langIdx })} className='trans-button'>{trans.code}</div>