From 16d464b49ca6e6050ca3ccb2f18c58ddfafffd84 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Thu, 15 Aug 2019 12:03:24 +0100 Subject: [PATCH] clean up media overlay --- src/components/Overlay/Media.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/Overlay/Media.js b/src/components/Overlay/Media.js index c5d7146..9c28449 100644 --- a/src/components/Overlay/Media.js +++ b/src/components/Overlay/Media.js @@ -3,10 +3,15 @@ import Content from './Content' import Controls from './Controls' import { selectTypeFromPathWithPoster } from '../../common/utilities' +/* + * Inside the SourceOverlay, both the currently displaying media and language + * can be changed by the user. These are both managed in this component's React + * state. + */ class SourceOverlay extends React.Component { constructor () { super() - this.state = { mediaIdx: 0, transIdx: 0 } + this.state = { mediaIdx: 0, langIdx: 0 } this.onShiftGallery = this.onShiftGallery.bind(this) } @@ -28,8 +33,8 @@ class SourceOverlay extends React.Component { this.setState({ mediaIdx: this.state.mediaIdx + shift }) } - switchToTrans (idx) { - this.setState({ transIdx: idx }) + switchLanguage (idx) { + this.setState({ langIdx: idx }) } renderContent (source) { @@ -46,10 +51,10 @@ class SourceOverlay extends React.Component {
{this.props.translations ? this.props.translations.map((trans, idx) => ( - this.state.transIdx !== idx + 1 ? ( -
this.switchToTrans(idx + 1)}>{trans.code}
+ this.state.langIdx !== idx + 1 ? ( +
this.switchLanguage(idx + 1)}>{trans.code}
) : ( -
this.switchToTrans(0)}>EN
+
this.switchLanguage(0)}>EN
) )) : null}
@@ -90,15 +95,20 @@ 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) + } + render () { if (typeof (this.props.source) !== 'object') { return this.renderError() } - const { transIdx } = this.state return (
- {this.renderContent(transIdx === 0 ? this.props.source : this.props.translations[transIdx - 1])} + {this.renderIntlContent()}
) }