diff --git a/app/views/admin/applications/_form.html.erb b/app/views/admin/applications/_form.html.erb index 51b5733..90ccc75 100644 --- a/app/views/admin/applications/_form.html.erb +++ b/app/views/admin/applications/_form.html.erb @@ -36,9 +36,9 @@ <%= form.text_area :description, rows: 3, class: "mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-100 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "Optional description of this application" %> -
-
- <%= form.label :icon, "Application Icon", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> +
+ - <% if application.icon.attached? && application.persisted? %> - <% begin %> - <%# Only show icon if we can successfully get its URL (blob is persisted) %> - <% if application.icon.blob&.persisted? && application.icon.blob.key.present? %> -
- <%= image_tag application.icon, class: "h-16 w-16 rounded-lg object-cover border border-gray-200 dark:border-gray-700", alt: "Current icon" %> -
-

Current icon

-

<%= number_to_human_size(application.icon.blob.byte_size) %>

-
-
- <% end %> - <% rescue ArgumentError => e %> - <%# Handle case where icon attachment exists but can't generate signed_id %> - <% if e.message.include?("Cannot get a signed_id for a new record") %> -
-

Icon uploaded

-

File will be processed shortly

-
- <% else %> - <%# Re-raise if it's a different error %> - <% raise e %> - <% end %> - <% end %> - <% end %> -
-
-
- - - -
- -

or drag and drop

-
-

PNG, JPG, GIF, or SVG up to 2MB

-

💡 Tip: Click here and press Ctrl+V (or Cmd+V) to paste an image from your clipboard

-
-
- -
+ <%= render "icon_uploader", + form: form, + field: :icon, + label: "Icon", + current_attached: (application.persisted? ? application.icon : nil), + current_label: "Current icon" %> -
- <%= form.label :icon_dark, "Dark mode icon (optional)", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> -

Used in place of the main icon when the user's theme is dark. If omitted, the main icon is used in both modes.

- <% if application.icon_dark.attached? && application.persisted? && application.icon_dark.blob&.persisted? && application.icon_dark.blob.key.present? %> -
- <%= image_tag application.icon_dark, class: "h-16 w-16 rounded-lg object-cover border border-gray-200 dark:border-gray-700 bg-gray-900", alt: "Current dark-mode icon" %> -
-

Current dark-mode icon

-

<%= number_to_human_size(application.icon_dark.blob.byte_size) %>

-
-
- <% end %> - <%= form.file_field :icon_dark, - accept: "image/png,image/jpg,image/jpeg,image/gif,image/svg+xml", - class: "mt-2 block w-full text-sm text-gray-700 dark:text-gray-300 file:mr-3 file:py-2 file:px-3 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-blue-50 file:text-blue-700 dark:file:bg-blue-900/30 dark:file:text-blue-300 hover:file:bg-blue-100 dark:hover:file:bg-blue-900/50" %> -
+ <%= render "icon_uploader", + form: form, + field: :icon_dark, + label: "Dark mode icon (optional)", + help: "Used in place of the main icon when the user's theme is dark. If omitted, the main icon is used in both modes.", + current_attached: (application.persisted? ? application.icon_dark : nil), + current_label: "Current dark-mode icon", + preview_extra_class: "bg-gray-900" %>
diff --git a/app/views/admin/applications/_icon_uploader.html.erb b/app/views/admin/applications/_icon_uploader.html.erb new file mode 100644 index 0000000..b7ae980 --- /dev/null +++ b/app/views/admin/applications/_icon_uploader.html.erb @@ -0,0 +1,66 @@ +<%# Compact icon uploader. Locals: + form - the form builder + field - symbol for the file field (:icon or :icon_dark) + label - heading text + help - small helper paragraph (optional) + current_attached - the attachment to show as "current" preview + current_label - text for the preview row (e.g. "Current icon") + preview_extra_class - extra css for the preview img (e.g. "bg-gray-900") +%> +
+ <%= form.label field, label, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %> + <% if local_assigns[:help].present? %> +

<%= help %>

+ <% end %> + + <% if current_attached&.attached? && current_attached.blob&.persisted? && current_attached.blob.key.present? %> +
+ <%= image_tag current_attached, class: "h-12 w-12 rounded-md object-cover border border-gray-200 dark:border-gray-700 #{local_assigns[:preview_extra_class]}", alt: current_label %> +
+

<%= current_label %>

+

<%= number_to_human_size(current_attached.blob.byte_size) %>

+
+
+ <% end %> + +
+
+ + + +
+ + · drag and drop · or click and paste (⌘V) +

PNG, JPG, GIF or SVG · max 2MB

+
+
+ +
+
diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 4d2b8fe..7bbcbfa 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Clinch - VERSION = "0.14.0" + VERSION = "0.14.1" end