From 2a7a19c93ee0e0d77e4e388d43f36a721c7ab715 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 20 Oct 2023 21:27:06 -0400 Subject: Added post voting --- app/views/blogs/_blog.html.haml | 4 ++++ app/views/blogs/voted.js.erb | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 app/views/blogs/voted.js.erb (limited to 'app/views') diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index ec61bb5..1f86ae8 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -19,3 +19,7 @@ %strong= blog.user.login.capitalize on = blog.visible_date.strftime("%B #{blog.visible_date.day.ordinalize}, %Y at %-I:%M:%S%P") + .post-vote{ id: "blog-vote-section-#{blog.id}" } + %span.vote-link{ id: "blog-upvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_upvoted?(request.remote_ip)), "👍", upvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-upvote-link", method: :post + %span.post-rating{ id: "blog-rating-#{blog.id}" }= blog.upvotes - blog.downvotes + %span.vote-link{ id: "blog-downvote-link-#{blog.id}" }= link_to_unless (not blog.published or blog.already_downvoted?(request.remote_ip)), "👎", downvote_blog_path(blog), remote: true, rel: "nofollow", class: "blog-downvote-link", method: :post diff --git a/app/views/blogs/voted.js.erb b/app/views/blogs/voted.js.erb new file mode 100644 index 0000000..951c740 --- /dev/null +++ b/app/views/blogs/voted.js.erb @@ -0,0 +1,12 @@ +$("#blog-rating-<%= @blog.id %>").html('<%= escape_javascript("#{@blog.upvotes - @blog.downvotes}") %>'); + +<% if @blog.already_upvoted? request.remote_ip %> + $("#blog-upvote-link-<%= @blog.id %>").html("👍"); +<% elsif @blog.already_downvoted? request.remote_ip %> + $("#blog-downvote-link-<%= @blog.id %>").html("👎"); +<% else %> + $("#blog-upvote-link-<%= @blog.id %>").html('<%= escape_javascript(link_to("👍", upvote_blog_path(@blog), remote: true, rel: "nofollow", class: "blog-upvote-link", method: :post)) %>'); + $("#blog-downvote-link-<%= @blog.id %>").html('<%= escape_javascript(link_to("👎", downvote_blog_path(@blog), remote: true, rel: "nofollow", class: "blog-downvote-link", method: :post)) %>'); +<% end %> + +$("#blog-vote-section-<%= @blog.id %>").effect('highlight', {}, 2000); -- cgit 1.4.1