diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 5cc8230e..1bff3be0 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -11,13 +11,22 @@ defmodule MusicLibraryWeb.ArtistLive.Show do @impl true def handle_params(%{"musicbrainz_id" => musicbrainz_id}, _, socket) do artist = Records.get_artist!(musicbrainz_id) - {:ok, artist_info} = Records.get_artist_info(musicbrainz_id) + + grouped_artist_records = + musicbrainz_id + |> Records.get_artist_records() + |> group_and_sort() {:noreply, socket |> assign(:nav_section, :artists) |> assign(:artist, artist) - |> assign(:artist_info, artist_info) + |> assign(:artist_records, grouped_artist_records) + |> assign_async(:artist_info, fn -> + with {:ok, artist_info} <- Records.get_artist_info(musicbrainz_id) do + {:ok, %{artist_info: artist_info}} + end + end) |> assign(:page_title, page_title(socket.assigns.live_action, artist))} end @@ -31,4 +40,13 @@ defmodule MusicLibraryWeb.ArtistLive.Show do " " ) end + + defp group_and_sort(records) do + {collection, wishlist} = Enum.split_with(records, fn r -> r.purchased_at end) + + %{ + collection: Enum.sort_by(collection, fn r -> r.release end, :desc), + wishlist: Enum.sort_by(wishlist, fn r -> r.release end, :desc) + } + end end diff --git a/lib/music_library_web/live/artist_live/show.html.heex b/lib/music_library_web/live/artist_live/show.html.heex index 70f94f4a..e191e716 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -1,8 +1,87 @@ -
- <%= (@artist_info.bio || gettext("Biography not available")) |> raw() %> +
+ <%= (artist_info.bio || gettext("Biography not available")) |> raw() %>
+ ++ <%= record.title %> +
++ <%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label( + record.type + ) %> +
++ <%= Records.Record.format_release(record.release) %> +
++ <%= record.title %> +
++ <%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label( + record.type + ) %> +
++ <%= Records.Record.format_release(record.release) %> +
+