Refactor UI, Add ability to remove suggestions
This commit is contained in:
@ -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
|
||||
};
|
||||
|
Reference in New Issue
Block a user