'use strict';
var $ = window.$ = window.jQuery = require('jquery');
require('bootstrap');
var React = require('react');
var ReactDOM = require('react-dom');
var ReactBootstrap = require('react-bootstrap');
/**
* 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 DuplicatesBox = require('./components/dups/duplicates-box');
var PlaylistBox = React.createClass({
getInitialState: function () {
return {
currentId: null
};
},
clickOnItem: function (id, uid, event) {
event.preventDefault();
this.setState({currentId: id});
this.props.handleClick(id, uid);
},
render: function () {
var ListGroup = ReactBootstrap.ListGroup,
ListGroupItem = ReactBootstrap.ListGroupItem;
var currentId = this.state.currentId;
var playlists =
No playlist found.
;
if (this.props.playlists) {
playlists = this.props.playlists.map(function (pl) {
var id = pl.id;
return (
{pl.name}
);
}, this);
}
return (
{playlists}
);
}
});
var DuplicateFinderBox = React.createClass({
getInitialState: function () {
return {
currentId: null,
currentUId: null,
dups: null,
dupsLoading: false,
clicked: false
};
},
componentWillReceiveProps: function () {
this.setState({
clicked: false
});
},
handlePlaylistClick: function (id, uid) {
this.setState({
currentId: id,
currentUId: uid,
dupsLoading: true,
clicked: true
});
var self = this;
$.ajax({
url: "/pl/" + uid + "/" + id,
data: {
'access_token': self.props.auth.access_token
},
success: function (data) {
var dups = data.data;
self.setState({
dups: dups,
dupsLoading: false
});
},
error: function (xhr, response, err) {
console.error(response, err);
}
});
},
render: function () {
var duplicates;
var Col = ReactBootstrap.Col,
Row = ReactBootstrap.Row;
if (this.state.clicked) {
duplicates =