2017-07-07 09:59:16 +12:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2017-07-07 08:49:07 +12:00
|
|
|
import { Link, hashHistory } from 'react-router'
|
2017-07-07 09:59:16 +12:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
|
|
|
|
|
|
|
|
|
import Header from '../../components/Header'
|
|
|
|
|
import List from '../../components/List'
|
|
|
|
|
import TrackList from '../../components/TrackList'
|
|
|
|
|
import GridItem from '../../components/GridItem'
|
|
|
|
|
|
|
|
|
|
import * as helpers from '../../helpers'
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class LibraryBrowse extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
this.loadDirectory()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
|
|
|
|
|
// mopidy goes online
|
|
|
|
|
if (!this.props.mopidy_connected && nextProps.mopidy_connected ){
|
|
|
|
|
this.loadDirectory( nextProps );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// our uri changes
|
|
|
|
|
if (nextProps.params.uri != this.props.params.uri){
|
|
|
|
|
this.loadDirectory( nextProps );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadDirectory( props = this.props ){
|
|
|
|
|
if (props.mopidy_connected){
|
|
|
|
|
var uri = null
|
|
|
|
|
if (typeof(props.params.uri) !== 'undefined'){
|
2017-07-07 08:25:58 +12:00
|
|
|
uri = decodeURIComponent(props.params.uri)
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
2017-07-07 08:49:07 +12:00
|
|
|
|
2017-07-07 09:59:16 +12:00
|
|
|
this.props.mopidyActions.getDirectory(uri)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
arrange_directory( directory ){
|
|
|
|
|
var folders = []
|
|
|
|
|
var tracks = []
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < directory.length; i++) {
|
|
|
|
|
if (directory[i].type && directory[i].type == 'track') {
|
|
|
|
|
tracks.push( directory[i] )
|
|
|
|
|
} else {
|
2017-07-07 08:49:07 +12:00
|
|
|
var uri = directory[i].uri
|
|
|
|
|
|
|
|
|
|
// If we've navigated to a handled asset type, use our standard views
|
|
|
|
|
switch (helpers.uriType(uri)){
|
|
|
|
|
case 'album':
|
|
|
|
|
uri = global.baseURL+'album/'+uri
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'artist':
|
|
|
|
|
uri = global.baseURL+'artist/'+uri
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'playlist':
|
|
|
|
|
uri = global.baseURL+'playlist/'+uri
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
uri = global.baseURL+"library/browse/"+encodeURIComponent(uri)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 09:59:16 +12:00
|
|
|
folders.push(Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
directory[i],
|
|
|
|
|
{
|
2017-07-07 08:49:07 +12:00
|
|
|
uri: uri
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
folders: folders,
|
|
|
|
|
tracks: tracks
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
if (typeof(this.props.params.uri) !== 'undefined' && this.props.params.uri){
|
|
|
|
|
|
2017-07-10 08:09:27 +12:00
|
|
|
var title = 'Browse'
|
|
|
|
|
var uri_exploded = this.props.params.uri.split(':')
|
|
|
|
|
if (uri_exploded.length > 0){
|
|
|
|
|
title = uri_exploded[0]
|
|
|
|
|
title = title.charAt(0).toUpperCase() + title.slice(1)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 09:59:16 +12:00
|
|
|
var options = null
|
|
|
|
|
if (this.props.params.uri != 'local:directory' ){
|
|
|
|
|
options = (
|
|
|
|
|
<button onClick={ () => window.history.back() }>
|
|
|
|
|
<FontAwesome name="reply" />
|
|
|
|
|
Back
|
|
|
|
|
</button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.props.directory || helpers.isLoading(this.props.load_queue,['mopidy_browse'])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
2017-07-10 08:09:27 +12:00
|
|
|
<Header icon="music" title={title} options={options} uiActions={this.props.uiActions} />
|
2017-08-07 21:34:33 +12:00
|
|
|
<div className="body-loader loading">
|
2017-07-07 09:59:16 +12:00
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var items = this.arrange_directory( this.props.directory )
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
2017-07-10 08:09:27 +12:00
|
|
|
<Header icon="music" title={title} options={options} uiActions={this.props.uiActions} />
|
2017-07-07 09:59:16 +12:00
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<List
|
|
|
|
|
columns={[{ name: 'name', width: '100'}]}
|
|
|
|
|
rows={items.folders}
|
2017-07-07 08:49:07 +12:00
|
|
|
className="library-local-directory-list" />
|
2017-07-07 09:59:16 +12:00
|
|
|
<TrackList
|
|
|
|
|
tracks={items.tracks}
|
|
|
|
|
className="library-local-track-list"
|
|
|
|
|
noheader />
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2017-08-13 21:04:59 +12:00
|
|
|
var grid_items = []
|
2017-07-07 09:59:16 +12:00
|
|
|
if (this.props.directory){
|
|
|
|
|
for (var i = 0; i < this.props.directory.length; i++){
|
|
|
|
|
var directory = this.props.directory[i]
|
|
|
|
|
|
|
|
|
|
switch (directory.name){
|
|
|
|
|
case 'Files':
|
2017-07-07 08:06:26 +12:00
|
|
|
directory.icons = ['assets/backgrounds/browse-folders.jpg']
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'Local media':
|
|
|
|
|
directory.icons = ['assets/backgrounds/browse-folders.jpg']
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'Spotify':
|
2017-07-07 08:20:42 +12:00
|
|
|
case 'Spotify Browse':
|
2017-07-07 08:06:26 +12:00
|
|
|
directory.icons = ['assets/backgrounds/browse-spotify.jpg']
|
|
|
|
|
break
|
|
|
|
|
|
2017-07-07 08:20:42 +12:00
|
|
|
case 'Spotify Tunigo':
|
2017-07-07 08:06:26 +12:00
|
|
|
case 'Tunigo':
|
|
|
|
|
directory.icons = ['assets/backgrounds/browse-tunigo.jpg']
|
2017-07-07 09:59:16 +12:00
|
|
|
break
|
|
|
|
|
|
2017-07-07 08:20:42 +12:00
|
|
|
case 'TuneIn':
|
2017-07-07 08:19:47 +12:00
|
|
|
directory.icons = ['assets/backgrounds/browse-tunein.jpg']
|
|
|
|
|
break
|
|
|
|
|
|
2017-07-07 09:59:16 +12:00
|
|
|
default:
|
2017-07-07 08:19:47 +12:00
|
|
|
directory.icons = ['assets/backgrounds/browse-default.jpg']
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid_items.push({
|
|
|
|
|
name: directory.name,
|
2017-07-07 08:19:47 +12:00
|
|
|
link: global.baseURL+'library/browse/'+encodeURIComponent(directory.uri),
|
2017-07-07 09:59:16 +12:00
|
|
|
icons: directory.icons
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
|
|
|
|
<Header icon="folder" title="Browse" />
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<div className="grid category-grid">
|
|
|
|
|
{
|
|
|
|
|
grid_items.map(
|
|
|
|
|
(item, index) => {
|
2017-08-11 08:08:03 +12:00
|
|
|
return (
|
|
|
|
|
<GridItem
|
|
|
|
|
item={item}
|
|
|
|
|
key={index}
|
|
|
|
|
onClick={e => hashHistory.push(item.link)}
|
|
|
|
|
/>
|
|
|
|
|
)
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
mopidy_connected: state.mopidy.connected,
|
|
|
|
|
directory: state.mopidy.directory
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryBrowse)
|