summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/viewer/nav/eflux.chrome.js
blob: a7f6d24ffe21ce6816e3134f9ae5d582dab6ce70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React, { Component } from 'react'
import { connect } from 'react-redux'

import {
  EfluxLogo, EfluxClose, EfluxMenu
} from './eflux.icons'
import { PlayButton } from './viewer.icons'
import actions from 'app/actions'

const PLAY_MESSAGES = {
  not_started: 'Start the Exhibition',
  playing: 'Pause',
  paused: 'Resume',
}

class EfluxChrome extends Component {
  state = {
    eflux: false,
    play: false,
    transcript: false,
    started: false,
    playMessage: PLAY_MESSAGES.not_started,
  }
  handleMouseEnter(category) {
    this.setState({ [category]: true })
  }
  handleMouseLeave(category) {
    this.setState({ [category]: false })
  }
  componentDidUpdate(prevProps) {
    if (this.props.playing !== prevProps.playing) {
      if (!this.state.started) {
        this.setState({
          started: true,
          play: false,
        })
        setTimeout(() => {
          this.setState({
            playMessage: this.props.playing ? PLAY_MESSAGES.playing : PLAY_MESSAGES.paused,
          })
        }, 150)
      } else {
        this.setState({
          playMessage: this.props.playing ? PLAY_MESSAGES.playing : PLAY_MESSAGES.paused,
        })
      }
    }
  }
  render() {
    const { navStyle, playing, transcriptOpen, growlOpen, growlMessage } = this.props
    return (
      <div className={"eflux-header " + navStyle + (transcriptOpen ? ' transcript-open' : '')}>
        <div className="eflux-logo">
          <a
            href="/"
            onMouseEnter={() => this.handleMouseEnter('eflux')}
            onMouseLeave={() => this.handleMouseLeave('eflux')}
          >
            {EfluxLogo}
          </a>
        </div>
        <div className={growlOpen ? "growl-tooltip growl-message open" : "growl-tooltip growl-message"}>
          {growlMessage}
        </div>
        <div className="eflux-nav">
          <span
            onMouseEnter={() => this.handleMouseEnter('play')}
            onMouseLeave={() => this.handleMouseLeave('play')}
          >
            <PlayButton playing={playing} />
          </span>
          <div
            className="transcript-icon"
            onMouseEnter={() => this.handleMouseEnter('transcript')}
            onMouseLeave={() => this.handleMouseLeave('transcript')}
            onClick={() => actions.viewer.toggleComponent('transcript')}
          >
            {EfluxMenu}
          </div>
        </div>
        <div className={this.state.eflux ? "growl-tooltip tooltip-eflux hover" : "growl-tooltip tooltip-eflux"}>
          {'Back to e-flux'}
        </div>
        <div className={this.state.play ? "growl-tooltip tooltip-play hover" : "growl-tooltip tooltip-play"}>
          {this.state.playMessage}
        </div>
        <div className={this.state.transcript ? "growl-tooltip tooltip-transcript hover" : "growl-tooltip tooltip-transcript"}>
          {'Read the Transcript'}
        </div>
      </div>
    )
  }
}

const mapStateToProps = state => ({
  navStyle: state.viewer.navStyle,
  playing: state.audio.playing,
  transcriptOpen: state.viewer.transcript,
  growlOpen: state.viewer.growlOpen,
  growlMessage: state.viewer.growlMessage,
})

export default connect(mapStateToProps)(EfluxChrome)