2017-07-07 09:59:16 +12:00
|
|
|
|
2019-01-16 16:46:40 +13:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import { Route, Switch } from 'react-router-dom';
|
2019-01-09 16:56:35 +13:00
|
|
|
|
2018-10-24 21:34:41 +13:00
|
|
|
import Link from '../../components/Link';
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2019-01-16 16:46:40 +13:00
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import List from '../../components/List';
|
|
|
|
|
import TrackList from '../../components/TrackList';
|
|
|
|
|
import GridItem from '../../components/GridItem';
|
|
|
|
|
import DropdownField from '../../components/Fields/DropdownField';
|
|
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
import URILink from '../../components/URILink';
|
|
|
|
|
import ErrorBoundary from '../../components/ErrorBoundary';
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2019-01-16 16:46:40 +13:00
|
|
|
import * as helpers from '../../helpers';
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
2017-07-07 09:59:16 +12:00
|
|
|
|
|
|
|
|
class LibraryBrowse extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-07-07 09:59:16 +12:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2019-01-17 15:54:04 +13:00
|
|
|
this.loadDirectory();
|
|
|
|
|
this.props.uiActions.setWindowTitle("Browse");
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
2017-07-07 09:59:16 +12:00
|
|
|
|
|
|
|
|
// mopidy goes online
|
2017-10-10 13:05:28 +13:00
|
|
|
if (!this.props.mopidy_connected && nextProps.mopidy_connected){
|
2018-09-11 21:31:30 +12:00
|
|
|
this.loadDirectory(nextProps);
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
loadDirectory(props = this.props){
|
2017-07-07 09:59:16 +12:00
|
|
|
if (props.mopidy_connected){
|
2019-01-17 15:54:04 +13:00
|
|
|
this.props.mopidyActions.getDirectory(null);
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 16:46:40 +13:00
|
|
|
render(){
|
2017-10-27 10:51:48 +13:00
|
|
|
var grid_items = []
|
|
|
|
|
if (this.props.directory){
|
2018-09-11 21:31:30 +12:00
|
|
|
for (var subdirectory of this.props.directory.subdirectories){
|
2017-07-07 08:06:26 +12:00
|
|
|
|
2018-09-11 21:31:30 +12:00
|
|
|
switch (subdirectory.name){
|
2017-11-17 21:38:24 +13:00
|
|
|
case 'Dirble':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-dirble.jpg']
|
2017-11-17 21:38:24 +13:00
|
|
|
break
|
|
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
case 'Files':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-folders.jpg']
|
2017-10-27 10:51:48 +13:00
|
|
|
break
|
2017-07-07 08:06:26 +12:00
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
case 'Local media':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-folders.jpg']
|
2017-10-27 10:51:48 +13:00
|
|
|
break
|
2017-07-07 08:06:26 +12:00
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
case 'Spotify':
|
|
|
|
|
case 'Spotify Browse':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-spotify.jpg']
|
2017-10-27 10:51:48 +13:00
|
|
|
break
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
case 'Spotify Tunigo':
|
|
|
|
|
case 'Tunigo':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-tunigo.jpg']
|
2017-10-27 10:51:48 +13:00
|
|
|
break
|
2017-07-07 08:19:47 +12:00
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
case 'TuneIn':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-tunein.jpg']
|
2017-10-27 10:51:48 +13:00
|
|
|
break
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2017-11-17 21:38:24 +13:00
|
|
|
case 'SoundCloud':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-soundcloud.jpg']
|
2017-11-17 21:38:24 +13:00
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'iTunes Store: Podcasts':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-itunes.jpg']
|
2017-11-17 21:38:24 +13:00
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'Soma FM':
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-somafm.jpg']
|
2017-11-17 21:38:24 +13:00
|
|
|
break
|
|
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
default:
|
2019-01-17 22:13:18 +13:00
|
|
|
subdirectory.icons = ['/assets/backgrounds/browse-default.jpg']
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
2017-10-27 10:51:48 +13:00
|
|
|
|
|
|
|
|
grid_items.push({
|
2018-09-11 21:31:30 +12:00
|
|
|
name: subdirectory.name,
|
2019-01-22 16:57:43 +13:00
|
|
|
link: '/library/browse/'+encodeURIComponent(subdirectory.uri),
|
2018-09-11 21:31:30 +12:00
|
|
|
icons: helpers.formatImages(subdirectory.icons)
|
2017-10-27 10:51:48 +13:00
|
|
|
})
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
2017-10-27 10:51:48 +13:00
|
|
|
}
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2017-10-27 10:51:48 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
2019-01-16 16:46:40 +13:00
|
|
|
<Header>
|
2018-05-15 21:30:57 +12:00
|
|
|
<Icon name="folder" type="material" />
|
|
|
|
|
Browse
|
|
|
|
|
</Header>
|
2017-10-27 10:51:48 +13:00
|
|
|
<section className="content-wrapper">
|
2019-01-17 22:13:18 +13:00
|
|
|
<div className="grid grid--tiles">
|
2018-10-04 21:07:25 +13:00
|
|
|
<ErrorBoundary>
|
|
|
|
|
{
|
|
|
|
|
grid_items.map(
|
|
|
|
|
(item, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<GridItem
|
|
|
|
|
item={item}
|
|
|
|
|
key={index}
|
2019-01-17 15:54:04 +13:00
|
|
|
link={item.link}
|
|
|
|
|
type="browse"
|
2018-10-04 21:07:25 +13:00
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
</ErrorBoundary>
|
2017-10-27 10:51:48 +13:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
mopidy_connected: state.mopidy.connected,
|
2018-09-11 21:31:30 +12:00
|
|
|
directory: state.mopidy.directory,
|
|
|
|
|
view: state.ui.library_directory_view
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2017-10-30 11:53:04 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2019-01-16 16:46:40 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch)
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryBrowse)
|