Skip to content

Commit

Permalink
update New
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrocp committed Jan 11, 2024
1 parent 855063a commit 646045e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ defmodule Beacon.LiveAdmin.PageEditorLive.FormComponent do
<.header>
<%= @page_title %>
<:actions>
<.button :if={@live_action == :new} phx-disable-with="Saving..." form="page-form" class="uppercase">Create Draft Page</.button>
<.button :if={!@visual_mode} phx-click="enable_visual_mode" phx-target={@myself} form="page-form" class="uppercase">Visual Editor</.button>
<.button :if={@visual_mode} phx-click="disable_visual_mode" phx-target={@myself} form="page-form" class="uppercase">Code Editor</.button>
<.button :if={@live_action == :new} phx-disable-with="Saving..." form="page-form" class="uppercase">Create Draft Page</.button>
<.button :if={@live_action == :edit} phx-disable-with="Saving..." form="page-form" class="uppercase">Save Changes</.button>
<.button :if={@live_action == :edit} phx-click={show_modal("publish-confirm-modal")} phx-target={@myself} class="uppercase">Publish</.button>
</:actions>
Expand Down
43 changes: 21 additions & 22 deletions lib/beacon/live_admin/live/page_editor_live/new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do
def menu_link(_, _), do: :skip

@impl true
def handle_params(params, _url, socket) do
{:noreply, assigns(socket, params)}
end

defp assigns(socket, params \\ %{}) do
def handle_params(_params, _url, socket) do
component_records =
Content.list_components(socket.assigns.beacon_page.site, per_page: :infinity)

%{data: components} = BeaconWeb.API.ComponentJSON.index(%{components: component_records})

Check warning on line 18 in lib/beacon/live_admin/live/page_editor_live/new.ex

View workflow job for this annotation

GitHub Actions / quality: OTP 26 | Elixir 1.15 | Phoenix ~> 1.7 | LiveView ~> 0.20

unknown_function

Function BeaconWeb.API.ComponentJSON.index/1 does not exist.

assign(socket,
page_title: "Create New Page",
visual_mode: params["visual_mode"] === "true",
components: components,
page: %Beacon.Content.Page{
path: "",
site: socket.assigns.beacon_page.site,
layout: %Beacon.Content.Layout{
template: "<%= @inner_content %>",
site: socket.assigns.beacon_page.site
}
}
)
{:noreply,
assign(socket,
page_title: "Create New Page",
components: components,
page: %Beacon.Content.Page{
path: "",
site: socket.assigns.beacon_page.site,
layout: %Beacon.Content.Layout{
template: "<%= @inner_content %>",
site: socket.assigns.beacon_page.site
}
}
)}
end

@impl true
Expand All @@ -60,9 +56,13 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do
{:reply, %{"ast" => ast}, socket}
end

def handle_event("update_page_ast", %{"id" => id, "ast" => ast}, socket) do
page = Content.set_page_ast(socket.assigns.beacon_page.site, socket.assigns.page, ast)
{:noreply, assign(socket, :page, page)}
def handle_event("update_page_ast", %{"ast" => ast}, socket) do
send_update(Beacon.LiveAdmin.PageEditorLive.FormComponent,
id: "page-editor-form-new",
ast: ast
)

{:noreply, socket}
end

@impl true
Expand All @@ -73,7 +73,6 @@ defmodule Beacon.LiveAdmin.PageEditorLive.New do
id="page-editor-form-new"
site={@beacon_page.site}
page_title={@page_title}
visual_mode={@visual_mode}
components={@components}
live_action={@live_action}
page={@page}
Expand Down

0 comments on commit 646045e

Please sign in to comment.