From b42b4744a0355046c687e81b3f112ebdb9081755 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 2 Dec 2024 21:37:04 +0000 Subject: [PATCH] Display records in artist page --- .../live/artist_live/show.ex | 22 ++++- .../live/artist_live/show.html.heex | 87 ++++++++++++++++++- priv/gettext/default.pot | 14 +++ 3 files changed, 117 insertions(+), 6 deletions(-) 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.name %>

-

- <%= (@artist_info.bio || gettext("Biography not available")) |> raw() %> +

+ <%= (artist_info.bio || gettext("Biography not available")) |> raw() %>

+ +
+

+ <%= gettext("Collection") %> +

+
    +
  • +
    + {record.title} + +
    +

    + <%= record.title %> +

    +

    + <%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label( + record.type + ) %> +

    +

    + <%= Records.Record.format_release(record.release) %> +

    +
  • +
+
+ +
+

+ <%= gettext("Wishlist") %> +

+
    +
  • +
    + {record.title} + +
    +

    + <%= record.title %> +

    +

    + <%= Records.Record.format_long_label(record.format) %> · <%= Records.Record.type_long_label( + record.type + ) %> +

    +

    + <%= Records.Record.format_release(record.release) %> +

    +
  • +
+
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 59448d6e..bbadf763 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -51,6 +51,7 @@ msgid "Choose a value" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:13 +#: lib/music_library_web/live/artist_live/show.html.heex:14 #: lib/music_library_web/live/collection_live/index.ex:77 #: lib/music_library_web/live/collection_live/show.ex:102 #: lib/music_library_web/live/collection_live/show.ex:119 @@ -327,6 +328,7 @@ msgid "Welcome to your Music Library" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:19 +#: lib/music_library_web/live/artist_live/show.html.heex:52 #: lib/music_library_web/live/wishlist_live/index.ex:75 #: lib/music_library_web/live/wishlist_live/show.ex:102 #, elixir-autogen, elixir-format @@ -449,6 +451,7 @@ msgstr "" msgid "No MB ID" msgstr "" +#: lib/music_library_web/live/artist_live/show.ex:38 #: lib/music_library_web/live/collection_live/show.ex:100 #, elixir-autogen, elixir-format msgid "Details" @@ -473,3 +476,14 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Dev dashboard" msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:9 +#, elixir-autogen, elixir-format +msgid "Biography not available" +msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:32 +#: lib/music_library_web/live/artist_live/show.html.heex:70 +#, elixir-autogen, elixir-format +msgid "View details" +msgstr ""