Change routes from "/records/*" to "/collection/*"

This commit is contained in:
Claudio Ortolina
2024-11-20 15:39:40 +00:00
parent b8f3bb9b2c
commit 5b3aab51ed
11 changed files with 56 additions and 52 deletions
@@ -7,7 +7,7 @@
<%= gettext("Stats") %> <%= gettext("Stats") %>
</.link> </.link>
<.link <.link
navigate={~p"/records"} navigate={~p"/collection"}
class={section_link_classes(assigns[:nav_section], :records)} class={section_link_classes(assigns[:nav_section], :records)}
> >
<%= gettext("Collection") %> <%= gettext("Collection") %>
@@ -96,7 +96,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
|> Map.put(:query, query) |> Map.put(:query, query)
|> Map.take([:query, :page, :page_size]) |> Map.take([:query, :page, :page_size])
{:noreply, push_patch(socket, to: ~p"/records?#{qs}")} {:noreply, push_patch(socket, to: ~p"/collection?#{qs}")}
end end
def handle_event("import", %{"id" => musicbrainz_id, "format" => format}, socket) do def handle_event("import", %{"id" => musicbrainz_id, "format" => format}, socket) do
@@ -110,7 +110,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
{:noreply, {:noreply,
socket socket
|> put_flash(:info, gettext("Record imported successfully")) |> put_flash(:info, gettext("Record imported successfully"))
|> push_navigate(to: ~p"/records/#{record.id}")} |> push_navigate(to: ~p"/collection/#{record.id}")}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, form: to_form(changeset))} {:noreply, assign(socket, form: to_form(changeset))}
@@ -119,7 +119,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
{:noreply, {:noreply,
socket socket
|> put_flash(:error, gettext("Error importing record") <> "," <> inspect(reason)) |> put_flash(:error, gettext("Error importing record") <> "," <> inspect(reason))
|> push_patch(to: ~p"/records")} |> push_patch(to: ~p"/collection")}
end end
end end
@@ -149,7 +149,7 @@ defmodule MusicLibraryWeb.CollectionLive.Index do
|> Map.take([:query, :page, :page_size]) |> Map.take([:query, :page, :page_size])
|> Enum.filter(fn {_, v} -> v not in ["", nil] end) |> Enum.filter(fn {_, v} -> v not in ["", nil] end)
~p"/records?#{qs}" ~p"/collection?#{qs}"
end end
defp musicbrainz_url(record) do defp musicbrainz_url(record) do
@@ -13,7 +13,7 @@
autocapitalize="none" autocapitalize="none"
/> />
</form> </form>
<.link patch={~p"/records/import"}> <.link patch={~p"/collection/import"}>
<.button><%= gettext("Import") %></.button> <.button><%= gettext("Import") %></.button>
</.link> </.link>
</div> </div>
@@ -36,7 +36,7 @@
> >
<li <li
:for={{id, record} <- @streams.records} :for={{id, record} <- @streams.records}
phx-click={JS.navigate(~p"/records/#{record}")} phx-click={JS.navigate(~p"/collection/#{record}")}
class="flex justify-between gap-x-6 py-5 hover:bg-zinc-50 dark:hover:bg-zinc-800 px-2 -mx-2 md:px-4 md:-mx-4 cursor-pointer" class="flex justify-between gap-x-6 py-5 hover:bg-zinc-50 dark:hover:bg-zinc-800 px-2 -mx-2 md:px-4 md:-mx-4 cursor-pointer"
id={id} id={id}
> >
@@ -51,7 +51,7 @@
<.link <.link
:for={artist <- record.artists} :for={artist <- record.artists}
class="text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300" class="text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
patch={~p"/records?query=mbid:#{artist.musicbrainz_id}"} patch={~p"/collection?query=mbid:#{artist.musicbrainz_id}"}
> >
<%= artist.name %> <%= artist.name %>
</.link> </.link>
@@ -151,7 +151,7 @@
role="menuitem" role="menuitem"
tabindex="-1" tabindex="-1"
id={"actions-#{record.id}-show"} id={"actions-#{record.id}-show"}
navigate={~p"/records/#{record}"} navigate={~p"/collection/#{record}"}
> >
<%= gettext("Show") %> <%= gettext("Show") %>
</.link> </.link>
@@ -171,7 +171,7 @@
role="menuitem" role="menuitem"
tabindex="-1" tabindex="-1"
id={"actions-#{record.id}-edit"} id={"actions-#{record.id}-edit"}
patch={~p"/records/#{record}/edit"} patch={~p"/collection/#{record}/edit"}
> >
<%= gettext("Edit") %> <%= gettext("Edit") %>
</.link> </.link>
@@ -9,9 +9,9 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
if connected?(socket) do if connected?(socket) do
socket socket
|> get_connect_params() |> get_connect_params()
|> Map.get("_live_referer", ~p"/records") |> Map.get("_live_referer", ~p"/collection")
else else
~p"/records" ~p"/collection"
end end
socket = socket =
@@ -40,7 +40,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
record = Records.get_record!(id) record = Records.get_record!(id)
{:ok, _} = Records.delete_record(record) {:ok, _} = Records.delete_record(record)
{:noreply, push_navigate(socket, to: ~p"/records")} {:noreply, push_navigate(socket, to: ~p"/collection")}
end end
def handle_event("refresh_musicbrainz_data", %{"id" => id}, socket) do def handle_event("refresh_musicbrainz_data", %{"id" => id}, socket) do
@@ -12,7 +12,7 @@
<.link <.link
:for={artist <- @record.artists} :for={artist <- @record.artists}
class="text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300" class="text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
patch={~p"/records?query=mbid:#{artist.musicbrainz_id}"} patch={~p"/collection?query=mbid:#{artist.musicbrainz_id}"}
> >
<%= artist.name %> <%= artist.name %>
</.link> </.link>
@@ -27,7 +27,7 @@
</p> </p>
<nav class="mt-5 isolate inline-flex rounded-md shadow-sm"> <nav class="mt-5 isolate inline-flex rounded-md shadow-sm">
<.link patch={~p"/records/#{@record}/show/edit"} phx-click={JS.push_focus()}> <.link patch={~p"/collection/#{@record}/show/edit"} phx-click={JS.push_focus()}>
<.button type="button" class="relative inline-flex items-center rounded-r-none"> <.button type="button" class="relative inline-flex items-center rounded-r-none">
<%= gettext("Edit") %> <%= gettext("Edit") %>
</.button> </.button>
@@ -159,7 +159,7 @@
:if={@live_action == :edit} :if={@live_action == :edit}
id="record-modal" id="record-modal"
show show
on_cancel={JS.patch(~p"/records/#{@record}")} on_cancel={JS.patch(~p"/collection/#{@record}")}
> >
<.live_component <.live_component
module={MusicLibraryWeb.RecordLive.FormComponent} module={MusicLibraryWeb.RecordLive.FormComponent}
@@ -168,6 +168,6 @@
action={@live_action} action={@live_action}
show_purchased_at={true} show_purchased_at={true}
record={@record} record={@record}
patch={~p"/records/#{@record}"} patch={~p"/collection/#{@record}"}
/> />
</.modal> </.modal>
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.StatsLive.DataComponents do
"relative overflow-hidden rounded-md bg-white dark:bg-zinc-800 px-4 pb-3 pt-5 shadow sm:px-6 sm:pt-6 cursor-pointer", "relative overflow-hidden rounded-md bg-white dark:bg-zinc-800 px-4 pb-3 pt-5 shadow sm:px-6 sm:pt-6 cursor-pointer",
@class @class
]} ]}
phx-click={JS.navigate(~p"/records/#{@record}")} phx-click={JS.navigate(~p"/collection/#{@record}")}
> >
<dt> <dt>
<img <img
@@ -29,7 +29,7 @@ defmodule MusicLibraryWeb.StatsLive.DataComponents do
<.link <.link
:for={artist <- @record.artists} :for={artist <- @record.artists}
class="text-sm md:text-base lg:text-2xl text-zinc-900 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" class="text-sm md:text-base lg:text-2xl text-zinc-900 hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200"
patch={~p"/records?query=mbid:#{artist.musicbrainz_id}"} patch={~p"/collection?query=mbid:#{artist.musicbrainz_id}"}
> >
<%= artist.name %> <%= artist.name %>
</.link> </.link>
@@ -8,7 +8,11 @@
title={gettext("Latest purchase")} title={gettext("Latest purchase")}
class="col-span-2 sm:col-span-3" class="col-span-2 sm:col-span-3"
/> />
<.counter title={gettext("Total collection")} count={@collection_count} path={~p"/records"} /> <.counter
title={gettext("Total collection")}
count={@collection_count}
path={~p"/collection"}
/>
<.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} /> <.counter title={gettext("Total wishlist")} count={@wishlist_count} path={~p"/wishlist"} />
</dl> </dl>
</div> </div>
@@ -28,7 +32,7 @@
<dd class="mt-1 text-center"> <dd class="mt-1 text-center">
<a <a
class="text-xl lg:text-2xl font-semibold hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" class="text-xl lg:text-2xl font-semibold hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200"
href={~p"/records?query=format:#{format}"} href={~p"/collection?query=format:#{format}"}
> >
<%= count %> <%= count %>
</a> </a>
@@ -52,7 +56,7 @@
<dd class="mt-1 text-center"> <dd class="mt-1 text-center">
<a <a
class="text-xl lg:text-2xl font-semibold hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200" class="text-xl lg:text-2xl font-semibold hover:text-zinc-500 dark:text-zinc-300 dark:hover:text-zinc-200"
href={~p"/records?query=type:#{type}"} href={~p"/collection?query=type:#{type}"}
> >
<%= count %> <%= count %>
</a> </a>
+5 -5
View File
@@ -32,12 +32,12 @@ defmodule MusicLibraryWeb.Router do
live "/", StatsLive.Index, :index live "/", StatsLive.Index, :index
live "/records", CollectionLive.Index, :index live "/collection", CollectionLive.Index, :index
live "/records/import", CollectionLive.Index, :import live "/collection/import", CollectionLive.Index, :import
live "/records/:id/edit", CollectionLive.Index, :edit live "/collection/:id/edit", CollectionLive.Index, :edit
live "/records/:id", CollectionLive.Show, :show live "/collection/:id", CollectionLive.Show, :show
live "/records/:id/show/edit", CollectionLive.Show, :edit live "/collection/:id/show/edit", CollectionLive.Show, :edit
live "/wishlist", WishlistLive.Index, :index live "/wishlist", WishlistLive.Index, :index
live "/wishlist/import", WishlistLive.Index, :import live "/wishlist/import", WishlistLive.Index, :import
+9 -9
View File
@@ -100,7 +100,7 @@ msgstr ""
msgid "Format" msgid "Format"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:18 #: lib/music_library_web/live/stats_live/index.html.heex:22
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Formats" msgid "Formats"
msgstr "" msgstr ""
@@ -178,7 +178,7 @@ msgid "No results"
msgstr "" msgstr ""
#: lib/music_library_web/live/collection_live/index.html.heex:121 #: lib/music_library_web/live/collection_live/index.html.heex:121
#: lib/music_library_web/live/stats_live/index.html.heex:155 #: lib/music_library_web/live/stats_live/index.html.heex:159
#: lib/music_library_web/live/wishlist_live/index.html.heex:121 #: lib/music_library_web/live/wishlist_live/index.html.heex:121
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Open options" msgid "Open options"
@@ -292,12 +292,12 @@ msgstr ""
msgid "The application has been updated, please reload." msgid "The application has been updated, please reload."
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:11 #: lib/music_library_web/live/stats_live/index.html.heex:12
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Total collection" msgid "Total collection"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:12 #: lib/music_library_web/live/stats_live/index.html.heex:16
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Total wishlist" msgid "Total wishlist"
msgstr "" msgstr ""
@@ -307,7 +307,7 @@ msgstr ""
msgid "Type" msgid "Type"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:42 #: lib/music_library_web/live/stats_live/index.html.heex:46
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Types" msgid "Types"
msgstr "" msgstr ""
@@ -363,7 +363,7 @@ msgstr ""
msgid "MusicBrainz data" msgid "MusicBrainz data"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:67 #: lib/music_library_web/live/stats_live/index.html.heex:71
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Scrobble activity" msgid "Scrobble activity"
msgstr "" msgstr ""
@@ -373,12 +373,12 @@ msgstr ""
msgid "Choose which format to import" msgid "Choose which format to import"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:124 #: lib/music_library_web/live/stats_live/index.html.heex:128
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Collected" msgid "Collected"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:137 #: lib/music_library_web/live/stats_live/index.html.heex:141
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Wishlisted" msgid "Wishlisted"
msgstr "" msgstr ""
@@ -411,7 +411,7 @@ msgstr ""
msgid "MusicBrainz data refreshed successfully" msgid "MusicBrainz data refreshed successfully"
msgstr "" msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:74 #: lib/music_library_web/live/stats_live/index.html.heex:78
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Refresh LastFm Feed" msgid "Refresh LastFm Feed"
msgstr "" msgstr ""
@@ -36,7 +36,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
conn: conn, conn: conn,
wishlist: wishlist_records wishlist: wishlist_records
} do } do
{:ok, index_live, _html} = live(conn, ~p"/records") {:ok, index_live, _html} = live(conn, ~p"/collection")
for record <- wishlist_records do for record <- wishlist_records do
refute has_element?(index_live, "#records-#{record.id}") refute has_element?(index_live, "#records-#{record.id}")
@@ -44,7 +44,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
end end
test "shows purchased records", %{conn: conn, collection: records} do test "shows purchased records", %{conn: conn, collection: records} do
{:ok, index_live, html} = live(conn, ~p"/records") {:ok, index_live, html} = live(conn, ~p"/collection")
assert html =~ "Collection" assert html =~ "Collection"
@@ -81,7 +81,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
setup [:fill_collection] setup [:fill_collection]
test "uses query string params", %{conn: conn, collection: records} do test "uses query string params", %{conn: conn, collection: records} do
{:ok, page_2_live, page_2_html} = live(conn, ~p"/records?page=2&page_size=25") {:ok, page_2_live, page_2_html} = live(conn, ~p"/collection?page=2&page_size=25")
{page_2_present, page_2_absent} = {page_2_present, page_2_absent} =
Enum.split_with(records, fn record -> Enum.split_with(records, fn record ->
@@ -98,7 +98,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
assert has_element?(page_2_pagination, "a", "4") assert has_element?(page_2_pagination, "a", "4")
assert has_element?(page_2_pagination, "a", "5") assert has_element?(page_2_pagination, "a", "5")
{:ok, page_3_live, page_3_html} = live(conn, ~p"/records?page=3&page_size=25") {:ok, page_3_live, page_3_html} = live(conn, ~p"/collection?page=3&page_size=25")
{page_3_present, page_3_absent} = {page_3_present, page_3_absent} =
Enum.split_with(records, fn record -> Enum.split_with(records, fn record ->
@@ -128,7 +128,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
test "supports raw queries", %{conn: conn, collection: records} do test "supports raw queries", %{conn: conn, collection: records} do
[record | _rest] = records [record | _rest] = records
qs = [query: record.title] qs = [query: record.title]
{:ok, index_live, _html} = live(conn, ~p"/records?#{qs}") {:ok, index_live, _html} = live(conn, ~p"/collection?#{qs}")
record_row = record_row =
index_live index_live
@@ -168,7 +168,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
page_size: @default_records_page_size page_size: @default_records_page_size
] ]
{:ok, index_live, _html} = live(conn, ~p"/records?#{qs}") {:ok, index_live, _html} = live(conn, ~p"/collection?#{qs}")
for record <- present do for record <- present do
record_row = record_row =
@@ -199,20 +199,20 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
test "can navigate to the record edit form", %{conn: conn} do test "can navigate to the record edit form", %{conn: conn} do
record = record_fixture() record = record_fixture()
{:ok, index_live, _html} = live(conn, ~p"/records") {:ok, index_live, _html} = live(conn, ~p"/collection")
assert index_live assert index_live
|> element("#records-#{record.id} a", "Edit") |> element("#records-#{record.id} a", "Edit")
|> render_click() =~ "Edit" |> render_click() =~ "Edit"
assert_patch(index_live, ~p"/records/#{record}/edit") assert_patch(index_live, ~p"/collection/#{record}/edit")
assert index_live |> render() =~ "Edit" assert index_live |> render() =~ "Edit"
end end
test "can change the record cover", %{conn: conn} do test "can change the record cover", %{conn: conn} do
record = record_fixture(cover_data: File.read!(marbles_cover_fixture())) record = record_fixture(cover_data: File.read!(marbles_cover_fixture()))
{:ok, form_live, html} = live(conn, ~p"/records/#{record.id}/edit") {:ok, form_live, html} = live(conn, ~p"/collection/#{record.id}/edit")
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}" assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
@@ -256,7 +256,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
describe "Importing a new record" do describe "Importing a new record" do
test "it shows the import modal", %{conn: conn} do test "it shows the import modal", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/records") {:ok, index_live, _html} = live(conn, ~p"/collection")
import_dialog = import_dialog =
index_live index_live
@@ -266,11 +266,11 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
assert import_dialog =~ "Search for a record on MusicBrainz" assert import_dialog =~ "Search for a record on MusicBrainz"
assert import_dialog =~ "No results" assert import_dialog =~ "No results"
assert_patch(index_live, ~p"/records/import") assert_patch(index_live, ~p"/collection/import")
end end
test "it imports a record when selected", %{conn: conn} do test "it imports a record when selected", %{conn: conn} do
{:ok, import_live, _html} = live(conn, ~p"/records/import") {:ok, import_live, _html} = live(conn, ~p"/collection/import")
mock_results = release_group_search_results() mock_results = release_group_search_results()
@@ -348,7 +348,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
musicbrainz_id: "1932f5b6-0b7b-4050-b1df-833ca89e5f44" musicbrainz_id: "1932f5b6-0b7b-4050-b1df-833ca89e5f44"
} = marillion } = marillion
assert_redirect(import_live, ~p"/records/#{record.id}") assert_redirect(import_live, ~p"/collection/#{record.id}")
end end
end end
end end
@@ -19,13 +19,13 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
test "can navigate to the record edit form", %{conn: conn} do test "can navigate to the record edit form", %{conn: conn} do
record = record_fixture() record = record_fixture()
{:ok, show_live, _html} = live(conn, ~p"/records/#{record.id}") {:ok, show_live, _html} = live(conn, ~p"/collection/#{record.id}")
assert show_live assert show_live
|> element("a", "Edit") |> element("a", "Edit")
|> render_click() =~ "Edit" |> render_click() =~ "Edit"
assert_patch(show_live, ~p"/records/#{record}/show/edit") assert_patch(show_live, ~p"/collection/#{record}/show/edit")
end end
end end
@@ -33,7 +33,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
test "it includes all needed information", %{conn: conn} do test "it includes all needed information", %{conn: conn} do
record = record_fixture() record = record_fixture()
{:ok, _show_live, html} = live(conn, ~p"/records/#{record.id}") {:ok, _show_live, html} = live(conn, ~p"/collection/#{record.id}")
assert html =~ escape(record.title) assert html =~ escape(record.title)
assert html =~ to_string(record.release) assert html =~ to_string(record.release)