Replace new.ex and edit.ex with new_edit.ex in translations_live
This commit is contained in:
53
lib/outlook_web/live/translation_live/new_edit.ex
Normal file
53
lib/outlook_web/live/translation_live/new_edit.ex
Normal file
@ -0,0 +1,53 @@
|
||||
defmodule OutlookWeb.TranslationLive.NewEdit do
|
||||
use OutlookWeb, :live_view
|
||||
|
||||
alias Outlook.{Articles,Translations}
|
||||
alias Outlook.Translations.{Translation,Basic}
|
||||
alias OutlookWeb.TranslationLive.FormComponent
|
||||
|
||||
@form_cmpnt_id "formkomponente"
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.live_component
|
||||
module={OutlookWeb.TranslationLive.FormComponent}
|
||||
id={@form_cmpnt_id}
|
||||
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) when socket.assigns.live_action == :new do
|
||||
socket = socket
|
||||
|> assign_new(:translation, fn ->
|
||||
%Translation{
|
||||
article_id: article_id,
|
||||
article: get_article(article_id)
|
||||
}
|
||||
end)
|
||||
|> common_assigns()
|
||||
{:ok, assign_new(socket, :translation_content, fn ->
|
||||
Basic.internal_tree_to_tunit_map(socket.assigns.translation.article.content) end)}
|
||||
end
|
||||
|
||||
def mount(%{"id" => id} = _params, _session, socket) when socket.assigns.live_action == :edit do
|
||||
socket = socket
|
||||
|> assign_new(:translation, fn -> Translations.get_translation!(id) end)
|
||||
|> common_assigns()
|
||||
{:ok, assign_new(socket, :translation_content, fn -> socket.assigns.translation.content end)}
|
||||
end
|
||||
|
||||
defp get_article(article_id) do
|
||||
Articles.get_article!(article_id)
|
||||
end
|
||||
|
||||
defp common_assigns(socket) do
|
||||
assign(socket, form_cmpnt_id: @form_cmpnt_id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user