diff --git a/app/components/app_catalog/web_app_icon_component.html.erb b/app/components/app_catalog/web_app_icon_component.html.erb new file mode 100644 index 0000000..3f9c5f3 --- /dev/null +++ b/app/components/app_catalog/web_app_icon_component.html.erb @@ -0,0 +1,5 @@ +<% if @image_url %> + <%= image_tag @image_url, class: "h-full w-full" %> +<% else %> + <%= render partial: "icons/remotestorage", locals: { custom_class: "h-full w-full p-0.5 text-gray-200" } %> +<% end %> diff --git a/app/components/app_catalog/web_app_icon_component.rb b/app/components/app_catalog/web_app_icon_component.rb new file mode 100644 index 0000000..8421d4f --- /dev/null +++ b/app/components/app_catalog/web_app_icon_component.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module AppCatalog + class WebAppIconComponent < ViewComponent::Base + def initialize(web_app:) + if web_app&.icon&.attached? + @image_url = image_url_for(web_app.icon) + elsif web_app&.apple_touch_icon&.attached? + @image_url = image_url_for(web_app.apple_touch_icon) + end + end + + def image_url_for(attachment) + if Setting.s3_enabled? + s3_image_url(attachment) + else + Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true) + end + end + end +end diff --git a/app/components/rs_auth_component.html.erb b/app/components/rs_auth_component.html.erb index 18ffcc8..535dc1b 100644 --- a/app/components/rs_auth_component.html.erb +++ b/app/components/rs_auth_component.html.erb @@ -1,16 +1,10 @@
- <% if @web_app.icon.attached? %> - <%= image_tag s3_image_url(@web_app.icon), class: "h-full w-full" %> - <% elsif @web_app.apple_touch_icon.attached? %> - <%= image_tag s3_image_url(@web_app.apple_touch_icon), class: "h-full w-full" %> - <% else %> - <%= render partial: "icons/remotestorage", locals: { custom_class: "h-full w-full p-0.5 text-gray-200" } %> - <% end %> + <%= render AppCatalog::WebAppIconComponent.new(web_app: @web_app) %>

- <%= @web_app.name %> + <%= @web_app&.name || @auth.app_name %>

<%= @auth.client_id %> diff --git a/app/views/icons/_remotestorage.html.erb b/app/views/icons/_remotestorage.html.erb index 2daafc4..4de0c04 100644 --- a/app/views/icons/_remotestorage.html.erb +++ b/app/views/icons/_remotestorage.html.erb @@ -1,5 +1,5 @@ - + diff --git a/spec/components/app_catalog/web_app_icon_component_spec.rb b/spec/components/app_catalog/web_app_icon_component_spec.rb new file mode 100644 index 0000000..f9ed3e5 --- /dev/null +++ b/spec/components/app_catalog/web_app_icon_component_spec.rb @@ -0,0 +1,11 @@ +require "rails_helper" + +RSpec.describe AppCatalog::WebAppIconComponent, type: :component do + describe "No web app given" do + it "renders the default icon" do + expect( + render_inline(described_class.new(web_app: nil)) {}.to_html + ).to include("icon-remotestorage") + end + end +end