import React, { Component } from 'react' import { Route } from 'react-router-dom' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { history } from 'site/store' import actions from 'site/actions' import { Loader } from 'app/common/loader.component' import TileHandle from 'app/views/page/components/tile.handle' import 'app/views/page/page.css' class ViewerContainer extends Component { state = { page: {}, bounds: { width: window.innerWidth, height: window.innerHeight }, roadblock: false, } constructor(props) { super(props) this.pageRef = React.createRef() this.handleMouseDown = this.handleMouseDown.bind(this) this.handleResize = this.handleResize.bind(this) this.removeRoadblock = this.removeRoadblock.bind(this) window.addEventListener('resize', this.handleResize) } componentDidUpdate(prevProps) { // console.log('didUpdate', this.props.graph !== prevProps.graph, this.props.location.pathname !== prevProps.location.pathname) if (this.props.graph !== prevProps.graph || this.props.location.pathname !== prevProps.location.pathname) { this.load() } } componentWillUnmount() { window.removeEventListener('resize', this.handleResize) actions.site.interact() } handleResize() { this.setState({ bounds: { width: window.innerWidth, height: window.innerHeight, } }) } load() { const { graph_name, page_name } = this.props.match.params const page_path = ["", graph_name, page_name].join('/') const { pages, home_page } = this.props.graph const page = pages[page_path] || pages[home_page] if (!this.props.interactive && hasAutoplay(page)) { this.setState({ page, roadblock: true }) } else { this.setState({ page, roadblock: false }) actions.site.interact() this.props.audio.player.playPage(page) } } handleMouseDown(e, tile) { console.log(tile) if (tile.href.indexOf('http') === 0) { window.location.href = tile.href } else { history.push(tile.href) } } render() { const { page, audio } = this.state if (this.state.roadblock) { return this.renderRoadblock() } if (this.props.graph.loading || !page.id) { return (
) } const { settings } = page const pageStyle = { backgroundColor: settings ? settings.background_color : '#000000' } // console.log(page) return (
{page.tiles.map(tile => { return ( this.handleMouseDown(e, tile)} onDoubleClick={e => {}} /> ) })}
) } removeRoadblock() { console.log("remove roadblock") actions.site.interact() this.setState({ roadblock: false }) this.props.audio.player.playPage(this.state.page) } renderRoadblock() { const { title } = this.props.graph return (

{title}

) } } const hasAutoplay = page => { const hasAutoplayVideo = page.tiles.some(tile => { return tile.type === 'video' && !tile.settings.muted }) const hasAutoplayAudio = page.settings.background_audio_id > 0 return hasAutoplayAudio || hasAutoplayVideo } const mapStateToProps = state => ({ site: state.site, audio: state.audio, graph: state.site.graph, interactive: state.site.interactive, }) const mapDispatchToProps = dispatch => ({ }) export default connect(mapStateToProps, mapDispatchToProps)(ViewerContainer)