defmodule OutlookWeb.TranslationLive.New do use OutlookWeb, :live_view alias Outlook.Articles alias Outlook.Translations.{Translation,Basic} @impl true def render(assigns) do ~H""" <.live_component module={OutlookWeb.TranslationLive.FormComponent} id={:new} title="New Translation" action={@live_action} translation={@translation} translation_content={@translation_content} navigate={~p"/translations"} /> """ end @impl true def mount(%{"article_id" => article_id} = _params, _session, socket) do socket = socket |> assign_new(:translation, fn -> %Translation{ article_id: article_id, article: get_article(article_id) } end) {:ok, assign_new(socket, :translation_content, fn -> Basic.internal_tree_to_tunit_map(socket.assigns.translation.article.content) end)} end defp get_article(article_id) do Articles.get_article!(article_id) end end