mode menu: refactor favorite and vote options.

This commit is contained in:
evazion
2020-02-20 03:40:01 -06:00
parent c89c7ccc63
commit 610ad9e119
3 changed files with 4 additions and 50 deletions

View File

@@ -1,37 +0,0 @@
import Post from './posts.js.erb'
import Utility from './utility'
let Favorite = {}
Favorite.create = function(post_id) {
Post.notice_update("inc");
$.ajax({
type: "POST",
url: "/favorites.js",
data: {
post_id: post_id
},
complete: function() {
Post.notice_update("dec");
},
error: function(data, status, xhr) {
Utility.notice("Error: " + data.reason);
}
});
}
Favorite.destroy = function(post_id) {
Post.notice_update("inc");
$.ajax({
type: "DELETE",
url: "/favorites/" + post_id + ".js",
complete: function() {
Post.notice_update("dec");
}
});
}
export default Favorite

View File

@@ -1,5 +1,4 @@
import CurrentUser from './current_user'
import Favorite from './favorites'
import Post from './posts.js.erb'
import Utility from './utility'
@@ -156,15 +155,15 @@ PostModeMenu.click = function(e) {
var post_id = $(e.target).closest("article").data("id");
if (s === "add-fav") {
Favorite.create(post_id);
Post.tag(post_id, "fav:me");
} else if (s === "remove-fav") {
Favorite.destroy(post_id);
Post.tag(post_id, "-fav:me");
} else if (s === "edit") {
PostModeMenu.open_edit(post_id);
} else if (s === 'vote-down') {
Post.vote("down", post_id);
Post.tag(post_id, "downvote:me");
} else if (s === 'vote-up') {
Post.vote("up", post_id);
Post.tag(post_id, "upvote:me");
} else if (s === 'approve') {
Post.approve(post_id);
} else if (s === "tag-script") {

View File

@@ -498,14 +498,6 @@ Post.update_data = function(data) {
}
}
Post.vote = function(score, id) {
Utility.notice("Voting...");
$.post("/posts/" + id + "/votes.js", {
score: score
});
}
Post.tag = function(post_id, tags) {
const tag_string = (Array.isArray(tags) ? tags.join(" ") : String(tags));
Post.update(post_id, { "post[old_tag_string]": "", "post[tag_string]": tag_string });