Files
Iris/src/js/views/discover/DiscoverFeatured.js

126 lines
3.4 KiB
JavaScript
Raw Normal View History

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';
import PlaylistGrid from '../../components/PlaylistGrid';
import Header from '../../components/Header';
import Icon from '../../components/Icon';
import Loader from '../../components/Loader';
import * as uiActions from '../../services/ui/actions';
import * as mopidyActions from '../../services/mopidy/actions';
import * as spotifyActions from '../../services/spotify/actions';
import { isLoading } from '../../util/helpers';
import { i18n, I18n } from '../../locale';
2016-10-26 16:55:47 +13:00
class DiscoverFeatured extends React.Component {
2019-09-05 15:36:11 +12:00
componentDidMount() {
const {
featured_playlists,
uiActions: {
setWindowTitle,
},
spotifyActions: {
getFeaturedPlaylists,
},
} = this.props;
setWindowTitle(i18n('discover.featured.title'));
if (!featured_playlists) getFeaturedPlaylists();
2019-09-05 15:36:11 +12:00
}
onRefresh = () => {
const {
uiActions: {
hideContextMenu,
},
spotifyActions: {
getFeaturedPlaylists,
},
} = this.props;
hideContextMenu();
getFeaturedPlaylists();
2019-09-05 15:36:11 +12:00
}
handleContextMenu = (e, item) => {
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],
};
showContextMenu(data);
2019-09-05 15:36:11 +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">
<Header className="overlay" uiActions={uiActions}>
2019-09-05 15:36:11 +12:00
<Icon name="star" type="material" />
<I18n path="discover.featured.title" />
2019-09-05 15:36:11 +12:00
</Header>
<Loader body loading />
2019-09-05 15:36:11 +12:00
</div>
);
}
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 = (
<a className="button button--no-hover" onClick={this.onRefresh}>
<Icon name="refresh" />
<I18n path="actions.refresh" />
2019-09-05 15:36:11 +12:00
</a>
);
return (
<div className="view discover-featured-view preserve-3d">
<Header uiActions={uiActions} options={options}>
2019-09-05 15:36:11 +12:00
<Icon name="star" type="material" />
<I18n path="discover.featured.title" />
2019-09-05 15:36:11 +12:00
</Header>
<section className="content-wrapper grid-wrapper">
{items && <PlaylistGrid playlists={items} />}
2019-09-05 15:36:11 +12:00
</section>
</div>
);
}
2016-10-26 16:55:47 +13: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
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverFeatured);