Extract component to render an initialjs avatar

This way it'll be easier to change it.
This commit is contained in:
Javi Martín
2023-09-26 23:37:42 +02:00
parent 959176b66d
commit 517f74a748
7 changed files with 29 additions and 5 deletions

View File

@@ -0,0 +1 @@
<%= avatar_image(record, options) %>

View File

@@ -0,0 +1,23 @@
class Shared::AvatarComponent < ApplicationComponent
attr_reader :record, :given_options
delegate :avatar_image, to: :helpers
def initialize(record, **given_options)
@record = record
@given_options = given_options
end
private
def default_options
{ seed: seed }
end
def options
default_options.merge(given_options)
end
def seed
record.id
end
end

View File

@@ -6,7 +6,7 @@
<%= link_to t("account.show.erase_account_link"), users_registrations_delete_form_path, class: "delete" %> <%= link_to t("account.show.erase_account_link"), users_registrations_delete_form_path, class: "delete" %>
</div> </div>
<%= avatar_image(@account, seed: @account.id, size: 100, class: "margin-bottom") %> <%= render Shared::AvatarComponent.new(@account, size: 100, class: "margin-bottom") %>
<h1 class="inline-block"><%= t("account.show.title") %></h1> <h1 class="inline-block"><%= t("account.show.title") %></h1>

View File

@@ -19,7 +19,7 @@
<% elsif comment.user.organization? %> <% elsif comment.user.organization? %>
<%= image_tag("avatar_collective.png", size: 32, class: "avatar float-left") %> <%= image_tag("avatar_collective.png", size: 32, class: "avatar float-left") %>
<% else %> <% else %>
<%= avatar_image(comment.user, seed: comment.user_id, size: 32, class: "float-left") %> <%= render Shared::AvatarComponent.new(comment.user, size: 32, class: "float-left") %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -1,7 +1,7 @@
<div class="comment-body"> <div class="comment-body">
<div class="comment-info"> <div class="comment-info">
<%= avatar_image(participant, seed: participant.id, size: 32, class: "author-photo") %> <%= render Shared::AvatarComponent.new(participant, size: 32, class: "author-photo") %>
<div class="comment-info"> <div class="comment-info">

View File

@@ -4,7 +4,7 @@
<%= t("shared.author_info.author_deleted") %> <%= t("shared.author_info.author_deleted") %>
</span> </span>
<% else %> <% else %>
<%= avatar_image(resource.author, seed: resource.author_id, size: 32, class: "author-photo") %> <%= render Shared::AvatarComponent.new(resource.author, size: 32, class: "author-photo") %>
<span class="author"> <span class="author">
<%= link_to resource.author.name, user_path(resource.author) %> <%= link_to resource.author.name, user_path(resource.author) %>
</span> </span>

View File

@@ -15,7 +15,7 @@
<% end %> <% end %>
<h2 class="inline-block"> <h2 class="inline-block">
<%= avatar_image(@user, seed: @user.id, size: 60) %> <%= render Shared::AvatarComponent.new(@user, size: 60) %>
<%= @user.name %> <%= @user.name %>
<% if current_user&.administrator? %> <% if current_user&.administrator? %>
<small><%= @user.email %></small> <small><%= @user.email %></small>