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';
|
2021-02-01 20:41:49 +13:00
|
|
|
import Loader from '../../components/Loader';
|
2019-01-16 16:46:40 +13:00
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
import ErrorBoundary from '../../components/ErrorBoundary';
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
2021-01-23 16:24:07 +13:00
|
|
|
import { formatImages, encodeUri } from '../../util/format';
|
2020-07-19 20:41:14 +12:00
|
|
|
import { I18n, i18n } from '../../locale';
|
2021-02-01 20:41:49 +13:00
|
|
|
import { makeLoadingSelector } from '../../util/selectors';
|
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();
|
2020-07-19 20:41:14 +12:00
|
|
|
this.props.uiActions.setWindowTitle(i18n('library.browse.title'));
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 08:06:24 +12:00
|
|
|
loadDirectory = () => {
|
|
|
|
|
const {
|
|
|
|
|
mopidyActions: {
|
|
|
|
|
getDirectory,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
getDirectory(null);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2021-02-01 20:41:49 +13:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
loading,
|
|
|
|
|
directory,
|
|
|
|
|
mopidyActions,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (!directory) {
|
|
|
|
|
if (loading) {
|
|
|
|
|
return <Loader body loading />;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const grid_items = [];
|
2021-02-01 20:41:49 +13:00
|
|
|
if (directory.subdirectories) {
|
|
|
|
|
for (const subdirectory of 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;
|
|
|
|
|
|
2020-07-05 21:16:31 +02:00
|
|
|
case 'Mixcloud':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-mixcloud.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
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;
|
|
|
|
|
|
2020-04-30 15:45:55 +12:00
|
|
|
case 'Tidal':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-tidal.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Google':
|
|
|
|
|
case 'Google Play':
|
|
|
|
|
case 'Google Play Music':
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-google.jpg'];
|
|
|
|
|
break;
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
default:
|
|
|
|
|
subdirectory.icons = ['/iris/assets/backgrounds/browse-default.jpg'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid_items.push({
|
|
|
|
|
name: subdirectory.name,
|
2021-01-23 16:24:07 +13:00
|
|
|
link: `/library/browse/${encodeUri(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" />
|
2021-02-01 20:41:49 +13:00
|
|
|
<I18n path="library.browse.title" />
|
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}
|
2021-02-01 20:41:49 +13:00
|
|
|
mopidyActions={mopidyActions}
|
2020-03-10 07:56:33 +13:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-02-01 20:41:49 +13:00
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
const {
|
|
|
|
|
mopidy: {
|
|
|
|
|
directory: _directory = {},
|
|
|
|
|
},
|
|
|
|
|
ui: {
|
|
|
|
|
library_directory_view: view,
|
|
|
|
|
},
|
|
|
|
|
} = state;
|
|
|
|
|
const directory = _directory && _directory.uri === null ? _directory : null;
|
|
|
|
|
const loadingSelector = makeLoadingSelector(['(.*)mopidy_library.browse(.*)']);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loading: loadingSelector(state),
|
|
|
|
|
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);
|