2016-11-01 07:37:18 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
import { Link } from 'react-router'
|
|
|
|
|
|
|
|
|
|
import Header from '../../components/Header'
|
2016-11-02 16:51:00 +13:00
|
|
|
import List from '../../components/List'
|
2016-11-01 07:37:18 +13:00
|
|
|
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class LibraryLocalDirectory extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on render
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
this.loadDirectory()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
|
|
|
|
|
// mopidy goes online
|
|
|
|
|
if( !this.props.mopidy.connected && nextProps.mopidy.connected ){
|
2016-11-02 16:51:00 +13:00
|
|
|
this.loadDirectory( nextProps );
|
2016-11-01 07:37:18 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// our uri changes
|
|
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
2016-11-02 16:51:00 +13:00
|
|
|
this.loadDirectory( nextProps );
|
2016-11-01 07:37:18 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 16:51:00 +13:00
|
|
|
loadDirectory( props = this.props ){
|
|
|
|
|
if( props.mopidy.connected ){
|
|
|
|
|
this.props.mopidyActions.getDirectory( props.params.uri );
|
2016-11-01 07:37:18 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2016-11-02 16:51:00 +13:00
|
|
|
if( !this.props.mopidy.directory ) return null
|
|
|
|
|
|
2016-11-01 07:37:18 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
2016-11-02 16:51:00 +13:00
|
|
|
<Header icon="music" title="Local files" />
|
|
|
|
|
<div>
|
|
|
|
|
<List columns={[{ name: 'name', width: '100'}]} rows={this.props.mopidy.directory} link_prefix="/library/local/directory/" />
|
|
|
|
|
</div>
|
2016-11-01 07:37:18 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryLocalDirectory)
|