Skip to content

Commit

Permalink
Use instance variables for reports and reportable name
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp-work committed Sep 21, 2023
1 parent b6caa48 commit ebff696
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/api/app/components/reports_notice_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.text-warning
%i.fas.fa-flag
- if by_user?
You reported this #{reportable.class.name.downcase}.
You reported this #{reportable_name}.
- else
This #{reportable.class.name.downcase} has #{pluralize(reports.count, 'report')}.
This #{reportable_name} has #{report_amount}.
8 changes: 5 additions & 3 deletions src/api/app/components/reports_notice_component.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
class ReportsNoticeComponent < ApplicationComponent
attr_reader :reportable, :user
attr_reader :reportable, :reportable_name, :user, :reports

def initialize(reportable:, user:)
super

@reportable = reportable
@reportable_name = reportable.class.name.downcase
@user = user
@reports = reportable&.reports
end

def by_user?
Report.exists?(user:, reportable:)

Check warning on line 14 in src/api/app/components/reports_notice_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/reports_notice_component.rb#L14

Added line #L14 was not covered by tests
end

def reports
reportable&.reports
def report_amount
pluralize(reports.count, 'report')

Check warning on line 18 in src/api/app/components/reports_notice_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/reports_notice_component.rb#L18

Added line #L18 was not covered by tests
end

def render?
Expand Down

0 comments on commit ebff696

Please sign in to comment.