1
0
Fork 0

Remainder of fix for not allowing someone to veto their own suggestion

This commit is contained in:
Aaron Lindsay 2017-01-02 07:38:37 -05:00
parent c4ea521e52
commit 17d87a2b30
1 changed files with 18 additions and 12 deletions

View File

@ -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;
}