import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
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';
import NiceNumber from '../components/NiceNumber';
import Loader from '../components/Loader';
import Icon from '../components/Icon';
import * as coreActions from '../services/core/actions';
import * as uiActions from '../services/ui/actions';
import * as spotifyActions from '../services/spotify/actions';
import {
isLoading,
getFromUri,
sourceIcon,
} from '../util/helpers';
import { collate } from '../util/format';
class User extends React.Component {
componentDidMount() {
this.setWindowTitle();
this.props.coreActions.loadUser(this.props.uri);
this.props.coreActions.loadUserPlaylists(this.props.uri);
}
componentDidUpdate = ({
uri: prevUri,
user: prevUser,
}) => {
const {
uri,
user,
coreActions: {
loadUser,
loadUserPlaylists,
},
} = this.props;
if (prevUri !== uri) {
loadUser(uri);
loadUserPlaylists(uri);
}
if (!prevUser && user) this.setWindowTitle(user);
}
setWindowTitle(user = this.props.user) {
if (user) {
this.props.uiActions.setWindowTitle(`${user.name} (user)`);
} else {
this.props.uiActions.setWindowTitle('User');
}
}
loadMore() {
this.props.spotifyActions.getMore(
this.props.user.playlists_more,
{
parent_type: 'user',
parent_key: this.props.uri,
records_type: 'playlist',
},
);
}
isMe() {
const userid = getFromUri('userid', this.props.uri);
return (this.props.me && this.props.me.id && this.props.me.id == userid);
}
render() {
const user_id = getFromUri('userid', this.props.uri);
if (!this.props.user) {
if (isLoading(this.props.load_queue, [`spotify_users/${user_id}`, `spotify_users/${user_id}/playlists/?`])) {
return
Could not find user with URI "
{encodeURIComponent(this.props.uri)}
"