Fix redirects for import/edit in collection index

This commit is contained in:
Claudio Ortolina
2024-10-22 09:12:17 +01:00
parent c7f9581b53
commit 758c62dff1
2 changed files with 23 additions and 4 deletions
@@ -141,6 +141,15 @@ defmodule MusicLibraryWeb.RecordLive.Index do
String.to_integer(value)
end
defp back_path(record_list_params) do
qs =
record_list_params
|> Map.take([:query, :page, :page_size])
|> Enum.filter(fn {_, v} -> v not in ["", nil] end)
~p"/records?#{qs}"
end
defp musicbrainz_url(record) do
"https://musicbrainz.org/release-group/#{record.musicbrainz_id}"
end
@@ -161,7 +161,12 @@
</li>
</ul>
<.modal :if={@live_action == :edit} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
<.modal
:if={@live_action == :edit}
id="record-modal"
show
on_cancel={JS.patch(back_path(@record_list_params))}
>
<.live_component
module={MusicLibraryWeb.RecordLive.FormComponent}
id={@record.id}
@@ -169,18 +174,23 @@
action={@live_action}
show_purchased_at={true}
record={@record}
patch={~p"/records"}
patch={back_path(@record_list_params)}
/>
</.modal>
<.modal :if={@live_action == :import} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
<.modal
:if={@live_action == :import}
id="record-modal"
show
on_cancel={JS.patch(back_path(@record_list_params))}
>
<.live_component
module={MusicLibraryWeb.RecordLive.ImportComponent}
id={:search}
title={@page_title}
action={@live_action}
record={@record}
patch={~p"/records"}
patch={back_path(@record_list_params)}
initial_query=""
/>
</.modal>