Fix issues with changed default :current_tunit
This commit is contained in:
@ -71,7 +71,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
{:ok, new_translation_content} ->
|
||||
{:ok, socket
|
||||
|> assign(translation_content: new_translation_content)
|
||||
|> update_current_tunit()}
|
||||
|> update_current_tunit(socket.assigns.current_tunit.status)}
|
||||
{:error, message} ->
|
||||
{:ok, socket |> put_flash(:error, message)}
|
||||
end
|
||||
@ -94,7 +94,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
|
||||
def handle_event("save", %{"translation" => translation_params}, socket) do
|
||||
socket = socket
|
||||
|> update_translation_with_current_tunit()
|
||||
|> update_translation_with_current_tunit(socket.assigns.current_tunit.status)
|
||||
translation_params = translation_params
|
||||
|> Map.put("content", socket.assigns.translation_content)
|
||||
save_translation(socket, socket.assigns.action, translation_params)
|
||||
@ -108,7 +108,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
def handle_event("select_current_tunit", %{"uuid" => uuid}, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> update_translation_with_current_tunit
|
||||
|> update_translation_with_current_tunit(socket.assigns.current_tunit.status)
|
||||
|> assign(:current_tunit, socket.assigns.translation_content[uuid])}
|
||||
end
|
||||
|
||||
@ -120,12 +120,12 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
|
||||
|
||||
# updating after Deepl translation
|
||||
defp update_current_tunit(socket) when is_struct(socket.assigns.current_tunit) do
|
||||
defp update_current_tunit(socket, nil), do: socket
|
||||
defp update_current_tunit(socket, _) do
|
||||
assign(socket,
|
||||
:current_tunit,
|
||||
socket.assigns.translation_content[socket.assigns.current_tunit.uuid])
|
||||
end
|
||||
defp update_current_tunit(socket), do: socket
|
||||
|
||||
defp assign_article_tree(socket, translation) do
|
||||
socket
|
||||
@ -135,15 +135,12 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
|
||||
%{tunits: %{phx: %{click: "select_current_tunit", target: socket.assigns.myself}}}))
|
||||
end
|
||||
|
||||
defp update_translation_with_current_tunit(socket) do
|
||||
translation_content = if socket.assigns.current_tunit do
|
||||
socket.assigns.translation_content
|
||||
|> Map.put(socket.assigns.current_tunit.uuid, socket.assigns.current_tunit)
|
||||
else
|
||||
socket.assigns.translation_content
|
||||
end
|
||||
defp update_translation_with_current_tunit(socket, nil), do: socket
|
||||
defp update_translation_with_current_tunit(socket, _) do
|
||||
socket
|
||||
|> assign(:translation_content, translation_content)
|
||||
|> assign(:translation_content,
|
||||
socket.assigns.translation_content
|
||||
|> Map.put(socket.assigns.current_tunit.uuid, socket.assigns.current_tunit))
|
||||
end
|
||||
|
||||
defp save_translation(socket, :edit, translation_params) do
|
||||
|
||||
Reference in New Issue
Block a user