From f329d66fb122275c5e93c3151d57764234003a0a Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 15 Jul 2025 10:08:40 +0100 Subject: [PATCH] Add format to online store templates --- lib/music_library/online_store_templates.ex | 2 ++ .../live/online_store_template_live/form_component.ex | 10 +++++++++- priv/gettext/default.pot | 5 +++++ priv/gettext/en/LC_MESSAGES/default.po | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/music_library/online_store_templates.ex b/lib/music_library/online_store_templates.ex index 2fdc0d10..9feab061 100644 --- a/lib/music_library/online_store_templates.ex +++ b/lib/music_library/online_store_templates.ex @@ -68,9 +68,11 @@ defmodule MusicLibrary.OnlineStoreTemplates do """ def generate_url(template, record) do artists_string = Enum.map_join(record.artists, " ", & &1.name) + format_string = Atom.to_string(record.format) template.url_template |> String.replace("{artist}", URI.encode(artists_string)) |> String.replace("{title}", URI.encode(record.title)) + |> String.replace("{format}", URI.encode(format_string)) end end diff --git a/lib/music_library_web/live/online_store_template_live/form_component.ex b/lib/music_library_web/live/online_store_template_live/form_component.ex index c62a72be..e42f5cec 100644 --- a/lib/music_library_web/live/online_store_template_live/form_component.ex +++ b/lib/music_library_web/live/online_store_template_live/form_component.ex @@ -59,6 +59,10 @@ defmodule MusicLibraryWeb.OnlineStoreTemplateLive.FormComponent do {"{title}"} - {gettext("Record title")}

+

+ {"{format}"} + - {gettext("Record format")} +

@@ -74,7 +78,11 @@ defmodule MusicLibraryWeb.OnlineStoreTemplateLive.FormComponent do @impl true def update(%{template: template} = assigns, socket) do - test_record = %Record{title: "Dark Side of the Moon", artists: [%Artist{name: "Pink Floyd"}]} + test_record = %Record{ + title: "Dark Side of the Moon", + artists: [%Artist{name: "Pink Floyd"}], + format: :vinyl + } {:ok, socket diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 5f5a1d4d..71822edf 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -1265,3 +1265,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Manage templates for generating links to online record stores." msgstr "" + +#: lib/music_library_web/live/online_store_template_live/form_component.ex +#, elixir-autogen, elixir-format +msgid "Record format" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 1bb903f8..7768d521 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -1265,3 +1265,8 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Manage templates for generating links to online record stores." msgstr "" + +#: lib/music_library_web/live/online_store_template_live/form_component.ex +#, elixir-autogen, elixir-format +msgid "Record format" +msgstr ""