From be4e33716a7c812440bc89900121c563bd6e380e Mon Sep 17 00:00:00 2001 From: Emily Elmseld Date: Wed, 16 Oct 2024 16:55:38 +0200 Subject: [PATCH 1/3] Add save & continue editing button --- lib/backpex/html/layout.ex | 6 ++++ .../html/resource/form_component.html.heex | 12 +++++++ lib/backpex/live_components/form_component.ex | 34 +++++++++++++++---- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/backpex/html/layout.ex b/lib/backpex/html/layout.ex index ce93ef0e..2b8680a4 100644 --- a/lib/backpex/html/layout.ex +++ b/lib/backpex/html/layout.ex @@ -130,6 +130,12 @@ defmodule Backpex.HTML.Layout do :if={Phoenix.Flash.get(@flash, :info) && Phoenix.Flash.get(@flash, :info) != ""} class="alert bg-info text-info-content my-4 text-sm" phx-value-key="info" + x-data="{ isVisible: false }" + x-init="() => { isVisible = true; setTimeout(() => isVisible = false, 5000) }" + x-show="isVisible" + x-transition:leave="transition ease-in duration-2000" + x-transition:leave-start="opacity-100 transform scale-100" + x-transition:leave-end="opacity-0 transform scale-90" > diff --git a/lib/backpex/html/resource/form_component.html.heex b/lib/backpex/html/resource/form_component.html.heex index 94449962..326a579b 100644 --- a/lib/backpex/html/resource/form_component.html.heex +++ b/lib/backpex/html/resource/form_component.html.heex @@ -53,7 +53,19 @@ + <% else %> <.link navigate={@live_resource.return_to(@socket, assigns, @live_action, @item)}> - @@ -57,7 +57,7 @@ type="submit" name="save-type" value="continue" - class={["btn", if(form_errors?(@show_form_errors, @form), do: "btn-error", else: "btn-primary")]} + class={["btn", if(form_errors?(@show_form_errors, @form), do: "btn-error", else: "btn-neutral btn-outline")]} phx-disable-with={@continue_label <> "..."} > <%= @continue_label %> diff --git a/lib/backpex/live_components/form_component.ex b/lib/backpex/live_components/form_component.ex index 4955f578..330544da 100644 --- a/lib/backpex/live_components/form_component.ex +++ b/lib/backpex/live_components/form_component.ex @@ -313,7 +313,7 @@ defmodule Backpex.FormComponent do end end - defp handle_save(socket, :resource_action, params, _) do + defp handle_save(socket, :resource_action, params, _save_type) do %{ assigns: %{ @@ -426,7 +426,7 @@ defmodule Backpex.FormComponent do defp flash_key(:ok), do: :info defp flash_key(:error), do: :error - defp return_to_path("continue", _, _, %{current_url: url}, item, :new) do + defp return_to_path("continue", _live_resource, _socket, %{current_url: url}, item, :new) do url |> URI.parse() |> Map.get(:path) @@ -434,11 +434,11 @@ defmodule Backpex.FormComponent do |> Kernel.<>("/#{item.id}/edit") end - defp return_to_path("continue", _, _, %{current_url: url}, _, _) do + defp return_to_path("continue", _live_resource, _socket, %{current_url: url}, _item, :edit) do URI.parse(url).path end - defp return_to_path(_, live_resource, socket, assigns, item, type) do + defp return_to_path(_save_type, live_resource, socket, assigns, item, type) do live_resource.return_to(socket, assigns, type, item) end diff --git a/lib/backpex/resource.ex b/lib/backpex/resource.ex index 651f9a55..66e99538 100644 --- a/lib/backpex/resource.ex +++ b/lib/backpex/resource.ex @@ -567,7 +567,7 @@ defmodule Backpex.Resource do %{custom_alias: custom_alias} -> association |> Map.from_struct() |> Map.put(:custom_alias, custom_alias) - _ -> + _other -> association |> Map.from_struct() end end) From d2d1f79ffe4af772daa6991a9d4fe50fb5519da0 Mon Sep 17 00:00:00 2001 From: Emily Elmseld Date: Mon, 21 Oct 2024 08:50:24 +0200 Subject: [PATCH 3/3] fix credo --- demo/lib/demo/short_link.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/lib/demo/short_link.ex b/demo/lib/demo/short_link.ex index c5fa9918..d204363a 100644 --- a/demo/lib/demo/short_link.ex +++ b/demo/lib/demo/short_link.ex @@ -38,7 +38,7 @@ defmodule Demo.ShortLink do defp add_short_key(changeset) do case get_field(changeset, :short_key) do nil -> put_change(changeset, :short_key, generate_short_key()) - _ -> changeset + _field -> changeset end end