2016-12-26 08:29:18 -05:00
|
|
|
var assign = require('object-assign');
|
|
|
|
|
|
|
|
var SuggestionConstants = require('../constants/SuggestionConstants');
|
|
|
|
var UserConstants = require('../constants/UserConstants');
|
|
|
|
|
2016-12-28 09:25:20 -05:00
|
|
|
module.exports = function(state = [], action) {
|
2016-12-26 08:29:18 -05:00
|
|
|
switch (action.type) {
|
|
|
|
case SuggestionConstants.POPULAR_SUGGESTIONS_FETCHED:
|
2016-12-28 09:25:20 -05:00
|
|
|
var suggestions = [];
|
2016-12-26 08:29:18 -05:00
|
|
|
for (var i = 0; i < action.suggestions.length; i++) {
|
2016-12-28 09:25:20 -05:00
|
|
|
suggestions.push(action.suggestions[i]);
|
2016-12-26 08:29:18 -05:00
|
|
|
}
|
2016-12-28 09:25:20 -05:00
|
|
|
suggestions.sort(function(a, b){return a.Popularity - b.Popularity});
|
2016-12-26 08:29:18 -05:00
|
|
|
return suggestions;
|
|
|
|
case UserConstants.USER_LOGGEDOUT:
|
2016-12-28 09:25:20 -05:00
|
|
|
return [];
|
2016-12-26 08:29:18 -05:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|