diff --git a/app.js b/app.js index 434b9c0..4cb22b7 100644 --- a/app.js +++ b/app.js @@ -91,9 +91,16 @@ app.get('/callback', function (req, res) { refresh_token = body.refresh_token; // we can also pass the token to the browser to make requests from there - res.send('') + res.redirect('/#' + + querystring.stringify({ + access_token: access_token, + refresh_token: refresh_token + })); } else { - res.send('') + res.redirect('/#' + + querystring.stringify({ + error: 'invalid_token' + })); } }); } diff --git a/public/index.html b/public/index.html index 1911af9..905efbe 100644 --- a/public/index.html +++ b/public/index.html @@ -9,30 +9,8 @@
- - - + diff --git a/public/script.js b/public/script.js index f1e66e2..5c03bea 100644 --- a/public/script.js +++ b/public/script.js @@ -1,9 +1,36 @@ 'use strict'; +/** + * Obtains parameters from the hash of the URL + * @return Object + */ +function getHashParams() { + var hashParams = {}; + var e, r = /([^&;=]+)=?([^&;]*)/g, + q = window.location.hash.substring(1); + while (e = r.exec(q)) { + hashParams[e[1]] = decodeURIComponent(e[2]); + } + return hashParams; +} + + var data = [ - {id: 1, name: "Mine"}, - {id: 2, name: "Other"}, - {id: 3, name: "A third"} + { + href: "https://api.spotify.com/v1/users/wizzler/playlists/53Y8wT46QIMz5H4WQ8O22c", + id: "53Y8wT46QIMz5H4WQ8O22c", + name: "Wizzlers Big Playlist", + owner: { + id: "wizzler" + } + }, { + href: "https://api.spotify.com/v1/users/wizzlersmate/playlists/1AVZz0mBuGbCEoNRQdYQju", + id: "1AVZz0mBuGbCEoNRQdYQju", + name: "Another Playlist", + owner: { + id: "wizzlersmate" + } + } ]; var dups = [ @@ -69,35 +96,49 @@ var Duplicate = React.createClass({ var DuplicatesBox = React.createClass({ render: function () { - var duplicates = this.props.data.map(function (duplicate) { + if (this.props.data && this.props.data.length > 0) { + var duplicates = this.props.data.map(function (duplicate) { + return ( +No duplicate found
+ ); + } } }); -var Playlist = React.createClass({ - render: function () { - return ( - {this.props.name} - ); - } -}); - var PlaylistBox = React.createClass({ + getInitialState: function () { + return { + currentId: null + }; + }, + clickOnItem: function (id, uid) { + this.setState({currentId: id}); + this.props.handleClick(id, uid); + }, render: function () { - var playlists = this.props.data.map(function (playlist) { - return ( -Loading...
; + if (!this.state.loading) { + duplicates =Please log in with Spotify :)
+ if (this.isLoggedIn()) { + content = ( +