DAVIDS/src/public/components/playlist-box.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-04-26 01:46:59 +02:00
/*
* Copyright (c) 2016 Gabriel Augendre <gabriel@augendre.info>
* Free software under MIT License. See LICENSE file.
*/
2016-04-23 02:10:23 +02:00
'use strict';
var React = require('react');
var ReactBootstrap = require('react-bootstrap');
var PlaylistBox = React.createClass({
getInitialState: function () {
return {
currentId: null
};
},
2016-04-27 17:00:11 +02:00
clickOnItem: function (id, uid, title, event) {
2016-04-23 02:10:23 +02:00
event.preventDefault();
if (!this.props.dupsLoading) {
this.setState({currentId: id});
2016-04-27 17:00:11 +02:00
this.props.handleClick(id, uid, title);
}
2016-04-23 02:10:23 +02:00
},
render: function () {
var ListGroup = ReactBootstrap.ListGroup,
ListGroupItem = ReactBootstrap.ListGroupItem;
var currentId = this.state.currentId;
var playlists = <p>No playlist found.</p>;
if (this.props.playlists) {
playlists = this.props.playlists.map(function (pl) {
var id = pl.id;
var active = currentId == id;
2016-05-07 19:18:07 +02:00
var dupsCount = active ? !this.props.dupsLoading && this.props.dupsCount : "";
2016-04-23 02:10:23 +02:00
return (
<ListGroupItem href="#"
2016-04-27 17:00:11 +02:00
onClick={this.clickOnItem.bind(this, id, pl.owner.id, pl.name)}
2016-05-07 19:18:07 +02:00
disabled={this.props.dupsLoading}
active={active}
key={id}>
2016-05-07 19:18:07 +02:00
{pl.name} <span className="badge">{dupsCount}</span>
</ListGroupItem>
2016-04-23 02:10:23 +02:00
);
}, this);
}
return (
<ListGroup>
{playlists}
</ListGroup>
);
}
});
module.exports = PlaylistBox;