2016-11-18 15:31:06 +13:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react'
|
2016-11-18 15:31:06 +13:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
2019-01-22 21:46:56 +13:00
|
|
|
import ErrorMessage from '../components/ErrorMessage';
|
|
|
|
|
import Thumbnail from '../components/Thumbnail';
|
|
|
|
|
import PlaylistGrid from '../components/PlaylistGrid';
|
|
|
|
|
import FollowButton from '../components/Fields/FollowButton';
|
|
|
|
|
import LazyLoadListener from '../components/LazyLoadListener';
|
|
|
|
|
import Parallax from '../components/Parallax';
|
2019-02-21 16:56:07 +13:00
|
|
|
import NiceNumber from '../components/NiceNumber';
|
2019-01-22 21:46:56 +13:00
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger';
|
|
|
|
|
import Icon from '../components/Icon';
|
|
|
|
|
|
|
|
|
|
import * as helpers from '../helpers';
|
|
|
|
|
import * as coreActions from '../services/core/actions';
|
|
|
|
|
import * as uiActions from '../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions';
|
2016-11-18 15:31:06 +13:00
|
|
|
|
|
|
|
|
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();
|
2019-01-30 16:59:51 +13:00
|
|
|
this.props.coreActions.loadUser(this.props.uri);
|
|
|
|
|
this.props.coreActions.loadUserPlaylists(this.props.uri);
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
2019-01-30 16:59:51 +13:00
|
|
|
if (nextProps.uri != this.props.uri){
|
|
|
|
|
this.props.coreActions.loadUser(nextProps.uri);
|
|
|
|
|
this.props.coreActions.loadUserPlaylists(this.props.uri);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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',
|
2019-01-30 16:59:51 +13:00
|
|
|
parent_key: this.props.uri,
|
2017-11-10 15:56:01 +13:00
|
|
|
records_type: 'playlist'
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
2017-02-08 08:34:14 +13:00
|
|
|
isMe(){
|
2019-01-30 16:59:51 +13:00
|
|
|
let userid = helpers.getFromUri('userid',this.props.uri);
|
2017-09-27 15:29:17 +13:00
|
|
|
return (this.props.me && this.props.me.id && this.props.me.id == userid);
|
2016-11-18 15:31:06 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2019-01-30 16:59:51 +13:00
|
|
|
var user_id = helpers.getFromUri('userid',this.props.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 {
|
2019-01-22 21:46:56 +13:00
|
|
|
return (
|
|
|
|
|
<ErrorMessage type="not-found" title="Not found">
|
2019-01-30 16:59:51 +13:00
|
|
|
<p>Could not find user with URI "{encodeURIComponent(this.props.uri)}"</p>
|
2019-01-22 21:46:56 +13:00
|
|
|
</ErrorMessage>
|
|
|
|
|
);
|
2018-04-10 20:14:31 +12:00
|
|
|
}
|
2017-11-01 08:14:26 +13:00
|
|
|
}
|
2017-06-27 09:37:33 +12:00
|
|
|
|
2018-08-31 16:04:55 +12:00
|
|
|
var user = helpers.collate(this.props.user, {playlists: this.props.playlists});
|
2017-06-27 09:37:33 +12:00
|
|
|
|
2018-08-31 16:04:55 +12:00
|
|
|
if (user && user.images){
|
2018-09-09 21:23:57 +12:00
|
|
|
var image = user.images.huge;
|
2017-02-26 18:33:20 +13:00
|
|
|
} else {
|
2018-08-31 16:04:55 +12:00
|
|
|
var image = null;
|
2017-06-27 09:37:33 +12:00
|
|
|
}
|
2017-02-26 18:33:20 +13:00
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
return (
|
2018-10-26 06:15:05 +13:00
|
|
|
<div className="view user-view preserve-3d">
|
|
|
|
|
<div className="intro preserve-3d">
|
2018-12-19 21:47:02 +13:00
|
|
|
|
|
|
|
|
<Parallax image={image} fixedHeight />
|
|
|
|
|
|
2017-06-27 09:37:33 +12:00
|
|
|
<div className="liner">
|
2018-08-31 16:04:55 +12:00
|
|
|
<h1>{user.name}</h1>
|
2017-06-27 09:37:33 +12:00
|
|
|
<h2>
|
|
|
|
|
<ul className="details">
|
2019-02-21 16:56:07 +13:00
|
|
|
{!this.props.slim_mode ? <li className="source"><Icon type="fontawesome" name={helpers.sourceIcon(user.uri )} /></li> : null}
|
|
|
|
|
{user.playlists_total ? <li><NiceNumber value={user.playlists_total} /> playlists</li> : null}
|
|
|
|
|
{user.followers ? <li><NiceNumber value={user.followers} /> 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">
|
2018-08-31 16:04:55 +12:00
|
|
|
<FollowButton className="primary" uri={user.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>
|
2018-08-31 16:04:55 +12:00
|
|
|
<PlaylistGrid playlists={user.playlists} />
|
2018-09-03 08:24:49 +12:00
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={user.playlists_more}
|
|
|
|
|
showLoader={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) => {
|
2019-01-30 16:59:51 +13:00
|
|
|
var uri = decodeURIComponent(ownProps.match.params.uri);
|
2016-11-18 15:31:06 +13:00
|
|
|
return {
|
2019-01-30 16:59:51 +13:00
|
|
|
uri: uri,
|
2018-08-31 16:04:55 +12:00
|
|
|
me: state.spotify.me,
|
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,
|
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)
|