import React from 'react' import marked from 'marked' 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, langIdx: 0 } this.onShiftGallery = this.onShiftGallery.bind(this) } getTypeCounts (media) { return media.reduce( (acc, vl) => { acc[vl.type] += 1 return acc }, { Image: 0, Video: 0, Text: 0 } ) } onShiftGallery (shift) { // no more left if (this.state.mediaIdx === 0 && shift === -1) return // no more right if (this.state.mediaIdx === this.props.source.paths.length - 1 && shift === 1) return this.setState({ mediaIdx: this.state.mediaIdx + shift }) } switchLanguage (idx) { this.setState({ langIdx: idx }) } renderContent (source) { const { url, title, paths, date, type, poster, description } = source const shortenedTitle = title.substring(0, 100) return (
close

{shortenedTitle}

e.stopPropagation()}>
this.switchLanguage(lang)} translations={this.props.translations} langIdx={this.state.langIdx} media={paths.map(p => selectTypeFromPathWithPoster(p, poster))} viewIdx={this.state.mediaIdx} />
{description ?
: null} {(type || date || url) ? (
{type ?

Evidence type

: null} {type ?

perm_media{type}

: null}
{date ?

Date Published

: null} {date ?

today{date}

: null}
{url ?

Link

: null} {url ? linkLink to original URL : null}
) : null}
) } renderIntlContent () { const { langIdx } = this.state 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 () { if (typeof (this.props.source) !== 'object') { return this.renderError() } return (
{this.renderIntlContent()}
) } } export default SourceOverlay