Refactor comments into CommentComponent
This commit is contained in:
parent
d6b5e2bae7
commit
597c859c2d
|
@ -0,0 +1,22 @@
|
||||||
|
%li.comment{ data: { comment_id: @comment.id } }
|
||||||
|
.d-flex
|
||||||
|
.flex-shrink-0
|
||||||
|
%a{ href: user_path(@comment.user), target: :_top }
|
||||||
|
= render AvatarComponent.new(user: @comment.user, size: "sm", classes: ["comment__user-avatar"])
|
||||||
|
.flex-grow-1
|
||||||
|
%h6.comment__user
|
||||||
|
= user_screen_name @comment.user
|
||||||
|
%span.text-muted
|
||||||
|
·
|
||||||
|
= time_tooltip @comment
|
||||||
|
.comment__content
|
||||||
|
= markdown @comment.content
|
||||||
|
.flex-shrink-0.ms-auto
|
||||||
|
- if current_user&.smiled?(@comment)
|
||||||
|
= render "reactions/destroy", type: "Comment", target: @comment
|
||||||
|
- else
|
||||||
|
= render "reactions/create", type: "Comment", target: @comment
|
||||||
|
.dropdown.d-inline
|
||||||
|
%button.btn.btn-link.answerbox__action{ data: { bs_toggle: :dropdown }, aria: { expanded: false } }
|
||||||
|
%i.fa.fa-fw.fa-ellipsis
|
||||||
|
= render "actions/comment", comment: @comment, answer: @answer
|
|
@ -0,0 +1,12 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CommentComponent < ApplicationComponent
|
||||||
|
include ApplicationHelper
|
||||||
|
include BootstrapHelper
|
||||||
|
include UserHelper
|
||||||
|
|
||||||
|
def initialize(comment:, answer:)
|
||||||
|
@comment = comment
|
||||||
|
@answer = answer
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,25 +3,4 @@
|
||||||
- else
|
- else
|
||||||
%ul.comment__container
|
%ul.comment__container
|
||||||
- comments.order(:created_at).each do |comment|
|
- comments.order(:created_at).each do |comment|
|
||||||
%li.comment{ data: { comment_id: comment.id } }
|
= render CommentComponent.new(comment:, answer: a)
|
||||||
.d-flex
|
|
||||||
.flex-shrink-0
|
|
||||||
%a{ href: user_path(comment.user) }
|
|
||||||
= render AvatarComponent.new(user: comment.user, size: "sm", classes: ["comment__user-avatar"])
|
|
||||||
.flex-grow-1
|
|
||||||
%h6.comment__user
|
|
||||||
= user_screen_name comment.user
|
|
||||||
%span.text-muted
|
|
||||||
·
|
|
||||||
= time_tooltip comment
|
|
||||||
.comment__content
|
|
||||||
= markdown comment.content
|
|
||||||
.flex-shrink-0.ms-auto
|
|
||||||
- if current_user&.smiled?(comment)
|
|
||||||
= render "reactions/destroy", type: "Comment", target: comment
|
|
||||||
- else
|
|
||||||
= render "reactions/create", type: "Comment", target: comment
|
|
||||||
.dropdown.d-inline
|
|
||||||
%button.btn.btn-link.answerbox__action{ data: { bs_toggle: :dropdown }, aria: { expanded: false } }
|
|
||||||
%i.fa.fa-fw.fa-ellipsis
|
|
||||||
= render "actions/comment", comment: comment, answer: a
|
|
||||||
|
|
Loading…
Reference in New Issue