From 7cd1e8e9448e2e3bb1e7f7488430fe6824037ff0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 2 Jan 2025 23:32:05 +0000 Subject: [PATCH] Extract grid component from artist view --- .../live/artist_live/record_components.ex | 60 ++++++++++ .../live/artist_live/show.ex | 1 + .../live/artist_live/show.html.heex | 104 +++--------------- priv/gettext/default.pot | 18 ++- 4 files changed, 83 insertions(+), 100 deletions(-) create mode 100644 lib/music_library_web/live/artist_live/record_components.ex diff --git a/lib/music_library_web/live/artist_live/record_components.ex b/lib/music_library_web/live/artist_live/record_components.ex new file mode 100644 index 00000000..34bd2161 --- /dev/null +++ b/lib/music_library_web/live/artist_live/record_components.ex @@ -0,0 +1,60 @@ +defmodule MusicLibraryWeb.ArtistLive.RecordComponents do + use MusicLibraryWeb, :live_component + + alias MusicLibrary.Records + + attr :records, :list, required: true + attr :title, :string, required: true + attr :id, :string, required: true + attr :record_path, :any, required: true + + def grid(assigns) do + ~H""" +
+

+ {@title} + + + {gettext("Number of records")} + + <.round_badge text={Enum.count(@records)} /> + +

+ <%!-- TODO: replace with OSS version --%> + +
+ """ + end +end diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 78ea2492..9e3f52be 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -1,5 +1,6 @@ defmodule MusicLibraryWeb.ArtistLive.Show do use MusicLibraryWeb, :live_view + import MusicLibraryWeb.ArtistLive.RecordComponents alias MusicLibrary.{Artists, Records} 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 214f2cc3..4c95fbd5 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -59,95 +59,19 @@ -
-

- {gettext("Collection")} - - - {gettext("Number of albums")} - - <.round_badge text={Enum.count(@artist_records.collection)} /> - -

- <%!-- TODO: replace with OSS version --%> - -
+ <.grid + :if={Enum.any?(@artist_records.collection)} + title={gettext("Collection")} + id="collection" + records={@artist_records.collection} + record_path={fn record -> ~p"/collection/#{record}" end} + /> -
-

- {gettext("Wishlist")} - - - {gettext("Number of albums")} - - <.round_badge text={Enum.count(@artist_records.wishlist)} /> - -

- <%!-- TODO: replace with OSS version --%> - -
+ <.grid + :if={Enum.any?(@artist_records.wishlist)} + title={gettext("Wishlist")} + id="wishlist" + records={@artist_records.wishlist} + record_path={fn record -> ~p"/wishlist/#{record}" end} + /> diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 9aa28f17..5184b058 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -306,7 +306,7 @@ msgid "Welcome to your Music Library" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:20 -#: lib/music_library_web/live/artist_live/show.html.heex:110 +#: lib/music_library_web/live/artist_live/show.html.heex:72 #: lib/music_library_web/live/wishlist_live/index.ex:83 #: lib/music_library_web/live/wishlist_live/show.ex:129 #, elixir-autogen, elixir-format @@ -407,7 +407,7 @@ msgstr "" msgid "No MB ID" msgstr "" -#: lib/music_library_web/live/artist_live/show.ex:39 +#: lib/music_library_web/live/artist_live/show.ex:40 #: lib/music_library_web/live/collection_live/show.ex:113 #, elixir-autogen, elixir-format msgid "Details" @@ -433,8 +433,7 @@ msgstr "" msgid "Dev dashboard" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:90 -#: lib/music_library_web/live/artist_live/show.html.heex:136 +#: lib/music_library_web/live/artist_live/record_components.ex:41 #, elixir-autogen, elixir-format msgid "View details" msgstr "" @@ -489,12 +488,6 @@ msgstr "" msgid "Refresh cover" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:67 -#: lib/music_library_web/live/artist_live/show.html.heex:113 -#, elixir-autogen, elixir-format -msgid "Number of albums" -msgstr "" - #: lib/music_library_web/live/stats_live/index.html.heex:3 #, elixir-autogen, elixir-format msgid "Records" @@ -519,3 +512,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Errors" msgstr "" + +#: lib/music_library_web/live/artist_live/record_components.ex:18 +#, elixir-autogen, elixir-format +msgid "Number of records" +msgstr ""