Add raw Deepl module and a progress bar

This commit is contained in:
Thelonius Kort
2023-01-05 22:19:23 +01:00
parent bafd9c81f7
commit 927530c66d
3 changed files with 97 additions and 1 deletions

View File

@ -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

View File

@ -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