From 758c62dff1251a993592459204773cec69c241ea Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 22 Oct 2024 09:12:17 +0100 Subject: [PATCH] Fix redirects for import/edit in collection index --- .../live/record_live/index.ex | 9 +++++++++ .../live/record_live/index.html.heex | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/music_library_web/live/record_live/index.ex b/lib/music_library_web/live/record_live/index.ex index 87dcf965..f5d9e884 100644 --- a/lib/music_library_web/live/record_live/index.ex +++ b/lib/music_library_web/live/record_live/index.ex @@ -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 diff --git a/lib/music_library_web/live/record_live/index.html.heex b/lib/music_library_web/live/record_live/index.html.heex index b6f168eb..53136bfa 100644 --- a/lib/music_library_web/live/record_live/index.html.heex +++ b/lib/music_library_web/live/record_live/index.html.heex @@ -161,7 +161,12 @@ -<.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 :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="" />