mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 08:29:53 +01:00
Refactor comments into CommentComponent
This commit is contained in:
parent
d6b5e2bae7
commit
597c859c2d
3 changed files with 35 additions and 22 deletions
22
app/components/comment_component.html.haml
Normal file
22
app/components/comment_component.html.haml
Normal file
|
@ -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
|
12
app/components/comment_component.rb
Normal file
12
app/components/comment_component.rb
Normal file
|
@ -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
|
||||
%ul.comment__container
|
||||
- comments.order(:created_at).each do |comment|
|
||||
%li.comment{ data: { comment_id: comment.id } }
|
||||
.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
|
||||
= render CommentComponent.new(comment:, answer: a)
|
||||
|
|
Loading…
Reference in a new issue