diff --git a/lib/beacon/live_admin/live/page_editor_live/edit.ex b/lib/beacon/live_admin/live/page_editor_live/edit.ex index eab44f25..03757ced 100644 --- a/lib/beacon/live_admin/live/page_editor_live/edit.ex +++ b/lib/beacon/live_admin/live/page_editor_live/edit.ex @@ -11,13 +11,13 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Edit do def menu_link(_, _), do: :skip @impl true - def mount(_params, _session, socket) do + def mount(params, _session, socket) do component_records = Content.list_components(socket.assigns.beacon_page.site, per_page: :infinity) - {:ok, assign(socket, page: nil, visual_mode: true, components: component_records)} + {:ok, assign(socket, page: nil, visual_mode: params["visual_mode"] === "true", components: component_records)} end @impl true - def handle_params(%{"id" => id}, _url, socket) do + def handle_params(%{"id" => id } = params, _url, socket) do page = Content.get_page(socket.assigns.beacon_page.site, id, preloads: [:layout]) component_records = Content.list_components(socket.assigns.beacon_page.site, per_page: :infinity) @@ -27,7 +27,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Edit do assign(socket, page_title: "Edit Page", page: page, - visual_mode: false, + visual_mode: params["visual_mode"] === "true", components: components )} end @@ -44,12 +44,16 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Edit do @impl true def handle_event("enable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: true)} + socket = assign(socket, visual_mode: true) + path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, socket.assigns.beacon_page.site, "/pages/#{socket.assigns.page.id}", %{visual_mode: "true"}) + {:noreply, push_patch(socket, to: path)} end @impl true def handle_event("disable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: false)} + socket = assign(socket, visual_mode: false) + path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, socket.assigns.beacon_page.site, "/pages/#{socket.assigns.page.id}") + {:noreply, push_patch(socket, to: path)} end @impl true 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..fe99309b 100644 --- a/lib/beacon/live_admin/live/page_editor_live/new.ex +++ b/lib/beacon/live_admin/live/page_editor_live/new.ex @@ -11,17 +11,17 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do def menu_link(_, _), do: :skip @impl true - def handle_params(_params, _url, socket) do - {:noreply, assigns(socket)} + def handle_params(params, _url, socket) do + {:noreply, assigns(socket, params)} end - defp assigns(socket) do + defp assigns(socket, params \\ %{}) do component_records = Content.list_components(socket.assigns.beacon_page.site, per_page: :infinity) %{data: components} = BeaconWeb.API.ComponentJSON.index(%{components: component_records}) assign(socket, page_title: "Create New Page", - visual_mode: true, + visual_mode: params["visual_mode"] === "true", components: components, page: %Beacon.Content.Page{ path: "", @@ -46,14 +46,19 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do @impl true def handle_event("enable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: true)} + socket = assign(socket, visual_mode: true) + path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, socket.assigns.beacon_page.site, "/pages/new", %{visual_mode: "true"}) + {:noreply, push_patch(socket, to: path)} end @impl true def handle_event("disable_visual_mode", _args, socket) do - {:noreply, assign(socket, visual_mode: false)} + socket = assign(socket, visual_mode: false) + path = Beacon.LiveAdmin.Router.beacon_live_admin_path(socket, socket.assigns.beacon_page.site, "/pages/new") + {:noreply, push_patch(socket, to: path)} end + @impl true def handle_event( "render_component_in_page",