import React, { Component } from 'react' import { connect } from 'react-redux' import { timestampToSeconds } from 'app/utils' import { getSection } from 'app/utils/viewer.utils' import actions from 'app/actions' class ViewerRouter extends Component { componentDidMount() { this.route() } route() { // console.log(this.props.match.params.component) const { component } = this.props.match.params if (component.match('section_')) { const sectionParts = component.split('_') const sectionIndex = parseInt(sectionParts[1]) - 1 actions.viewer.seekToSection(getSection(sectionIndex)) const seek_ts = timestampToSeconds(sectionParts[2]) if (seek_ts) { actions.audio.jump(seek_ts) } return } if (component.match('timestamp_')) { const timestampParts = component.split('_') actions.viewer.seekToTimestamp(timestampToSeconds(timestampParts[1])) return } switch (this.props.match.params.component) { case 'transcript': actions.viewer.showComponent('transcript') break case 'nav': actions.viewer.showComponent('nav') break case 'checklist': actions.viewer.showComponent('checklist') break case 'carousel': actions.viewer.seekToSection(getSection(1)) break case 'vitrine': actions.viewer.seekToSection(getSection(2)) break case 'gallery': actions.viewer.seekToSection(getSection(3)) break case 'video': actions.viewer.seekToSection(getSection(4)) break case 'credits': actions.viewer.showCredits() break case 'footnotes': actions.viewer.showComponent('footnotes') break case 'subscribe': actions.viewer.showComponent('nav') actions.viewer.showNavComponent('subscribe') break case 'share': actions.viewer.showComponent('nav') actions.viewer.showNavComponent('share') break case 'textplate': actions.viewer.seekToTimestamp(timestampToSeconds('44:39')) break case 'book': actions.viewer.seekToTimestamp(timestampToSeconds('15:00')) break case 'end': break } } render() { return null } } const mapStateToProps = state => ({ viewer: state.viewer, }) export default connect(mapStateToProps)(ViewerRouter)