Loading...
;
if (!this.props.playlistsLoading) {
playlistBox = ;
}
return (
Playlists
{playlistBox}
{duplicates}
);
}
});
var Authenticate = React.createClass({
logout: function () {
this.props.refreshAuth(null, null);
},
refreshToken: function (event) {
event.preventDefault();
var self = this;
$.ajax({
url: '/refresh_token',
data: {
'refresh_token': self.props.auth.refresh_token
},
success: function (data) {
self.props.refreshAuth(data.access_token, self.props.auth.refresh_token);
},
error: function (xhr, status, err) {
console.error(status, err);
}
});
},
render: function () {
var auth;
var Nav = ReactBootstrap.Nav,
NavItem = ReactBootstrap.NavItem,
Navbar = ReactBootstrap.Navbar;
if (this.props.auth.access_token == null) {
auth = (
);
}
else {
auth = (
);
}
return (
Duplicate Finder
{auth}
);
}
});
var App = React.createClass({
getInitialState: function () {
var params = getHashParams();
var access_token = params.access_token || null;
var refresh_token = params.refresh_token || null;
return {
access_token: access_token,
refresh_token: refresh_token,
playlists: null,
playlistsLoading: true
};
},
getPlaylists: function () {
this.setState({
playlistsLoading: true
});
var self = this;
$.ajax({
url: '/get_playlists',
data: {
'access_token': this.state.access_token
},
success: function (data) {
var pl = data.data;
self.setState({
playlists: pl,
playlistsLoading: false
});
},
error: function (xhr, response, err) {
console.error(response, err);
}
});
},
isLoggedIn: function () {
return !(this.state.access_token == null && this.state.refresh_token == null);
},
refreshAuth: function (access, refresh) {
this.setState({
access_token: access,
refresh_token: refresh
});
if (!(access == null && refresh == null)) {
this.getPlaylists();
}
},
componentDidMount: function () {
if (this.isLoggedIn()) {
this.getPlaylists();
}
},
render: function () {
var auth = {
access_token: this.state.access_token,
refresh_token: this.state.refresh_token
};
var content = Please log in with Spotify :)
;
if (this.isLoggedIn()) {
var playlistsLoading = this.state.playlistsLoading;
content = (
);
}
return (
);
}
});
ReactDOM.render(
,
document.getElementById('content')
);