From 901685a53b57eb58fa1d192126e94cc18101c1ce Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Fri, 15 Dec 2023 16:44:49 -0300 Subject: [PATCH] move visual mode handle event to the current process --- .../live/page_editor_live/form_component.ex | 12 ++++++++++-- lib/beacon/live_admin/live/page_editor_live/new.ex | 10 ---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/beacon/live_admin/live/page_editor_live/form_component.ex b/lib/beacon/live_admin/live/page_editor_live/form_component.ex index b7e948db..23886417 100644 --- a/lib/beacon/live_admin/live/page_editor_live/form_component.ex +++ b/lib/beacon/live_admin/live/page_editor_live/form_component.ex @@ -83,6 +83,14 @@ defmodule Beacon.LiveAdmin.PageEditorLive.FormComponent do end end + def handle_event("enable_visual_mode", _args, socket) do + {:noreply, assign(socket, visual_mode: true)} + end + + def handle_event("disable_visual_mode", _args, socket) do + {:noreply, assign(socket, visual_mode: false)} + end + defp save_page(socket, :new, page_params) do case Content.create_page(socket.assigns.site, page_params) do {:ok, page} -> @@ -131,8 +139,8 @@ defmodule Beacon.LiveAdmin.PageEditorLive.FormComponent do <%= @page_title %> <:actions> <.button :if={@live_action == :new} phx-disable-with="Saving..." form="page-form" class="uppercase">Create Draft Page - <.button :if={!@visual_mode} phx-click="enable_visual_mode" form="page-form" class="uppercase">Visual Editor - <.button :if={@visual_mode} phx-click="disable_visual_mode" form="page-form" class="uppercase">Code Editor + <.button :if={!@visual_mode} phx-click="enable_visual_mode" phx-target={@myself} form="page-form" class="uppercase">Visual Editor + <.button :if={@visual_mode} phx-click="disable_visual_mode" phx-target={@myself} form="page-form" class="uppercase">Code Editor <.button :if={@live_action == :edit} phx-disable-with="Saving..." form="page-form" class="uppercase">Save Changes <.button :if={@live_action == :edit} phx-click={show_modal("publish-confirm-modal")} phx-target={@myself} class="uppercase">Publish diff --git a/lib/beacon/live_admin/live/page_editor_live/new.ex b/lib/beacon/live_admin/live/page_editor_live/new.ex index 0bc70de1..2bf8b724 100644 --- a/lib/beacon/live_admin/live/page_editor_live/new.ex +++ b/lib/beacon/live_admin/live/page_editor_live/new.ex @@ -44,16 +44,6 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do {:noreply, socket} end - @impl true - def handle_event("enable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: true)} - end - - @impl true - def handle_event("disable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: false)} - end - @impl true def handle_event( "render_component_in_page",