From 40346d91234b4d318d3b4265075803e2b0feb037 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 4 Jul 2025 14:53:27 +0100 Subject: [PATCH] Render scrobble rule type with badge --- .../live/scrobble_rules_live/index.ex | 13 +++++++------ .../live/scrobble_rules_live/index.html.heex | 4 +++- priv/gettext/default.pot | 2 ++ priv/gettext/en/LC_MESSAGES/default.po | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/music_library_web/live/scrobble_rules_live/index.ex b/lib/music_library_web/live/scrobble_rules_live/index.ex index 2777a517..e2a17ce0 100644 --- a/lib/music_library_web/live/scrobble_rules_live/index.ex +++ b/lib/music_library_web/live/scrobble_rules_live/index.ex @@ -103,12 +103,13 @@ defmodule MusicLibraryWeb.ScrobbleRulesLive.Index do {:noreply, put_flash(socket, :info, message)} end - defp rule_type_badge(type) do - case type do - "album" -> "Album" - "artist" -> "Artist" - _ -> type - end + attr :type, :atom, required: true, values: [:album, :artist] + + defp type_badge(assigns) do + ~H""" + <.badge :if={@type == :album} color="green">{gettext("Album")} + <.badge :if={@type == :artist} color="blue">{gettext("Artist")} + """ end defp enabled_badge(enabled) do diff --git a/lib/music_library_web/live/scrobble_rules_live/index.html.heex b/lib/music_library_web/live/scrobble_rules_live/index.html.heex index 2c58c732..4c794772 100644 --- a/lib/music_library_web/live/scrobble_rules_live/index.html.heex +++ b/lib/music_library_web/live/scrobble_rules_live/index.html.heex @@ -36,7 +36,9 @@ <.table_body phx-update="stream" id="scrobble-rules"> <.table_row :for={{dom_id, scrobble_rule} <- @streams.scrobble_rules} id={dom_id}> - <:cell>{rule_type_badge(scrobble_rule.type)} + <:cell> + <.type_badge type={scrobble_rule.type} /> + <:cell>{scrobble_rule.match_value} <:cell class="whitespace-nowrap font-mono">{scrobble_rule.target_musicbrainz_id} <:cell>{enabled_badge(scrobble_rule.enabled)} diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index c3c3caae..f5b01cc5 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -434,6 +434,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/scrobble_rules_live/form_component.ex +#: lib/music_library_web/live/scrobble_rules_live/index.ex #, elixir-autogen, elixir-format msgid "Album" msgstr "" @@ -978,6 +979,7 @@ msgid "Apply All Rules" msgstr "" #: lib/music_library_web/live/scrobble_rules_live/form_component.ex +#: lib/music_library_web/live/scrobble_rules_live/index.ex #, elixir-autogen, elixir-format msgid "Artist" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index c88f02ba..6afad218 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -434,6 +434,7 @@ msgstr "" #: lib/music_library_web/components/record_components.ex #: lib/music_library_web/live/scrobble_rules_live/form_component.ex +#: lib/music_library_web/live/scrobble_rules_live/index.ex #, elixir-autogen, elixir-format msgid "Album" msgstr "" @@ -978,6 +979,7 @@ msgid "Apply All Rules" msgstr "" #: lib/music_library_web/live/scrobble_rules_live/form_component.ex +#: lib/music_library_web/live/scrobble_rules_live/index.ex #, elixir-autogen, elixir-format, fuzzy msgid "Artist" msgstr ""