From fa7671f9727b6396efd0becefa62bbd79d1272e3 Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Thu, 19 Jan 2023 13:55:38 +0100 Subject: [PATCH] Add "publish" button to translation form --- .../live/translation_live/form_component.ex | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/outlook_web/live/translation_live/form_component.ex b/lib/outlook_web/live/translation_live/form_component.ex index b58de1b..88112af 100644 --- a/lib/outlook_web/live/translation_live/form_component.ex +++ b/lib/outlook_web/live/translation_live/form_component.ex @@ -32,18 +32,20 @@ defmodule OutlookWeb.TranslationLive.FormComponent do <.input field={{f, :public}} type="checkbox" label="public" /> <.input field={{f, :unauthorized}} type="checkbox" label="unauthorized" /> + + <:actions> - <.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit")} + <.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit") |> JS.set_attribute({"value", "false"}, to: "#publish")} phx-disable-with="Saving...">Save Translation - - <.button phx-click={JS.set_attribute({"value", "true"}, to: "#continue_edit")} + <.button phx-click={JS.set_attribute({"value", "false"}, to: "#continue_edit") |> JS.set_attribute({"value", "true"}, to: "#publish")} + phx-disable-with="Saving...">Save and Publish + <.button phx-click={JS.set_attribute({"value", "true"}, to: "#continue_edit") |> JS.set_attribute({"value", "false"}, to: "#publish")} phx-disable-with="Saving...">Save and Edit <.tunit_editor current_tunit={@current_tunit} 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 @@ -106,6 +108,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do "content", socket.assigns.translation_content ) + |> publish(params, socket) } save_translation(socket, socket.assigns.action, params) end @@ -188,4 +191,16 @@ defmodule OutlookWeb.TranslationLive.FormComponent do defp continue_edit(socket, %{"continue_edit" => "false"}) do socket |> push_navigate(to: socket.assigns.navigate) end + + defp publish(translation_params, %{"publish" => "true"}, socket) do + translation_params + |> Map.put("public_content", + OutlookWeb.HtmlDocComponent.render_doc(%{tree: InternalTree.render_translation(socket.assigns.translation.article.content, + translation_params["content"]), tunit_tag: "span"}) + |> Phoenix.HTML.Safe.to_iodata() + |> IO.iodata_to_binary()) + end + defp publish(translation_params, %{"publish" => "false"}, _) do + translation_params + end end