Skip to content

Commit

Permalink
Refactor comments into CommentComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeldesu committed Mar 10, 2024
1 parent d6b5e2b commit 597c859
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
22 changes: 22 additions & 0 deletions app/components/comment_component.html.haml
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions app/components/comment_component.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 1 addition & 22 deletions app/views/answerbox/_comments.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 597c859

Please sign in to comment.