Add HtmlDocComponent to render the InternalTree

Very basic but promising.
This commit is contained in:
Thelonius Kort
2023-01-05 22:22:44 +01:00
parent 927530c66d
commit 78160a5bae
3 changed files with 47 additions and 1 deletions

View File

@ -87,6 +87,7 @@ defmodule OutlookWeb do
# Core UI components and translation # Core UI components and translation
import OutlookWeb.CoreComponents import OutlookWeb.CoreComponents
import OutlookWeb.HtmlTreeComponent import OutlookWeb.HtmlTreeComponent
import OutlookWeb.HtmlDocComponent
import OutlookWeb.TunitEditorComponent import OutlookWeb.TunitEditorComponent
import OutlookWeb.Gettext import OutlookWeb.Gettext

View File

@ -0,0 +1,45 @@
defmodule OutlookWeb.HtmlDocComponent do
use Phoenix.Component
# use OutlookWeb, :html
import OutlookWeb.CoreComponents
import Phoenix.HTML
alias Phoenix.LiveView.JS
attr :tree, :list, required: true
def render_doc(assigns) do
~H"""
<%= for node <- @tree do %>
<.dnode node={node} />
<% end %>
"""
end
def dnode(%{node: %{status: status}} = assigns) do
~H"""
<span class="tunit" uuid={@node.uuid}>
<%= @node.content |> raw %>
</span>
"""
end
def dnode(assigns) when assigns.node.type == :element do
~H"""
<.dynamic_tag name={@node.name} uuid={@node.uuid}>
<%= for child_node <- @node.content do %>
<.dnode node={child_node} />
<% end %>
</.dynamic_tag>
"""
end
def dnode(assigns) when assigns.node.type == :text do
~H"<%= @node.content %>"
end
def dnode(assigns) when assigns.node.type == :comment do
~H"<!--<%= @node.content |> raw %>-->"
end
end

View File

@ -38,10 +38,10 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
<.tunit_editor current_tunit={@current_tunit} target={@myself} /> <.tunit_editor current_tunit={@current_tunit} target={@myself} />
</div> </div>
<div class="article"> <div class="article">
<%= InternalTree.render_html_preview(@translation.article.content, @myself) |> raw %>
<.button phx-disable-with="Translating..." phx-click="translate-deepl" phx-target={@myself} <.button phx-disable-with="Translating..." phx-click="translate-deepl" phx-target={@myself}
data-confirm-not="Are you sure? All previously translated text will be lost.">Translate with Deepl</.button> data-confirm-not="Are you sure? All previously translated text will be lost.">Translate with Deepl</.button>
<progress :if={@deepl_progress} max="100" value={@deepl_progress} /> <progress :if={@deepl_progress} max="100" value={@deepl_progress} />
<.render_doc tree={@translation.article.content} />
</div> </div>
</div> </div>
""" """