From 48c7d16c892fea6b7ec90e95856b0a2343d2d0de Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 10 Feb 2026 19:31:12 +0000 Subject: [PATCH] Consolidate a few components --- .../components/artist_components.ex | 29 -------- .../components/record_components.ex | 71 ++++++++++++------- .../components/search_components.ex | 4 +- .../components/stats_components.ex | 21 +++--- .../live/artist_live/form.ex | 2 +- .../live/artist_live/show.ex | 4 +- .../live/stats_live/top_artists.ex | 2 +- 7 files changed, 60 insertions(+), 73 deletions(-) delete mode 100644 lib/music_library_web/components/artist_components.ex diff --git a/lib/music_library_web/components/artist_components.ex b/lib/music_library_web/components/artist_components.ex deleted file mode 100644 index c438a654..00000000 --- a/lib/music_library_web/components/artist_components.ex +++ /dev/null @@ -1,29 +0,0 @@ -defmodule MusicLibraryWeb.ArtistComponents do - use MusicLibraryWeb, :html - - alias MusicLibrary.Assets.Transform - - attr :artist, :map, required: true - attr :image_hash, :string, required: true - attr :class, :string, required: false, default: nil - attr :width, :integer, default: nil - attr :rest, :global - - def artist_image(assigns) do - payload = - Transform.new(hash: assigns.image_hash, width: assigns.width) - |> Transform.encode!() - - assigns = assign(assigns, :payload, payload) - - ~H""" - {@artist.name} ~p"/images/cover-not-found.png" <> "';"} - {@rest} - /> - """ - end -end diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex index 24b04b21..29586fb7 100644 --- a/lib/music_library_web/components/record_components.ex +++ b/lib/music_library_web/components/record_components.ex @@ -6,6 +6,27 @@ defmodule MusicLibraryWeb.RecordComponents do alias MusicLibrary.Records alias Phoenix.LiveView.JS + attr :record, :map, required: true + attr :size, :atom, values: [:sm, :md], default: :sm + + def release_groups_badge(assigns) do + ~H""" + 0} + class={[ + "absolute right-0 bottom-0 rounded-br-lg rounded-tl-lg", + "font-medium", + "border border-zinc-600/20 dark:border-zinc-500/20", + @size == :sm && + "px-1 text-xs bg-zinc-200/80 dark:bg-zinc-500/70 text-zinc-700 dark:text-zinc-200", + @size == :md && "px-2 text-sm bg-zinc-50 dark:bg-zinc-500/10 text-zinc-700 dark:text-zinc-400" + ]} + > + {Records.Record.included_release_groups_count(@record)} + + """ + end + attr :record, :map, required: true attr :class, :string, required: false, default: "rounded-lg" attr :width, :integer, default: nil @@ -67,18 +88,7 @@ defmodule MusicLibraryWeb.RecordComponents do
<.record_cover record={record} width={160} /> - 0} - class={[ - "absolute right-0 bottom-0 rounded-br-lg rounded-tl-lg px-1", - "text-xs font-medium", - "bg-zinc-200/80 dark:bg-zinc-500/70", - "text-zinc-700 dark:text-zinc-200", - "border border-zinc-600/20 dark:border-zinc-500/20" - ]} - > - {Records.Record.included_release_groups_count(record)} - + <.release_groups_badge record={record} />

@@ -251,18 +261,7 @@ defmodule MusicLibraryWeb.RecordComponents do class="aspect-square object-cover rounded-lg group-hover:shadow-lg/20" width={460} /> - 0} - class={[ - "absolute right-0 bottom-0 rounded-br-lg rounded-tl-lg px-2", - "text-sm font-medium", - "bg-zinc-50 dark:bg-zinc-500/10", - "text-zinc-700 dark:text-zinc-400", - "border border-zinc-600/20 dark:border-zinc-500/20" - ]} - > - {Records.Record.included_release_groups_count(record)} - + <.release_groups_badge record={record} size={:md} />
<.dropdown id={"actions-#{record.id}"} placement="bottom-end"> <:toggle> @@ -529,4 +528,28 @@ defmodule MusicLibraryWeb.RecordComponents do """ end + + attr :artist, :map, required: true + attr :image_hash, :string, required: true + attr :class, :string, required: false, default: nil + attr :width, :integer, default: nil + attr :rest, :global + + def artist_image(assigns) do + payload = + Transform.new(hash: assigns.image_hash, width: assigns.width) + |> Transform.encode!() + + assigns = assign(assigns, :payload, payload) + + ~H""" + {@artist.name} ~p"/images/cover-not-found.png" <> "';"} + {@rest} + /> + """ + end end diff --git a/lib/music_library_web/components/search_components.ex b/lib/music_library_web/components/search_components.ex index 282dc7c9..1bc9e978 100644 --- a/lib/music_library_web/components/search_components.ex +++ b/lib/music_library_web/components/search_components.ex @@ -5,8 +5,8 @@ defmodule MusicLibraryWeb.SearchComponents do use MusicLibraryWeb, :html - import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1, record_cover: 1] - import MusicLibraryWeb.ArtistComponents, only: [artist_image: 1] + import MusicLibraryWeb.RecordComponents, + only: [format_label: 1, type_label: 1, record_cover: 1, artist_image: 1] alias MusicLibrary.Records.Record alias MusicLibraryWeb.Markdown diff --git a/lib/music_library_web/components/stats_components.ex b/lib/music_library_web/components/stats_components.ex index 4e8f5c65..9d9604af 100644 --- a/lib/music_library_web/components/stats_components.ex +++ b/lib/music_library_web/components/stats_components.ex @@ -2,7 +2,13 @@ defmodule MusicLibraryWeb.StatsComponents do use MusicLibraryWeb, :live_component import MusicLibraryWeb.RecordComponents, - only: [format_label: 1, type_label: 1, artist_links: 1, record_cover: 1] + only: [ + format_label: 1, + type_label: 1, + artist_links: 1, + record_cover: 1, + release_groups_badge: 1 + ] alias MusicLibrary.Records @@ -167,18 +173,7 @@ defmodule MusicLibraryWeb.StatsComponents do
<.record_cover record={record} width={96} /> - 0} - class={[ - "absolute right-0 bottom-0 rounded-br-lg rounded-tl-lg px-1", - "text-xs font-medium", - "bg-zinc-200/80 dark:bg-zinc-500/70", - "text-zinc-700 dark:text-zinc-200", - "border border-zinc-600/20 dark:border-zinc-500/20" - ]} - > - {Records.Record.included_release_groups_count(record)} - + <.release_groups_badge record={record} />

diff --git a/lib/music_library_web/live/artist_live/form.ex b/lib/music_library_web/live/artist_live/form.ex index 5862d2bc..dcb27164 100644 --- a/lib/music_library_web/live/artist_live/form.ex +++ b/lib/music_library_web/live/artist_live/form.ex @@ -1,7 +1,7 @@ defmodule MusicLibraryWeb.ArtistLive.Form do use MusicLibraryWeb, :live_component - import MusicLibraryWeb.ArtistComponents, only: [artist_image: 1] + import MusicLibraryWeb.RecordComponents, only: [artist_image: 1] alias MusicLibrary.Artists alias MusicLibrary.Assets diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 9f72932f..0eca1b14 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -2,9 +2,7 @@ defmodule MusicLibraryWeb.ArtistLive.Show do use MusicLibraryWeb, :live_view import MusicLibraryWeb.RecordComponents, - only: [record_grid: 1, country_label: 1] - - import MusicLibraryWeb.ArtistComponents, only: [artist_image: 1] + only: [record_grid: 1, country_label: 1, artist_image: 1] alias MusicLibrary.{Artists, Records} alias MusicLibrary.Artists.ArtistInfo diff --git a/lib/music_library_web/live/stats_live/top_artists.ex b/lib/music_library_web/live/stats_live/top_artists.ex index a309356a..1df92687 100644 --- a/lib/music_library_web/live/stats_live/top_artists.ex +++ b/lib/music_library_web/live/stats_live/top_artists.ex @@ -1,7 +1,7 @@ defmodule MusicLibraryWeb.StatsLive.TopArtists do use MusicLibraryWeb, :live_component - import MusicLibraryWeb.ArtistComponents, only: [artist_image: 1] + import MusicLibraryWeb.RecordComponents, only: [artist_image: 1] alias MusicLibrary.ScrobbleActivity