diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index d8b9ea6f..3b9c2e93 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -7,4 +7,11 @@ class CommentController < ApplicationController render "index", locals: { a: answer } end + + def show_reactions + comment = Comment.find(params[:id]) + @reactions = Appendable::Reaction.where(parent_type: "Comment", parent: comment.id).includes([{ user: :profile }]) + + redirect_to answer_path(username: comment.answer.user.screen_name, id: comment.answer.id) unless turbo_frame_request? + end end diff --git a/app/views/actions/_comment.html.haml b/app/views/actions/_comment.html.haml index 23b8e408..a88d7a4a 100644 --- a/app/views/actions/_comment.html.haml +++ b/app/views/actions/_comment.html.haml @@ -1,5 +1,5 @@ .dropdown-menu.dropdown-menu-end{ role: :menu } - %a.dropdown-item{ href: "#", data: { bs_target: "#modal-view-comment#{comment.id}-smiles", bs_toggle: :modal } } + = link_to comment_reactions_path(username: comment.user.screen_name, id: comment.id), class: "dropdown-item", data: { turbo_frame: "modal" } do %i.fa.fa-fw.fa-smile-o = t(".view_smiles") - if privileged?(comment.user) || privileged?(answer.user) diff --git a/app/views/answerbox/_comments.html.haml b/app/views/answerbox/_comments.html.haml index a03e4e10..78ce559b 100644 --- a/app/views/answerbox/_comments.html.haml +++ b/app/views/answerbox/_comments.html.haml @@ -4,7 +4,6 @@ %ul.comment__container - comments.order(:created_at).each do |comment| %li.comment{ data: { comment_id: comment.id } } - %div{ style: "height: 0; width: 0" }= render "modal/comment_smiles", comment: comment .d-flex .flex-shrink-0 %a{ href: user_path(comment.user) } diff --git a/app/views/comment/show_reactions.html.haml b/app/views/comment/show_reactions.html.haml new file mode 100644 index 00000000..90ec41fe --- /dev/null +++ b/app/views/comment/show_reactions.html.haml @@ -0,0 +1,21 @@ += turbo_frame_tag "modal" do + .modal.fade.show.d-block{ id: "modal-view-comment-smiles", aria: { hidden: false, labelledby: "modal-commentsmile-label" }, role: :dialog, tabindex: -1 } + .modal-dialog + .modal-content + .modal-header + %h5.modal-title#modal-commentsmile-label= t(".title") + = button_to modal_close_path, method: :get, class: "btn-close" do + %span.visually-hidden Close + .modal-body + - if @reactions.count.zero? + = t(".none") + - else + %ul.smiles__user-list + - @reactions.each do |smile| + %li.smiles__user-list-entry + %a{ href: user_path(smile.user) } + %img{ src: smile.user.profile_picture.url(:small), alt: user_screen_name(smile.user, url: false) } + %span= user_screen_name(smile.user, url: false) + .modal-footer + = button_to t("voc.close"), modal_close_path, method: :get, class: "btn btn-default" + .modal-backdrop.fade.show diff --git a/app/views/modal/_comment_smiles.html.haml b/app/views/modal/_comment_smiles.html.haml deleted file mode 100644 index 70cf7772..00000000 --- a/app/views/modal/_comment_smiles.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -.modal.fade{ id: "modal-view-comment#{comment.id}-smiles", aria: { hidden: true, labelledby: "modal-commentsmile-label" }, role: :dialog, tabindex: -1 } - .modal-dialog - .modal-content - .modal-header - %h5.modal-title#modal-commentsmile-label= t(".title") - %button.btn-close{ data: { bs_dismiss: :modal }, type: :button } - %span.visually-hidden Close - .modal-body - - if comment.smiles.all.count.zero? - = t(".none") - - else - %ul.smiles__user-list - - comment.smiles.all.each do |smile| - %li.smiles__user-list-entry - %a{ href: user_path(smile.user) } - %img{ src: smile.user.profile_picture.url(:small), alt: user_screen_name(smile.user, url: false) } - %span= user_screen_name(smile.user, url: false) diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml index 1af7cb01..d0426826 100644 --- a/config/locales/views.en.yml +++ b/config/locales/views.en.yml @@ -150,6 +150,10 @@ en: non_anonymous_html: | This user does not want to receive anonymous questions.
(%{sign_in} or %{sign_up}) + comment: + show_reactions: + title: "People who smiled this comment" + none: "No one has smiled this comment yet." devise: registrations: edit: @@ -262,9 +266,6 @@ en: action: "Ask" loading: "Asking…" long_question_warning: "This question will only be sent to those who allow long questions in their profile settings." - comment_smiles: - title: "People who smiled this comment" - none: "No one has smiled this comment yet." list: title: "Manage list memberships" tab: diff --git a/config/routes.rb b/config/routes.rb index e5fcf899..51e170f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -156,6 +156,7 @@ Rails.application.routes.draw do get "/@:username/a/:id/comments", to: "comment#index", as: :comments get "/@:username/a/:id/reactions", to: "reaction#index", as: :reactions get "/@:username/q/:id", to: "question#show", as: :question + get "/@:username/c/:id/reactions", to: "comment#show_reactions", as: :comment_reactions get "/@:username/followers", to: "user#followers", as: :show_user_followers get "/@:username/followings", to: "user#followings", as: :show_user_followings get "/@:username/friends", to: redirect("/@%{username}/followings")