Add raw Deepl module and a progress bar
This commit is contained in:
@ -39,6 +39,9 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
</div>
|
||||
<div class="article">
|
||||
<%= InternalTree.render_html_preview(@translation.article.content, @myself) |> raw %>
|
||||
<.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>
|
||||
<progress :if={@deepl_progress} max="100" value={@deepl_progress} />
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
@ -51,10 +54,20 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign(:changeset, changeset)}
|
||||
|> assign(:changeset, changeset)
|
||||
|> assign(:deepl_progress, nil)}
|
||||
end
|
||||
|
||||
def update(%{progress: progress}, socket) do
|
||||
{:ok, socket |> assign(deepl_progress: progress)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("translate-deepl", _, socket) do
|
||||
Task.start_link(Outlook.Translators.Deepl, :test, [self()])
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("validate", %{"translation" => translation_params}, socket) do
|
||||
changeset =
|
||||
socket.assigns.translation
|
||||
|
||||
@ -50,4 +50,10 @@ defmodule OutlookWeb.TranslationLive.NewEdit do
|
||||
defp common_assigns(socket) do
|
||||
assign(socket, form_cmpnt_id: @form_cmpnt_id)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:progress, payload}, socket) do
|
||||
send_update(self(), FormComponent, progress: payload.progress, id: @form_cmpnt_id)
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user