27 lines
784 B
JavaScript
27 lines
784 B
JavaScript
|
var assign = require('object-assign');
|
||
|
|
||
|
var SuggestionConstants = require('../constants/SuggestionConstants');
|
||
|
var UserConstants = require('../constants/UserConstants');
|
||
|
|
||
|
module.exports = function(state = {}, action) {
|
||
|
switch (action.type) {
|
||
|
case SuggestionConstants.SUGGESTIONS_FETCHED:
|
||
|
var suggestions = {};
|
||
|
for (var i = 0; i < action.suggestions.length; i++) {
|
||
|
var suggestion = action.suggestions[i];
|
||
|
suggestions[suggestion.SuggestionId] = suggestion;
|
||
|
}
|
||
|
return suggestions;
|
||
|
case SuggestionConstants.SUGGESTION_CREATED:
|
||
|
var suggestion = action.suggestion;
|
||
|
var suggestions = assign({}, state, {
|
||
|
[suggestion.SuggestionId]: suggestion
|
||
|
});
|
||
|
return suggestions;
|
||
|
case UserConstants.USER_LOGGEDOUT:
|
||
|
return {};
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
};
|