Refactor code

This commit is contained in:
Gabriel Augendre 2016-04-21 01:26:21 +02:00
parent 006c34c68b
commit 2093e1c86b

View file

@ -17,24 +17,24 @@ function getHashParams() {
var Duplicate = React.createClass({
render: function () {
var authors = "";
this.props.data.artists.forEach(function (item, index) {
this.props.track.artists.forEach(function (item, index) {
if (index != 0) {
authors += ', ';
}
authors += item.name;
});
return (
<div className="list-group-item">{this.props.data.name} - {authors}</div>
<div className="list-group-item">{this.props.track.name} - {authors}</div>
);
}
});
var DuplicatesBox = React.createClass({
render: function () {
if (this.props.data && this.props.data.length > 0) {
var duplicates = this.props.data.map(function (duplicate) {
if (this.props.dups && this.props.dups.length > 0) {
var duplicates = this.props.dups.map(function (duplicate) {
return (
<Duplicate data={duplicate.track} key={duplicate.track.id}/>
<Duplicate track={duplicate.track} key={duplicate.track.id}/>
);
});
return (
@ -65,8 +65,8 @@ var PlaylistBox = React.createClass({
render: function () {
var currentId = this.state.currentId;
var playlists;
if (this.props.data) {
playlists = this.props.data.map(function (pl) {
if (this.props.playlists) {
playlists = this.props.playlists.map(function (pl) {
var id = pl.id;
var classes = "list-group-item" + (currentId == id ? " active" : "");
return (
@ -119,13 +119,13 @@ var DuplicateFinderBox = React.createClass({
render: function () {
var duplicates = <p>Loading...</p>;
if (!this.state.loading) {
duplicates = <DuplicatesBox data={this.state.dups}/>;
duplicates = <DuplicatesBox dups={this.state.dups}/>;
}
return (
<div className="duplicateFinderBox">
<div className="col-md-3">
<h2>Playlists</h2>
<PlaylistBox handleClick={this.handlePlaylistClick} data={this.props.playlists}/>
<PlaylistBox handleClick={this.handlePlaylistClick} playlists={this.props.playlists}/>
</div>
<div className="col-md-6">
<h2>Duplicates</h2>