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