diff --git a/app/controllers/web/home_controller.rb b/app/controllers/web/home_controller.rb index 0ebf38a..e0db1d7 100644 --- a/app/controllers/web/home_controller.rb +++ b/app/controllers/web/home_controller.rb @@ -3,7 +3,7 @@ module Web class HomeController < ApplicationController def index - @posts = Post.all.order(created_at: :desc) + @posts = Post.includes(:creator).order(created_at: :desc) end end end diff --git a/app/views/web/posts/comments/_show.html.slim b/app/views/web/posts/comments/_show.html.slim index 442f429..0ec08b7 100644 --- a/app/views/web/posts/comments/_show.html.slim +++ b/app/views/web/posts/comments/_show.html.slim @@ -1,5 +1,5 @@ .mb-3.mt-3 - - comments.arrange.each do |comment, _sub_item| + - comments.each do |comment, child_comments| .card.mb-2 .card-body .card-text @@ -8,10 +8,10 @@ = render partial: 'web/shared/creation_data', locals: { email: comment.user.email, created_at: comment.created_at } -if comment.has_children? - = render partial: 'web/posts/comments/show', locals: { comments: comment.children } + = render partial: 'web/posts/comments/show', locals: { comments: child_comments, current_comment: current_comment, post: post } div - if user_signed_in? a.text-decoration-none[data-bs-toggle="collapse" href="#collapse-#{comment.id}" role="button" aria-expanded="false"] = t('.reply') .collapse[id="collapse-#{comment.id}"] .mb-2.m-4 - = render partial: 'web/posts/comments/form', locals: { comment: @comment, parent_id: comment.id, url: post_comments_path(@post, @comment) } + = render partial: 'web/posts/comments/form', locals: { comment: current_comment, parent_id: comment.id, url: post_comments_path(post, current_comment) } diff --git a/app/views/web/posts/likes/_links.html.slim b/app/views/web/posts/likes/_links.html.slim index 163dc75..4024eea 100644 --- a/app/views/web/posts/likes/_links.html.slim +++ b/app/views/web/posts/likes/_links.html.slim @@ -1,10 +1,8 @@ -- if like.present? - .d-flex - .mx-2 = @post.likes_count || 0 - = link_to(post_like_path(@post, like, anchor: 'likes-section'), rel: :nofollow, method: :delete, class: 'text-dark') do - i.fa-solid.fa-thumbs-up -- else - .d-flex - .mx-2 = @post.likes_count || 0 - = link_to(post_likes_path(@post, anchor: 'likes-section'), rel: :nofollow, method: :post, class: 'text-dark') do - i.fa-regular.fa-thumbs-up +.d-flex + .mx-2 = post.likes_count || 0 + - if like.present? + = link_to(post_like_path(post, like, anchor: 'likes-section'), rel: :nofollow, method: :delete, class: 'text-dark') do + i.fa-solid.fa-thumbs-up + - else + = link_to(post_likes_path(post, anchor: 'likes-section'), rel: :nofollow, method: :post, class: 'text-dark') do + i.fa-regular.fa-thumbs-up diff --git a/app/views/web/posts/show.html.slim b/app/views/web/posts/show.html.slim index 693544e..c8066b1 100644 --- a/app/views/web/posts/show.html.slim +++ b/app/views/web/posts/show.html.slim @@ -14,11 +14,11 @@ p .d-flex.justify-content-between = render partial: 'web/shared/creation_data', locals: { email: @post.creator.email, created_at: @post.created_at } - = render partial: 'web/posts/likes/links', locals: { like: @like_current_user } + = render partial: 'web/posts/likes/links', locals: { like: @like_current_user, post: @post } - if user_signed_in? h3 | #{t('.title')} = render partial: 'web/posts/comments/form', locals: { comment: @comment, parent_id: nil, url: post_comments_path(@post, @comment) } -= render partial: 'web/posts/comments/show', locals: { comments: @comments } += render partial: 'web/posts/comments/show', locals: { comments: @comments.arrange, current_comment: @comment, post: @post }