Refactor UI, Add ability to remove suggestions

This commit is contained in:
2017-01-01 08:10:58 -05:00
parent d7adb27c10
commit 0400dd06b6
10 changed files with 222 additions and 55 deletions

View File

@ -33,6 +33,19 @@ function suggestionCreated(suggestion) {
}
}
function removeSuggestion() {
return {
type: SuggestionConstants.REMOVE_SUGGESTION
}
}
function suggestionRemoved(suggestionId) {
return {
type: SuggestionConstants.SUGGESTION_REMOVED,
suggestionId: suggestionId
}
}
function fetchPopularSuggestions() {
return {
type: SuggestionConstants.FETCH_POPULAR_SUGGESTIONS
@ -129,8 +142,33 @@ function fetchPopular() {
};
}
function remove(suggestion) {
return function(dispatch) {
dispatch(removeSuggestion());
$.ajax({
type: "DELETE",
dataType: "json",
url: "suggestion/"+suggestion.SuggestionId+"/",
success: function(data, status, jqXHR) {
var e = new Error();
e.fromJSON(data);
if (e.isError()) {
ErrorActions.serverError(e);
} else {
dispatch(suggestionRemoved(suggestion.SuggestionId));
}
},
error: function(jqXHR, status, error) {
ErrorActions.ajaxError(e);
}
});
};
}
module.exports = {
fetchAll: fetchAll,
create: create,
remove: remove,
fetchPopular: fetchPopular
};