Skip to content

Commit

Permalink
Create app_view component and made app_page a Stripped page
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Sep 26, 2023
1 parent 1ede2d2 commit c0dda6e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule CoreWeb.Layouts.Stripped.Component do
</div>
<% end %>
<div class="flex-1 bg-white">
<div class="flex flex-row">
<div class="flex flex-row w-full h-full">
<div class="flex-1">
<%= render_slot(@inner_block) %>
<Margin.y id={:page_footer_top} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Systems.Feldspar.Internal do
defmodule Systems.Feldspar.Private do
def get_backend do
:core
|> Application.fetch_env!(:feldspar)
Expand Down
2 changes: 1 addition & 1 deletion core/systems/feldspar/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Systems.Feldspar.Public do
Feldspar
}

import Feldspar.Internal, only: [get_backend: 0]
import Feldspar.Private, only: [get_backend: 0]

def get_tool!(id, preload \\ []) do
from(tool in Feldspar.ToolModel, preload: ^preload)
Expand Down
51 changes: 33 additions & 18 deletions core/systems/feldspar/app_page.ex
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
defmodule Systems.Feldspar.AppPage do
alias Systems.Feldspar
use CoreWeb, :live_view
use CoreWeb.Layouts.Stripped.Component, :projects

import Feldspar.AppView

@impl true
def mount(%{"id" => app_id}, _session, socket) do
app_url = Feldspar.Public.get_public_url(app_id) <> "/index.html"

{:ok, assign(socket, app_url: app_url, error: nil)}
{
:ok,
socket
|> update_menus()
|> assign(app_url: app_url, error: nil)
}
end

@impl true
def handle_uri(socket), do: socket

@impl true
def render(assigns) do
~H"""
<div class="flex flex-col w-full h-screen">
<%!-- Ensure that updates don't alter the hierarchy in front of the iframe.
Changing the preceding siblings of the iframe would result in a reload of the iframe
due to Morphdom (https://github.com/patrick-steele-idem/morphdom/issues/200).
--%>
<div>
<div :if={@error} class="bg-[#ff00ff] text-white p-8 text-xl"><%= @error %></div>
</div>
<div phx-update="ignore" id="web-app-frame" phx-hook="FeldsparApp">
<iframe src={@app_url} class="grow w-full h-screen"></iframe>
</div>
</div>
<.stripped menus={@menus}>
<.app_view url={@app_url} />
</.stripped>
"""
end

@impl true
def handle_event("app_event", params, socket) do
{:noreply, assign(socket, :error, "Unsupported message: #{inspect(params)}")}
def handle_event("app_event", %{"__type__" => type, "json_string" => event}, socket) do
{
:noreply,
socket |> handle(type, event)
}
end

@impl true
def handle_event("app_event", event, socket) do
{
:noreply,
socket |> handle(nil, inspect(event))
}
end

defp handle(socket, "CommandSystemDonate", event) do
Frameworks.Pixel.Flash.put_error(socket, "Unsupported donation " <> event)
end

defp handle(socket, _, event) do
Frameworks.Pixel.Flash.put_error(socket, "Unsupported " <> event)
end
end
19 changes: 19 additions & 0 deletions core/systems/feldspar/app_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Systems.Feldspar.AppView do
use CoreWeb, :html

attr(:url, :string, required: true)

def app_view(assigns) do
~H"""
<div class="flex flex-col w-full h-full">
<%!-- Ensure that updates don't alter the hierarchy in front of the iframe.
Changing the preceding siblings of the iframe would result in a reload of the iframe
due to Morphdom (https://github.com/patrick-steele-idem/morphdom/issues/200).
--%>
<div class="w-full h-full" phx-update="ignore" id="web-app-frame" phx-hook="FeldsparApp">
<iframe src={@url} class="w-full h-full"></iframe>
</div>
</div>
"""
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Systems.Feldspar.Plug do
conn,
options
) do
call(Systems.Feldspar.Internal.get_backend(), conn, options)
call(Systems.Feldspar.Private.get_backend(), conn, options)
end

def call(Systems.Feldspar.LocalFS, conn, options) do
Expand Down
2 changes: 1 addition & 1 deletion core/test/systems/feldspar/app_page_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Systems.Feldspar.AppPageTest do
{:ok, view, _html} = live(conn, ~p"/apps/test")

assert render_hook(view, :app_event, %{unexpected_key: "some data"}) =~
"Unsupported message:"
"Unsupported "
end
end
end

0 comments on commit c0dda6e

Please sign in to comment.