From 17d87a2b308f4b8b9251d144fecab6aef9159855 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 2 Jan 2017 07:38:37 -0500 Subject: [PATCH] Remainder of fix for not allowing someone to veto their own suggestion --- js/components/NewSuggestion.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/js/components/NewSuggestion.js b/js/components/NewSuggestion.js index 1cb9dca..45a0534 100644 --- a/js/components/NewSuggestion.js +++ b/js/components/NewSuggestion.js @@ -37,14 +37,14 @@ module.exports = React.createClass({ // Find the last suggestion, if possible var lastSuggestion = null; - var lastSuggestionId = this.getLastSuggestion(); - if (this.props.suggestions.hasOwnProperty(lastSuggestionId)) - lastSuggestion = this.props.suggestions[lastSuggestionId]; + var lastSuggestionId = this.getLastSuggestion(props); + if (props.suggestions.hasOwnProperty(lastSuggestionId)) + lastSuggestion = props.suggestions[lastSuggestionId]; if (this.state.attendee == null || !props.attendees.hasOwnProperty(this.state.attendee.AttendeeId) || (lastSuggestion && lastSuggestion.AttendeeId == this.state.attendee.AttendeeId)) { - var attendeeList = this.getAttendeeList(); + var attendeeList = this.getAttendeeList(props); if (attendeeList.length >= 1) { this.setState({ attendee: attendeeList[0] @@ -56,23 +56,29 @@ module.exports = React.createClass({ } } }, - getAttendeeList: function() { + getAttendeeList: function(props) { + if (!props) + props = this.props; + var attendeeList = []; var lastSuggestion = null; - var lastSuggestionId = this.getLastSuggestion(); - if (this.props.suggestions.hasOwnProperty(lastSuggestionId)) - lastSuggestion = this.props.suggestions[lastSuggestionId]; + var lastSuggestionId = this.getLastSuggestion(props); + if (props.suggestions.hasOwnProperty(lastSuggestionId)) + lastSuggestion = props.suggestions[lastSuggestionId]; - for (var attendeeId in this.props.attendees) { + for (var attendeeId in props.attendees) { if (!lastSuggestion || lastSuggestion.AttendeeId != parseInt(attendeeId, 10)) - attendeeList.push(this.props.attendees[attendeeId]); + attendeeList.push(props.attendees[attendeeId]); } return attendeeList; }, - getLastSuggestion: function() { + getLastSuggestion: function(props) { + if (!props) + props = this.props; + var lastSuggestion = -1; - for (var suggestionId in this.props.suggestions) { + for (var suggestionId in props.suggestions) { if (suggestionId > lastSuggestion) lastSuggestion = suggestionId; }