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

130 lines
3.6 KiB
JavaScript
Raw Normal View History

2016-10-26 16:55:47 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import Link from '../../components/Link';
2016-10-26 16:55:47 +13:00
import PlaylistGrid from '../../components/PlaylistGrid';
import Header from '../../components/Header';
import Icon from '../../components/Icon';
import Parallax from '../../components/Parallax';
import Thumbnail from '../../components/Thumbnail';
import URILink from '../../components/URILink';
import Dater from '../../components/Dater';
import * as helpers from '../../helpers';
import * as uiActions from '../../services/ui/actions';
import * as mopidyActions from '../../services/mopidy/actions';
import * as spotifyActions from '../../services/spotify/actions';
2016-10-26 16:55:47 +13:00
class DiscoverFeatured extends React.Component{
2017-10-10 13:05:28 +13:00
constructor(props){
2016-10-26 16:55:47 +13:00
super(props);
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Featured playlists");
if (!this.props.featured_playlists){
this.props.spotifyActions.getFeaturedPlaylists();
}
2016-10-26 16:55:47 +13:00
}
playPlaylist(e,playlist){
this.props.mopidyActions.playPlaylist(playlist.uri)
}
2017-05-31 08:40:55 +12:00
handleContextMenu(e,item){
e.preventDefault()
var data = {
e: e,
context: 'playlist',
uris: [item.uri],
items: [item]
}
this.props.uiActions.showContextMenu(data)
}
2017-05-25 20:15:47 +12:00
renderIntro(playlist = null){
if (playlist){
return (
<div className="intro preserve-3d">
<Parallax image={playlist.images ? playlist.images.large : null} blur />
2017-05-25 20:15:47 +12:00
</div>
)
} else {
return (
<div className="intro">
<Parallax disabled={this.props.disable_parallax} />
2017-05-25 20:15:47 +12:00
</div>
)
}
}
2016-10-26 16:55:47 +13:00
render(){
2017-05-22 04:19:44 +12:00
if (helpers.isLoading(this.props.load_queue,['spotify_browse/featured-playlists'])){
return (
<div className="view discover-featured-view">
<Header className="overlay" uiActions={this.props.uiActions}>
2018-05-15 21:30:57 +12:00
<Icon name="star" type="material" />
Featured playlists
</Header>
2017-08-07 21:34:33 +12:00
<div className="body-loader loading">
2017-05-22 04:19:44 +12:00
<div className="loader"></div>
</div>
</div>
)
}
var playlists = []
if (this.props.featured_playlists){
for (var i = 0; i < this.props.featured_playlists.playlists.length; i++){
var uri = this.props.featured_playlists.playlists[i]
if (this.props.playlists.hasOwnProperty(uri)){
playlists.push(this.props.playlists[uri])
}
}
}
// Pull the first playlist out and we'll use this for the parallax artwork
var first_playlist = playlists[0];
2017-05-25 20:15:47 +12:00
2018-07-02 16:22:05 +12:00
var options = (
2018-12-07 15:57:20 +13:00
<a className="button button--no-hover" onClick={e => {this.props.uiActions.hideContextMenu(); this.props.spotifyActions.getFeaturedPlaylists()}}>
2018-07-02 16:22:05 +12:00
<Icon name="refresh" />Refresh
</a>
2018-07-02 16:22:05 +12:00
);
2016-10-26 16:55:47 +13:00
return (
<div className="view discover-featured-view preserve-3d">
2018-07-02 16:22:05 +12:00
<Header className="overlay" options={options}>
2018-05-15 21:30:57 +12:00
<Icon name="star" type="material" />
Featured playlists
</Header>
2017-05-25 20:15:47 +12:00
{this.renderIntro(first_playlist)}
2017-06-18 05:47:36 +12:00
<section className="content-wrapper grid-wrapper">
2017-05-25 20:15:47 +12:00
{playlists ? <PlaylistGrid playlists={playlists} /> : null }
</section>
2016-10-26 16:55:47 +13:00
</div>
);
}
}
const mapStateToProps = (state, ownProps) => {
return {
2018-08-27 08:21:41 +12:00
theme: state.ui.theme,
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
featured_playlists: state.spotify.featured_playlists,
playlists: state.core.playlists
}
2016-10-26 16:55:47 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
2017-05-31 08:40:55 +12:00
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
2016-10-26 16:55:47 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverFeatured)