From 00befc96f02da20dfe38b742ed74ce1db4b0869d Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 21 Nov 2021 18:04:52 -0600 Subject: [PATCH] /comments: add vote buttons beneath thumbnails on /comments page. Also fix an N+1 queries problem. --- .../post_votes_component/post_votes_component.scss | 2 +- app/controllers/comments_controller.rb | 5 ----- app/views/comments/_index_by_post.html.erb | 4 ++-- app/views/comments/partials/index/_header.html.erb | 4 ---- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/components/post_votes_component/post_votes_component.scss b/app/components/post_votes_component/post_votes_component.scss index b5abde985..6b7945144 100644 --- a/app/components/post_votes_component/post_votes_component.scss +++ b/app/components/post_votes_component/post_votes_component.scss @@ -12,7 +12,7 @@ } } -.posts-container { +article.post-preview { .post-score a { @include inactive-link; } diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fdb3e4162..2001b9bf8 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -84,11 +84,6 @@ class CommentsController < ApplicationController @limit = params.fetch(:limit, 20) @posts = Post.where.not(last_comment_bumped_at: nil).user_tag_match(params[:tags]).reorder("last_comment_bumped_at DESC NULLS LAST").paginate(params[:page], limit: @limit, search_count: params[:search]) - if request.format.html? - @posts = @posts.includes(comments: [:creator]) - @posts = @posts.includes(comments: [:votes]) if CurrentUser.is_member? - end - respond_with(@posts) end diff --git a/app/views/comments/_index_by_post.html.erb b/app/views/comments/_index_by_post.html.erb index f3ffffb46..fefdc5029 100644 --- a/app/views/comments/_index_by_post.html.erb +++ b/app/views/comments/_index_by_post.html.erb @@ -3,9 +3,9 @@ <%= render "post_sets/blank" %> <% end %> - <% @posts.select(&:visible?).each do |post| %> + <% @posts.includes(:media_asset, :uploader, :vote_by_current_user, comments: [:creator, :votes]).select(&:visible?).each do |post| %> <%= tag.div id: "post_#{post.id}", **PostPreviewComponent.new(post: post).article_attrs("post space-x-4") do %> - <%= post_preview(post, show_deleted: true) %> + <%= post_preview(post, show_deleted: true, show_votes: true) %>
<%= render "comments/partials/index/header", post: post %> diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb index dd806d822..ef4643b03 100644 --- a/app/views/comments/partials/index/_header.html.erb +++ b/app/views/comments/partials/index/_header.html.erb @@ -12,10 +12,6 @@ Rating <%= post.pretty_rating %> - - Score - <%= render_post_votes post, current_user: CurrentUser.user %> -
Tags