2017-07-07 09:59:16 +12:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2019-01-16 16:46:40 +13:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import GridItem from '../../components/GridItem';
|
|
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
import ErrorBoundary from '../../components/ErrorBoundary';
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
2020-03-05 21:32:54 +13:00
|
|
|
import { formatImages } from '../../util/format';
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2020-03-03 16:39:37 +13:00
|
|
|
class LibraryBrowse extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.loadDirectory();
|
|
|
|
|
this.props.uiActions.setWindowTitle('Browse');
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 21:32:50 +13:00
|
|
|
componentDidUpdate = ({ mopidy_connected: prev_mopidy_connected}) => {
|
|
|
|
|
const { mopidy_connected } = this.props;
|
|
|
|
|
if (!prev_mopidy_connected && mopidy_connected) this.loadDirectory();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadDirectory(props = this.props) {
|
|
|
|
|
if (props.mopidy_connected) {
|
|
|
|
|
this.props.mopidyActions.getDirectory(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const grid_items = [];
|
|
|
|
|
if (this.props.directory) {
|
2020-03-03 16:39:37 +13:00
|
|
|
for (const subdirectory of this.props.directory.subdirectories) {
|
2019-09-05 15:36:11 +12:00
|
|
|
switch (subdirectory.name) {
|
|
|
|
|
case 'Dirble':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-dirble.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Files':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-folders.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Local media':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-folders.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Spotify':
|
|
|
|
|
case 'Spotify Browse':
|
|
|
|
|
case 'Spotify Web Browse':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-spotify.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Spotify Tunigo':
|
|
|
|
|
case 'Tunigo':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-tunigo.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'TuneIn':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-tunein.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'SoundCloud':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-soundcloud.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'iTunes Store: Podcasts':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-itunes.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Soma FM':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-somafm.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-default.jpg'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid_items.push({
|
|
|
|
|
name: subdirectory.name,
|
|
|
|
|
link: `/library/browse/${encodeURIComponent(subdirectory.uri)}`,
|
2020-03-03 16:39:37 +13:00
|
|
|
icons: formatImages(subdirectory.icons),
|
2019-09-05 15:36:11 +12:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-local-view">
|
|
|
|
|
<Header>
|
|
|
|
|
<Icon name="folder" type="material" />
|
2018-05-15 21:30:57 +12:00
|
|
|
Browse
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<div className="grid grid--tiles">
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
{
|
2018-10-04 21:07:25 +13:00
|
|
|
grid_items.map(
|
2019-09-05 15:36:11 +12:00
|
|
|
(item, index) => (
|
2020-03-10 07:56:33 +13:00
|
|
|
<GridItem
|
|
|
|
|
item={item}
|
|
|
|
|
key={index}
|
|
|
|
|
link={item.link}
|
|
|
|
|
mopidyActions={this.props.mopidyActions}
|
|
|
|
|
type="browse"
|
|
|
|
|
/>
|
2019-09-05 15:36:11 +12:00
|
|
|
),
|
2018-10-04 21:07:25 +13:00
|
|
|
)
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
</ErrorBoundary>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-07-07 09:59:16 +12:00
|
|
|
}
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
mopidy_connected: state.mopidy.connected,
|
|
|
|
|
directory: state.mopidy.directory,
|
|
|
|
|
view: state.ui.library_directory_view,
|
|
|
|
|
});
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
});
|
2017-07-07 09:59:16 +12:00
|
|
|
|
2020-03-03 16:39:37 +13:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryBrowse);
|