import React from 'react';
import ReactDOM from 'react-dom';
export default class Sidebar extends React.Component {
createDeck(event) {
if(event.which !== 13) return;
var name = 'ReactDOM.findDOMNode(this.refs.add).value';
this.props.addDeck(name);
this.props.hideAddDeck();
}
addingDeck(event) {
this.props.showAddDeck();
}
render() {
let props = this.props;
return (
<div className="sidebar">
<h2>All Decks</h2>
<button onClick={e => this.addingDeck(e)}>
New Deck
</button>
<ul>
{props.decks.map((deck, i) => {
return <li key={i}>{deck.name}</li>
})
}
</ul>
{ this.props.addingDeck && <input ref='add' onKeyPress={e => this.createDeck(e)}/> }
</div>
);
}
}