From ddbda5b4d2b5c8ee5d1ee52f0abe1c983fc164c0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 7 Oct 2024 14:57:30 +0100 Subject: [PATCH] Normalize display of artist names --- lib/music_library_web/artist_helpers.ex | 7 +++++++ lib/music_library_web/controllers/stats_html.ex | 2 ++ .../controllers/stats_html/index.html.heex | 2 +- lib/music_library_web/live/record_live/index.ex | 1 + lib/music_library_web/live/record_live/index.html.heex | 2 +- lib/music_library_web/live/record_live/show.ex | 1 + lib/music_library_web/live/record_live/show.html.heex | 2 +- 7 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 lib/music_library_web/artist_helpers.ex diff --git a/lib/music_library_web/artist_helpers.ex b/lib/music_library_web/artist_helpers.ex new file mode 100644 index 00000000..42e80603 --- /dev/null +++ b/lib/music_library_web/artist_helpers.ex @@ -0,0 +1,7 @@ +defmodule MusicLibraryWeb.ArtistHelpers do + def format_artist_names(artists) do + artists + |> Enum.map(fn a -> a.name end) + |> Enum.join(", ") + end +end diff --git a/lib/music_library_web/controllers/stats_html.ex b/lib/music_library_web/controllers/stats_html.ex index 1fa94e1d..1fcae19f 100644 --- a/lib/music_library_web/controllers/stats_html.ex +++ b/lib/music_library_web/controllers/stats_html.ex @@ -1,6 +1,8 @@ defmodule MusicLibraryWeb.StatsHTML do use MusicLibraryWeb, :html + import MusicLibraryWeb.ArtistHelpers + alias MusicLibrary.Records.Record embed_templates "stats_html/*" diff --git a/lib/music_library_web/controllers/stats_html/index.html.heex b/lib/music_library_web/controllers/stats_html/index.html.heex index 483149b8..64cf4457 100644 --- a/lib/music_library_web/controllers/stats_html/index.html.heex +++ b/lib/music_library_web/controllers/stats_html/index.html.heex @@ -48,7 +48,7 @@

- <%= Enum.map(@latest_record.artists, fn a -> a.name end) %> + <%= format_artist_names(@latest_record.artists) %> <%= @latest_record.title %>

diff --git a/lib/music_library_web/live/record_live/index.ex b/lib/music_library_web/live/record_live/index.ex index 8ad73db4..d948cdbc 100644 --- a/lib/music_library_web/live/record_live/index.ex +++ b/lib/music_library_web/live/record_live/index.ex @@ -1,6 +1,7 @@ defmodule MusicLibraryWeb.RecordLive.Index do use MusicLibraryWeb, :live_view import MusicLibraryWeb.Pagination + import MusicLibraryWeb.ArtistHelpers alias MusicLibrary.Records diff --git a/lib/music_library_web/live/record_live/index.html.heex b/lib/music_library_web/live/record_live/index.html.heex index 0690f352..0ffefe24 100644 --- a/lib/music_library_web/live/record_live/index.html.heex +++ b/lib/music_library_web/live/record_live/index.html.heex @@ -36,7 +36,7 @@ <:col :let={{_id, record}}> -

<%= Enum.map(record.artists, fn a -> a.name end) %>

+

<%= format_artist_names(record.artists) %>

<%= record.title %>

<%= record.release %>

diff --git a/lib/music_library_web/live/record_live/show.ex b/lib/music_library_web/live/record_live/show.ex index e4cab821..1d010d19 100644 --- a/lib/music_library_web/live/record_live/show.ex +++ b/lib/music_library_web/live/record_live/show.ex @@ -1,5 +1,6 @@ defmodule MusicLibraryWeb.RecordLive.Show do use MusicLibraryWeb, :live_view + import MusicLibraryWeb.ArtistHelpers alias MusicLibrary.Records diff --git a/lib/music_library_web/live/record_live/show.html.heex b/lib/music_library_web/live/record_live/show.html.heex index f91ad292..99abc64c 100644 --- a/lib/music_library_web/live/record_live/show.html.heex +++ b/lib/music_library_web/live/record_live/show.html.heex @@ -1,6 +1,6 @@ <.header> <%= @record.title %> - <:subtitle><%= Enum.map(@record.artists, fn a -> a.name end) %> + <:subtitle><%= format_artist_names(@record.artists) %> <:actions> <.link patch={~p"/records/#{@record}/show/edit"} phx-click={JS.push_focus()}> <.button>Edit Metadata