Move app/labor/reaction_image.rb to helper (#11678)
This commit is contained in:
parent
5185de4c91
commit
2939813168
6 changed files with 24 additions and 29 deletions
15
app/helpers/notifications_helper.rb
Normal file
15
app/helpers/notifications_helper.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module NotificationsHelper
|
||||
REACTION_IMAGES = {
|
||||
"like" => "heart-filled.svg",
|
||||
"unicorn" => "unicorn-filled.svg",
|
||||
"hands" => "emoji/emoji-one-hands.png",
|
||||
"thinking" => "emoji/emoji-one-thinking.png",
|
||||
"readinglist" => "save-filled.svg",
|
||||
"thumbsdown" => "emoji/emoji-one-thumbs-down.png",
|
||||
"vomit" => "emoji/emoji-one-nausea-face.png"
|
||||
}.freeze
|
||||
|
||||
def reaction_image(category)
|
||||
REACTION_IMAGES[category]
|
||||
end
|
||||
end
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
class ReactionImage
|
||||
attr_accessor :category
|
||||
|
||||
def initialize(category)
|
||||
@category = category
|
||||
end
|
||||
|
||||
def path
|
||||
images = {
|
||||
"like" => "heart-filled.svg",
|
||||
"unicorn" => "unicorn-filled.svg",
|
||||
"hands" => "emoji/emoji-one-hands.png",
|
||||
"thinking" => "emoji/emoji-one-thinking.png",
|
||||
"readinglist" => "save-filled.svg",
|
||||
"thumbsdown" => "emoji/emoji-one-thumbs-down.png",
|
||||
"vomit" => "emoji/emoji-one-nausea-face.png"
|
||||
}.freeze
|
||||
images[category]
|
||||
end
|
||||
end
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
<% reaction_categories = siblings.map { |n| n["category"] } %>
|
||||
<% reaction_categories.each do |cat| %>
|
||||
<% image_path = ReactionImage.new(cat).path %>
|
||||
<% image_path = reaction_image(cat) %>
|
||||
<% if image_path.present? %>
|
||||
<%= inline_svg_tag(image_path, aria: true, class: "crayons-icon reaction-image mx-1 my-1 reaction-icon--#{cat}", title: cat.to_s.humanize) %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
with
|
||||
<span>
|
||||
<% category = notification.json_data["reaction"]["category"] %>
|
||||
<%= inline_svg_tag(ReactionImage.new(category).path, class: "crayons-icon reaction-image mx-1 reaction-icon--#{category}", title: category.to_s.humanize) %>
|
||||
<%= inline_svg_tag(reaction_image(category), class: "crayons-icon reaction-image mx-1 reaction-icon--#{category}", title: category.to_s.humanize) %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
7
spec/helpers/notifications_helper_spec.rb
Normal file
7
spec/helpers/notifications_helper_spec.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe NotificationsHelper, type: :helper do
|
||||
it "returns a category image" do
|
||||
expect(helper.reaction_image("unicorn")).to eq("unicorn-filled.svg")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe ReactionImage, type: :labor do
|
||||
it "returns a category image" do
|
||||
expect(described_class.new("unicorn").path).to eq("unicorn-filled.svg")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue