From 4ce71cf4e2e2be0cd87199cab889131e75464dda Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 30 Oct 2024 08:49:40 +0000 Subject: [PATCH] Extract stats album preview component --- .../live/stats_live/data_components.ex | 41 +++++++++++++++++++ .../live/stats_live/index.html.heex | 34 +++------------ priv/gettext/default.pot | 10 ++--- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/lib/music_library_web/live/stats_live/data_components.ex b/lib/music_library_web/live/stats_live/data_components.ex index cac29d98..b8692722 100644 --- a/lib/music_library_web/live/stats_live/data_components.ex +++ b/lib/music_library_web/live/stats_live/data_components.ex @@ -1,6 +1,47 @@ defmodule MusicLibraryWeb.StatsLive.DataComponents do use MusicLibraryWeb, :live_component + attr :record, MusicLibrary.Records.Record, required: true + attr :title, :string, required: true + attr :class, :string, default: "" + + def album_preview(assigns) do + ~H""" +
+
+ {@record.title} +

+ <%= @title %> +

+
+
+

+ <.link + :for={artist <- @record.artists} + class="text-sm md:text-base lg:text-2xl text-gray-900 hover:text-gray-500 dark:text-gray-300 dark:hover:text-gray-200" + patch={~p"/records?query=mbid:#{artist.musicbrainz_id}"} + > + <%= artist.name %> + + + <%= @record.title %> + +

+
+
+ """ + end + attr :data, :list, required: true, doc: """ diff --git a/lib/music_library_web/live/stats_live/index.html.heex b/lib/music_library_web/live/stats_live/index.html.heex index dc042ee8..5abb7225 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -3,35 +3,11 @@ <%= gettext("Basics") %>
-
-
- {@latest_record.title} -

- <%= gettext("Latest purchase") %> -

-
-
-

- <.link - :for={artist <- @latest_record.artists} - class="text-sm md:text-base lg:text-2xl text-gray-900 hover:text-gray-500 dark:text-gray-300 dark:hover:text-gray-200" - patch={~p"/records?query=mbid:#{artist.musicbrainz_id}"} - > - <%= artist.name %> - - - <%= @latest_record.title %> - -

-
-
+ <.album_preview + record={@latest_record} + title={gettext("Latest purchase")} + class="col-span-2 sm:col-span-3" + /> <.counter title={gettext("Total collection")} count={@collection_count} path={~p"/records"} /> <.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} />
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 2b85fbce..1b386b5f 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -97,7 +97,7 @@ msgstr "" msgid "Format" msgstr "" -#: lib/music_library_web/live/stats_live/index.html.heex:42 +#: lib/music_library_web/live/stats_live/index.html.heex:18 #, elixir-autogen, elixir-format msgid "Formats" msgstr "" @@ -136,7 +136,7 @@ msgstr "" msgid "Invalid password" msgstr "" -#: lib/music_library_web/live/stats_live/index.html.heex:17 +#: lib/music_library_web/live/stats_live/index.html.heex:8 #, elixir-autogen, elixir-format msgid "Latest purchase" msgstr "" @@ -287,12 +287,12 @@ msgstr "" msgid "The application has been updated, please reload." msgstr "" -#: lib/music_library_web/live/stats_live/index.html.heex:35 +#: lib/music_library_web/live/stats_live/index.html.heex:11 #, elixir-autogen, elixir-format msgid "Total collection" msgstr "" -#: lib/music_library_web/live/stats_live/index.html.heex:36 +#: lib/music_library_web/live/stats_live/index.html.heex:12 #, elixir-autogen, elixir-format msgid "Total wishlist" msgstr "" @@ -302,7 +302,7 @@ msgstr "" msgid "Type" msgstr "" -#: lib/music_library_web/live/stats_live/index.html.heex:46 +#: lib/music_library_web/live/stats_live/index.html.heex:22 #, elixir-autogen, elixir-format msgid "Types" msgstr ""