import React from "react"; import { connect } from "react-redux"; import { Player } from "video-react"; import marked from "marked"; import MediaOverlay from "./atoms/Media"; // import falogo from "../assets/fa-logo.png"; import bcatlogo from "../assets/bellingcat-logo.png"; const MEDIA_HIDDEN = -2; /** * Manages the presentation of props that come in from the store's app.cover. * These are documented in docs/custom-cover.md. * The component is a bit of a mess, keeping a lot of internal state and using * a couple of weird offset calculations... but it works for the time being. */ class TemplateCover extends React.Component { constructor(props) { super(props); this.state = { video: MEDIA_HIDDEN, featureLang: 0, }; } getVideo(index, headerEndIndex) { if (index < headerEndIndex) { return this.props.cover.headerVideos[index]; } else if (index >= 0) { return this.props.cover.videos[index - headerEndIndex]; } else { return null; } } onVideoClickHandler(index) { const buffer = this.props.cover.headerVideos ? this.props.cover.headerVideos.length : 0; return () => { this.setState({ video: index + buffer, }); }; } renderFeature() { const { featureVideo } = this.props.cover; const { featureLang } = this.state; const { translations } = featureVideo; const source = featureLang === 0 ? featureVideo : { ...translations[featureLang - 1], poster: featureVideo.poster, }; return (
{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}
); } else { return (
this.setState({ featureLang: 0 })} className="trans-button" > ENG
); } })}
); } renderHeaderVideos() { const { headerVideos } = this.props.cover; return (
{headerVideos.slice(0, 2).map((media, index) => (
this.setState({ video: index })} > {media.buttonTitle}
))}
); } renderButton(button, yellow) { return (
{button.title}
); } renderMediaOverlay() { const video = this.getVideo( this.state.video, this.props.cover.headerVideos ? this.props.cover.headerVideos.length : 0 ); return ( this.setState({ video: MEDIA_HIDDEN })} /> ); } render() { if (!this.props.cover) { return (
You haven't specified any cover props. Put them in the values that overwrite the store in app.cover
); } const { videos, footerButton } = this.props.cover; const { showing } = this.props; return (
{/* Forensic Architecture logo */} Bellingcat logo
{this.props.cover.bgVideo ? (
) : null}

{this.props.cover.subtitle ? (

{this.props.cover.subtitle}

) : null} {this.props.cover.subsubtitle ? (
{this.props.cover.subsubtitle}
) : null} {this.props.cover.featureVideo ? this.renderFeature() : null}
{this.props.cover.headerVideos ? this.renderHeaderVideos() : null} {this.props.cover.headerButton ? this.renderButton(this.props.cover.headerButton) : null}
{this.props.cover.exploreButton}
{Array.isArray(this.props.cover.description) ? ( this.props.cover.description.map((e) => (
)) ) : (
)} {videos ? (
{/* NOTE: only take first four videos, drop any others for style reasons */} {videos && videos.slice(0, 2).map((media, index) => (
{media.buttonTitle}
{media.buttonSubtitle}
))}
{videos.length > 2 && this.props.cover.videos.slice(2, 4).map((media, index) => (
{media.buttonTitle}
{media.buttonSubtitle}
))}
) : null} {footerButton ? (
{this.renderButton(footerButton)}
) : null}
{this.state.video !== MEDIA_HIDDEN ? this.renderMediaOverlay() : null}
); } } function mapStateToProps(state) { return { cover: state.app.cover, }; } export default connect(mapStateToProps)(TemplateCover);