2016-10-26 16:55:47 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2018-12-05 21:39:06 +13:00
|
|
|
import PlaylistGrid from '../../components/PlaylistGrid';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import Icon from '../../components/Icon';
|
2019-09-10 06:59:44 +12:00
|
|
|
import Loader from '../../components/Loader';
|
2018-12-05 21:39:06 +13:00
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions';
|
2020-03-03 16:39:37 +13:00
|
|
|
import { isLoading } from '../../util/helpers';
|
2016-10-26 16:55:47 +13:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
class DiscoverFeatured extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
componentDidMount() {
|
2020-06-18 21:06:52 +12:00
|
|
|
const {
|
|
|
|
|
featured_playlists,
|
|
|
|
|
uiActions: {
|
|
|
|
|
setWindowTitle,
|
|
|
|
|
},
|
|
|
|
|
spotifyActions: {
|
|
|
|
|
getFeaturedPlaylists,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
setWindowTitle('Featured playlists');
|
|
|
|
|
if (!featured_playlists) getFeaturedPlaylists();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-06-18 21:06:52 +12:00
|
|
|
onRefresh = () => {
|
|
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
hideContextMenu,
|
|
|
|
|
},
|
|
|
|
|
spotifyActions: {
|
|
|
|
|
getFeaturedPlaylists,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
hideContextMenu();
|
|
|
|
|
getFeaturedPlaylists();
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleContextMenu(e, item) {
|
2020-06-18 21:06:52 +12:00
|
|
|
const {
|
|
|
|
|
uiActions: {
|
|
|
|
|
showContextMenu,
|
|
|
|
|
},
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
e.preventDefault();
|
|
|
|
|
const data = {
|
|
|
|
|
e,
|
|
|
|
|
context: 'playlist',
|
|
|
|
|
uris: [item.uri],
|
|
|
|
|
items: [item],
|
|
|
|
|
};
|
2020-06-18 21:06:52 +12:00
|
|
|
showContextMenu(data);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-06-18 21:06:52 +12:00
|
|
|
render = () => {
|
|
|
|
|
const {
|
|
|
|
|
load_queue,
|
|
|
|
|
uiActions,
|
|
|
|
|
featured_playlists,
|
|
|
|
|
playlists,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (isLoading(load_queue, ['spotify_browse/featured-playlists'])) {
|
2019-09-05 15:36:11 +12:00
|
|
|
return (
|
|
|
|
|
<div className="view discover-featured-view preserve-3d">
|
2020-06-18 21:06:52 +12:00
|
|
|
<Header className="overlay" uiActions={uiActions}>
|
2019-09-05 15:36:11 +12:00
|
|
|
<Icon name="star" type="material" />
|
2018-05-15 21:30:57 +12:00
|
|
|
Featured playlists
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
2019-09-10 06:59:44 +12:00
|
|
|
<Loader body loading />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 21:06:52 +12:00
|
|
|
const items = [];
|
|
|
|
|
if (featured_playlists) {
|
|
|
|
|
for (let i = 0; i < featured_playlists.playlists.length; i++) {
|
|
|
|
|
const uri = featured_playlists.playlists[i];
|
|
|
|
|
if (playlists.hasOwnProperty(uri)) {
|
|
|
|
|
items.push(playlists[uri]);
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const options = (
|
2020-06-18 21:06:52 +12:00
|
|
|
<a className="button button--no-hover" onClick={this.onRefresh}>
|
2019-09-10 06:59:44 +12:00
|
|
|
<Icon name="refresh" />
|
2020-06-18 21:06:52 +12:00
|
|
|
Refresh
|
2019-09-05 15:36:11 +12:00
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view discover-featured-view preserve-3d">
|
2020-06-18 21:06:52 +12:00
|
|
|
<Header uiActions={uiActions} options={options}>
|
2019-09-05 15:36:11 +12:00
|
|
|
<Icon name="star" type="material" />
|
2020-06-18 21:06:52 +12:00
|
|
|
Featured playlists
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
<section className="content-wrapper grid-wrapper">
|
2020-06-18 21:06:52 +12:00
|
|
|
{items && <PlaylistGrid playlists={items} />}
|
2019-09-05 15:36:11 +12:00
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-26 16:55:47 +13:00
|
|
|
}
|
|
|
|
|
|
2020-06-18 21:06:52 +12:00
|
|
|
const mapStateToProps = (state) => ({
|
2019-09-05 15:36:11 +12:00
|
|
|
theme: state.ui.theme,
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
featured_playlists: state.spotify.featured_playlists,
|
|
|
|
|
playlists: state.core.playlists,
|
|
|
|
|
});
|
2016-10-26 16:55:47 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
});
|
2016-10-26 16:55:47 +13:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverFeatured);
|