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: () => { if (! ownProps.file) return 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