Skip to content

Commit

Permalink
It works!!
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Oct 20, 2023
1 parent 23cf2ff commit e1f1375
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/beacon/live_admin/live/page_editor_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Edit do
require IEx
use Beacon.LiveAdmin.PageBuilder
alias Beacon.LiveAdmin.Content
alias Beacon.LiveAdmin.WebAPI

@impl true
def menu_link("/pages", :edit), do: {:submenu, "Pages"}
Expand Down Expand Up @@ -58,12 +59,8 @@ defmodule Beacon.LiveAdmin.PageEditorLive.Edit do
def handle_event("render_component_in_page", %{ "component_id" => component_id, "page_id" => page_id }, socket) do
page = Content.get_page(socket.assigns.beacon_page.site, page_id)
component = Content.get_component(socket.assigns.beacon_page.site, component_id)
# path = for segment <- String.split(page.path, "/"), segment != "", do: segment
# beacon_live_data = Beacon.DataSource.live_data(page.site, path, [])
# {:ok, ast} = Beacon.Template.HEEx.JSONEncoder.encode(component.site, component.body, assigns)
# data = Map.put(data(component), :ast, ast)
# %{data: data}
{:reply, %{ "ast" => "sample_data" }, socket}
%{data: %{ ast: ast } } = WebAPI.Component.show_ast(socket.assigns.beacon_page.site, component, page)
{:reply, %{ "ast" => ast }, socket}
end

def handle_event("update_page_ast", %{ "id" => id, "ast" => ast }, socket) do
Expand Down
14 changes: 14 additions & 0 deletions lib/beacon/live_admin/web_api/component.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Beacon.LiveAdmin.WebAPI.Component do
@moduledoc """
Calls Beacon Web API through the cluster.
"""

import Beacon.LiveAdmin.Cluster, only: [call: 4]

def show_ast(site, component, page) do
path = for segment <- String.split(page.path, "/"), segment != "", do: segment
# beacon_live_data = Beacon.DataSource.live_data(site, path, [])
beacon_live_data = call(site, Beacon.DataSource, :live_data, [site, path, []])
call(site, BeaconWeb.API.ComponentJSON, :show_ast, [%{component: component, assigns: %{beacon_live_data: beacon_live_data}}])
end
end
File renamed without changes.

0 comments on commit e1f1375

Please sign in to comment.