2016-11-18 15:31:06 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import Thumbnail from '../components/Thumbnail'
|
|
|
|
|
import PlaylistGrid from '../components/PlaylistGrid'
|
2018-04-19 13:34:16 +12:00
|
|
|
import FollowButton from '../components/Fields/FollowButton'
|
2016-11-18 15:31:06 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
2017-06-23 08:57:26 +12:00
|
|
|
import Parallax from '../components/Parallax'
|
2017-02-28 16:13:27 +13:00
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger'
|
2018-05-21 06:01:53 +12:00
|
|
|
import Icon from '../components/Icon'
|
2016-11-18 15:31:06 +13:00
|
|
|
|
|
|
|
|
import * as helpers from '../helpers'
|
2018-08-13 19:58:36 +12:00
|
|
|
import * as coreActions from '../services/core/actions'
|
2018-06-29 14:26:06 +12:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
2016-11-18 15:31:06 +13:00
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class User extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-11-18 15:31:06 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2018-06-29 14:26:06 +12:00
|
|
|
this.setWindowTitle();
|
2016-11-18 15:31:06 +13:00
|
|
|
this.loadUser();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
|
|
|
|
if (nextProps.params.uri != this.props.params.uri){
|
2017-11-01 08:14:26 +13:00
|
|
|
this.loadUser(nextProps);
|
2017-08-06 21:07:04 +12:00
|
|
|
}
|
2018-06-29 14:26:06 +12:00
|
|
|
|
|
|
|
|
if (!this.props.user && nextProps.user){
|
|
|
|
|
this.setWindowTitle(nextProps.user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
setWindowTitle(user = this.props.user){
|
2018-06-29 14:26:06 +12:00
|
|
|
if (user){
|
|
|
|
|
this.props.uiActions.setWindowTitle(user.name+" (user)");
|
|
|
|
|
} else{
|
|
|
|
|
this.props.uiActions.setWindowTitle("User");
|
|
|
|
|
}
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
loadUser(props = this.props){
|
2018-02-15 09:47:49 +13:00
|
|
|
if (!props.user || props.user.playlists_uris === undefined){
|
2017-11-10 15:56:01 +13:00
|
|
|
this.props.spotifyActions.getUser(props.params.uri, true);
|
2017-11-01 08:14:26 +13:00
|
|
|
this.props.spotifyActions.following(props.params.uri);
|
2017-08-06 21:07:04 +12:00
|
|
|
}
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMore(){
|
2017-11-12 09:05:34 +13:00
|
|
|
this.props.spotifyActions.getMore(
|
2017-11-10 15:56:01 +13:00
|
|
|
this.props.user.playlists_more,
|
|
|
|
|
{
|
|
|
|
|
parent_type: 'user',
|
|
|
|
|
parent_key: this.props.params.uri,
|
|
|
|
|
records_type: 'playlist'
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
2017-02-08 08:34:14 +13:00
|
|
|
isMe(){
|
2017-09-27 15:29:17 +13:00
|
|
|
let userid = helpers.getFromUri('userid',this.props.params.uri);
|
|
|
|
|
return (this.props.me && this.props.me.id && this.props.me.id == userid);
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2018-02-16 16:58:46 +13:00
|
|
|
var user_id = helpers.getFromUri('userid',this.props.params.uri);
|
2017-06-27 09:37:33 +12:00
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
if (!this.props.user){
|
2018-04-10 20:14:31 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_users/'+user_id,'spotify_users/'+user_id+'/playlists/?'])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-11-01 08:14:26 +13:00
|
|
|
}
|
2017-06-27 09:37:33 +12:00
|
|
|
|
2017-11-01 08:14:26 +13:00
|
|
|
var playlists = [];
|
2017-06-27 09:37:33 +12:00
|
|
|
if (this.props.user.playlists_uris){
|
|
|
|
|
for (var i = 0; i < this.props.user.playlists_uris.length; i++){
|
|
|
|
|
var uri = this.props.user.playlists_uris[i]
|
|
|
|
|
if (this.props.playlists.hasOwnProperty(uri)){
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 20:32:12 +13:00
|
|
|
if (this.props.user && this.props.user.images){
|
2017-06-27 09:37:33 +12:00
|
|
|
var image = helpers.sizedImages(this.props.user.images).huge
|
2017-02-26 18:33:20 +13:00
|
|
|
} else {
|
2017-06-27 09:37:33 +12:00
|
|
|
var image = null
|
|
|
|
|
}
|
2017-02-26 18:33:20 +13:00
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
return (
|
|
|
|
|
<div className="view user-view">
|
|
|
|
|
<div className="intro">
|
2017-07-25 09:22:28 +12:00
|
|
|
<Parallax image={image} />
|
2017-06-27 09:37:33 +12:00
|
|
|
<div className="liner">
|
|
|
|
|
<h1>{ this.props.user.display_name ? this.props.user.display_name : this.props.user.id }</h1>
|
|
|
|
|
<h2>
|
|
|
|
|
<ul className="details">
|
2017-09-25 20:32:12 +13:00
|
|
|
{this.props.user.playlists_total ? <li>{this.props.user.playlists_total ? this.props.user.playlists_total.toLocaleString() : 0} playlists</li> : null}
|
|
|
|
|
{this.props.user.followers ? <li>{this.props.user.followers.total.toLocaleString()} followers</li> : null}
|
2017-10-14 08:35:37 +13:00
|
|
|
{this.isMe() ? <li><span className="blue-text">You</span></li> : null}
|
2017-06-27 09:37:33 +12:00
|
|
|
</ul>
|
|
|
|
|
</h2>
|
2017-02-26 18:33:20 +13:00
|
|
|
<div className="actions">
|
2017-07-14 08:47:02 +12:00
|
|
|
<FollowButton className="primary" uri={this.props.params.uri} addText="Follow" removeText="Unfollow" />
|
2017-02-26 18:33:20 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2016-11-18 15:31:06 +13:00
|
|
|
</div>
|
2018-08-13 19:58:36 +12:00
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
<div className="content-wrapper">
|
|
|
|
|
<section className="grid-wrapper">
|
|
|
|
|
<h4>Playlists</h4>
|
|
|
|
|
<PlaylistGrid playlists={playlists} />
|
2017-11-10 15:56:01 +13:00
|
|
|
<LazyLoadListener loading={this.props.user.playlists_more} loadMore={() => this.loadMore()} />
|
2017-06-27 09:37:33 +12:00
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2017-10-26 20:36:27 +13:00
|
|
|
var uri = ownProps.params.uri;
|
2016-11-18 15:31:06 +13:00
|
|
|
return {
|
2017-06-27 09:37:33 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-08-04 22:33:49 +12:00
|
|
|
spotify_authorized: state.spotify.authorization,
|
2016-11-18 15:31:06 +13:00
|
|
|
me: state.spotify.me,
|
2017-08-02 10:53:30 +12:00
|
|
|
playlists: state.core.playlists,
|
2017-11-10 15:56:01 +13:00
|
|
|
user: (state.core.users[uri] !== undefined ? state.core.users[uri] : false)
|
2016-11-18 15:31:06 +13:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2018-08-13 19:58:36 +12:00
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
2018-06-29 14:26:06 +12:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-11-18 15:31:06 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(User)
|