Skip to content

Commit

Permalink
Select a person by clicking on her
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsaraujo committed May 24, 2022
1 parent bff6460 commit 7cf5af7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/actions/people_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var Actions = Reflux.createActions([
'add',
'remove',
'shuffle',
'nextDriver'
'nextDriver',
'selectDriver'
]);

export default Actions;
12 changes: 8 additions & 4 deletions src/components/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ import PeopleActions from '../actions/people_actions';
import ClassNames from 'classnames';

class Person extends React.Component {
handleClick() {
remove() {
PeopleActions.remove(this.props.index);
}

select() {
PeopleActions.selectDriver(this.props.index);
}

render() {
var classes = ClassNames({
active: this.props.isCurrent
});

return (
<li className={classes}>
<a href="#" className="remove" onClick={this.handleClick.bind(this)}>x</a>
<span>{this.props.name}</span>
<a href="#" className="remove" onClick={this.remove.bind(this)}>x</a>
<span onClick={this.select.bind(this)}>{this.props.name}</span>
</li>
);
}
};
}

Person.propTypes = {
name: React.PropTypes.string.isRequired
Expand Down
8 changes: 7 additions & 1 deletion src/stores/people_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var Store = Reflux.createStore({
},

// Actions

onAdd(name) {
if (name.length > 0) {
this.people.push(name);
Expand Down Expand Up @@ -51,6 +50,13 @@ var Store = Reflux.createStore({
this.trigger();
},

onSelectDriver(index) {
this.currentDriverIndex = index;

this.commitCurrentDriver();
this.trigger();
},

onNextDriver() {
this.currentDriverIndex += 1;
if (this.currentDriverIndex >= this.people.length) {
Expand Down

0 comments on commit 7cf5af7

Please sign in to comment.