summaryrefslogtreecommitdiff
path: root/app/client/common/header.component.js
blob: 8a2310fe33700aa5186204765ab71b22837f8b74 (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
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router-dom';
import { connect } from 'react-redux'

import * as systemActions from '../system/system.actions'

import modules from '../modules'

function Header({ site, app, fps, playing, actions }) {
  const tool_list = Object.keys(modules).map((name, i) => {
    const label = name.replace(/_/, " ")
    return <option value={name} key={i}>{label}</option>
  })
  const Links = modules[app.tool].links
  console.log(app, site, Object.keys(modules))
  return (
    <header>
      <b>{site.name} cortex</b>
      <span>
        <select onChange={e => actions.changeTool(e.target.value)} value={app.tool}>
          {tool_list}
        </select>
      </span>
      <span><Link to="/system">system</Link></span>
      <span><Link to="/dashboard">dashboard</Link></span>
      <Links />
      {playing && <span>{fps} fps</span>}
    </header>
  )
}

const mapStateToProps = state => ({
  site: state.system.site,
  app: state.system.app,
  fps: state.live.fps,
  playing: state.live.playing,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(systemActions, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(Header)