summaryrefslogtreecommitdiff
path: root/client/containers/fileLink.js
blob: 22834d849605400a9448f38c7655b1d20dc477eb (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
import { connect } from 'react-redux'
import { audioPlayFile } from '../actions'
import { filepath } from '../vendor/paths'
import Link from '../components/UI/Link.jsx'

const mapStateToProps = (state, ownProps) => ({
  href: ownProps.file ? filepath(ownProps.file) : '#',
  children: ownProps.children || (ownProps.file ? ownProps.file.name : "(~)"),
  disabled: ownProps.disabled || ! ownProps.file,
  selected: ownProps.file && state.audioPlayer.file && state.audioPlayer.file.id == ownProps.file.id
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  onClick: () => {
    switch (ownProps.file.type) {
      case 'audio':
        let file = ownProps.file
        dispatch(audioPlayFile(null))
        setTimeout(() => {
          dispatch(audioPlayFile(ownProps.file))
        }, 10)
        break
      case 'image':
        // document.body.style.backgroundImage = 
        break
    }
  }
})

const FileLink = connect(
  mapStateToProps,
  mapDispatchToProps
)(Link)

export default FileLink