Permalink
Browse files

Stage 4: Deleting contact

  • Loading branch information...
juhofriman committed Jul 19, 2016
1 parent 4820f9a commit 99bab576bc7398be6e8fd6d5e883941a6e848ab9
Showing with 13 additions and 0 deletions.
  1. +6 −0 src/ContactListing.jsx
  2. +7 −0 src/PhoneBook.jsx
View
@@ -2,13 +2,18 @@
var React = require('react');
var ContactListing = require('./ContactListing.jsx');
+var eb = require('./eventbus.js');
var ContactTableRow = React.createClass({
+ fireDelete: function() {
+ eb.publish('DELETE_CONTACT', this.props.contact);
+ },
render: function() {
return (
<tr>
<td>{this.props.contact.lastname}, {this.props.contact.firstname}</td>
<td>{this.props.contact.phone}</td>
+ <td><button className="ink-button red small" onClick={this.fireDelete}>Delete</button></td>
</tr>
);
}
@@ -28,6 +33,7 @@ module.exports = React.createClass({
<tr>
<th className="align-left">Name</th>
<th className="align-left">Phone</th>
+ <th className="align-left"></th>
</tr>
</thead>
<tbody>
View
@@ -52,6 +52,13 @@ module.exports = React.createClass({
}
}});
});
+ eb.on(this, 'DELETE_CONTACT', function(contact) {
+ console.log('DELETE_CONTACT received');
+ var newContacts = this.state.contacts.filter(function(c) {
+ return c.firstname !== contact.firstname || c.lastname !== contact.lastname ;
+ });
+ this.setState({contacts: newContacts});
+ });
},
getContacts: function() {
if(this.state.nameFilter === '') {

0 comments on commit 99bab57

Please sign in to comment.