From 354c0d8dfbfdebf74187c8e53d420cd231f2c0f0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 13 May 2025 09:48:28 +0100 Subject: [PATCH] Use Fluxon badges --- .../components/barcode_scanner_component.ex | 12 +++- .../components/core_components.ex | 72 +------------------ .../live/artist_live/show.html.heex | 3 +- .../live/stats_live/index.html.heex | 28 ++++---- 4 files changed, 26 insertions(+), 89 deletions(-) diff --git a/lib/music_library_web/components/barcode_scanner_component.ex b/lib/music_library_web/components/barcode_scanner_component.ex index 77339682..9c22bd2a 100644 --- a/lib/music_library_web/components/barcode_scanner_component.ex +++ b/lib/music_library_web/components/barcode_scanner_component.ex @@ -286,12 +286,18 @@ defmodule MusicLibraryWeb.BarcodeScannerComponent do )}

- <.badge :if={@status == :new} color={:gray} text={gettext("New")} /> + <.badge :if={@status == :new}> + {gettext("New")} + <.link :if={@status == :wishlisted} navigate={~p"/wishlist/#{@record_id}"}> - <.badge color={:yellow} text={gettext("Wishlisted")} /> + <.badge color="yellow"> + {gettext("Wishlisted")} + <.link :if={@status == :collected} navigate={~p"/collection/#{@record_id}"}> - <.badge color={:green} text={gettext("Collected")} /> + <.badge color="green"> + {gettext("Collected")} + """ diff --git a/lib/music_library_web/components/core_components.ex b/lib/music_library_web/components/core_components.ex index bc8a381a..96820a2d 100644 --- a/lib/music_library_web/components/core_components.ex +++ b/lib/music_library_web/components/core_components.ex @@ -19,6 +19,7 @@ defmodule MusicLibraryWeb.CoreComponents do alias Phoenix.LiveView.JS use Gettext, backend: MusicLibraryWeb.Gettext + defdelegate badge(assigns), to: Fluxon.Components.Badge defdelegate button(assigns), to: Fluxon.Components.Button defdelegate date_time_picker(assigns), to: Fluxon.Components.DatePicker defdelegate input(assigns), to: Fluxon.Components.Input @@ -272,77 +273,6 @@ defmodule MusicLibraryWeb.CoreComponents do """ end - @doc """ - Renders a round badge. - """ - attr :text, :string, required: true - attr :class, :string, default: nil - - def round_badge(assigns) do - ~H""" - - {assigns.text} - - """ - end - - attr :color, :atom, values: [:green, :yellow, :gray], required: true - attr :text, :string, required: true - - def badge(assigns) do - case assigns.color do - :green -> - ~H""" - - {@text} - - """ - - :yellow -> - ~H""" - - {@text} - - """ - - :gray -> - ~H""" - - {@text} - - """ - end - end - ## JS Commands def show(js \\ %JS{}, selector) do 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 b6c0b3ca..80525cc1 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -24,10 +24,11 @@ - <.round_badge text={gettext("On Tour")} class="mr-2" /> + <.badge variant="pill" class="mr-2">{gettext("On Tour")} 0} 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 51e44ee9..9036ebad 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -201,18 +201,18 @@
- <.badge - :if={album.metadata.musicbrainz_id == ""} - color={:gray} - text={gettext("No MB ID")} - /> + <.badge :if={album.metadata.musicbrainz_id == ""}> + {gettext("No MB ID")} + <.link :if={ record_id = tracked_record?(@collected_releases, album.metadata.musicbrainz_id) } navigate={~p"/collection/#{record_id}"} > - <.badge color={:green} text={gettext("Collected")} /> + <.badge color="green"> + {gettext("Collected")} + <.link :if={ @@ -220,7 +220,9 @@ } navigate={~p"/wishlist/#{record_id}"} > - <.badge color={:yellow} text={gettext("Wishlisted")} /> + <.badge color="yellow"> + {gettext("Wishlisted")} +
@@ -332,22 +334,20 @@
- <.badge - :if={track.album.musicbrainz_id == ""} - color={:gray} - text={gettext("No MB ID")} - /> + <.badge :if={track.album.musicbrainz_id == ""}> + {gettext("No MB ID")} + <.link :if={record_id = tracked_record?(@collected_releases, track.album.musicbrainz_id)} navigate={~p"/collection/#{record_id}"} > - <.badge color={:green} text={gettext("Collected")} /> + <.badge color="green">{gettext("Collected")} <.link :if={record_id = tracked_record?(@wishlisted_releases, track.album.musicbrainz_id)} navigate={~p"/wishlist/#{record_id}"} > - <.badge color={:yellow} text={gettext("Wishlisted")} /> + <.badge color="yellow">{gettext("Wishlisted")}