From 17c9098aba648031636b817399484da4f50172ac Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 20 Apr 2025 14:29:53 +0100 Subject: [PATCH] Consolidate usage of 'artist names' string --- lib/music_library/records/record.ex | 4 ++++ lib/music_library_web/components/form_component.ex | 4 ++-- lib/music_library_web/live/collection_live/show.ex | 8 ++------ lib/music_library_web/live/wishlist_live/show.ex | 4 +--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/music_library/records/record.ex b/lib/music_library/records/record.ex index 10606639..3b5f4619 100644 --- a/lib/music_library/records/record.ex +++ b/lib/music_library/records/record.ex @@ -30,6 +30,10 @@ defmodule MusicLibrary.Records.Record do timestamps(type: :utc_datetime) end + def artist_names(record) do + Enum.map_join(record.artists, ", ", fn artist -> artist.name end) + end + def formats, do: @formats def types, do: @types diff --git a/lib/music_library_web/components/form_component.ex b/lib/music_library_web/components/form_component.ex index 1ea361c2..f6029caa 100644 --- a/lib/music_library_web/components/form_component.ex +++ b/lib/music_library_web/components/form_component.ex @@ -3,7 +3,7 @@ defmodule MusicLibraryWeb.FormComponent do import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1] alias MusicLibrary.Records - alias MusicLibrary.Records.Cover + alias MusicLibrary.Records.{Cover, Record} @impl true def mount(socket) do @@ -18,7 +18,7 @@ defmodule MusicLibraryWeb.FormComponent do

- {Enum.map(@record.artists, & &1.name) |> Enum.join(", ")} + {Record.artist_names(@record)}

{@record.title} diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex index 80124444..6e6d42f1 100644 --- a/lib/music_library_web/live/collection_live/show.ex +++ b/lib/music_library_web/live/collection_live/show.ex @@ -116,11 +116,9 @@ defmodule MusicLibraryWeb.CollectionLive.Show do end def page_title(:show, record) do - artist_names = Enum.map(record.artists, & &1.name) - Enum.join( [ - Enum.join(artist_names, ", "), + Records.Record.artist_names(record), "-", record.title, "·", @@ -133,11 +131,9 @@ defmodule MusicLibraryWeb.CollectionLive.Show do end def page_title(action, record) do - artist_names = Enum.map(record.artists, & &1.name) - Enum.join( [ - Enum.join(artist_names, ", "), + Records.Record.artist_names(record), "-", record.title, "·", diff --git a/lib/music_library_web/live/wishlist_live/show.ex b/lib/music_library_web/live/wishlist_live/show.ex index d6fb0204..4cd84643 100644 --- a/lib/music_library_web/live/wishlist_live/show.ex +++ b/lib/music_library_web/live/wishlist_live/show.ex @@ -124,11 +124,9 @@ defmodule MusicLibraryWeb.WishlistLive.Show do end def page_title(action, record) do - artist_names = Enum.map(record.artists, & &1.name) - Enum.join( [ - Enum.join(artist_names, ", "), + Records.Record.artist_names(record), "-", record.title, "·",