From d8fdf68cbba32c53c048ebe1644c345472e2d279 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sun, 1 Jan 2017 21:15:22 -0500 Subject: [PATCH] Partial fix for not allowing someone to veto their own suggestion --- js/components/NewSuggestion.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/js/components/NewSuggestion.js b/js/components/NewSuggestion.js index 563867a..1cb9dca 100644 --- a/js/components/NewSuggestion.js +++ b/js/components/NewSuggestion.js @@ -34,11 +34,20 @@ module.exports = React.createClass({ pickNewAttendee: function(props) { // Pick a new attendee if the current one can't be valid *and* we have // a list of valid possibilities + + // Find the last suggestion, if possible + var lastSuggestion = null; + var lastSuggestionId = this.getLastSuggestion(); + if (this.props.suggestions.hasOwnProperty(lastSuggestionId)) + lastSuggestion = this.props.suggestions[lastSuggestionId]; + if (this.state.attendee == null || - !props.attendees.hasOwnProperty(this.state.attendee.AttendeeId)) { - if (Object.keys(props.attendees).length >= 1) { + !props.attendees.hasOwnProperty(this.state.attendee.AttendeeId) || + (lastSuggestion && lastSuggestion.AttendeeId == this.state.attendee.AttendeeId)) { + var attendeeList = this.getAttendeeList(); + if (attendeeList.length >= 1) { this.setState({ - attendee: props.attendees[Object.keys(props.attendees)[0]] + attendee: attendeeList[0] }); } else { this.setState({ @@ -49,8 +58,15 @@ module.exports = React.createClass({ }, getAttendeeList: function() { var attendeeList = []; + var lastSuggestion = null; + + var lastSuggestionId = this.getLastSuggestion(); + if (this.props.suggestions.hasOwnProperty(lastSuggestionId)) + lastSuggestion = this.props.suggestions[lastSuggestionId]; + for (var attendeeId in this.props.attendees) { - attendeeList.push(this.props.attendees[attendeeId]); + if (!lastSuggestion || lastSuggestion.AttendeeId != parseInt(attendeeId, 10)) + attendeeList.push(this.props.attendees[attendeeId]); } return attendeeList; },