parent
3ee8b2ed0b
commit
d8587ca9b6
@ -0,0 +1,56 @@
|
||||
defmodule DecentralisedBookIndexWeb.DbiServerLive.Edit do
|
||||
use DecentralisedBookIndexWeb, :live_view
|
||||
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.live_component
|
||||
module={DecentralisedBookIndexWeb.DbiServerLive.FormComponent}
|
||||
id={(@dbi_server && @dbi_server.id) || :new}
|
||||
title={@page_title}
|
||||
current_user={@current_user}
|
||||
action={@live_action}
|
||||
dbi_server={@dbi_server}
|
||||
/>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign_new(:current_user, fn -> nil end)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:params, params)
|
||||
|> apply_action(socket.assigns.live_action, params)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Server")
|
||||
|> assign(
|
||||
:dbi_server,
|
||||
Ash.get!(DecentralisedBookIndex.Metadata.DBIServer, id, actor: socket.assigns.current_user)
|
||||
)
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Server")
|
||||
|> assign(:dbi_server, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
@ -0,0 +1,56 @@
|
||||
defmodule DecentralisedBookIndexWeb.PublisherLive.Edit do
|
||||
use DecentralisedBookIndexWeb, :live_view
|
||||
|
||||
alias DecentralisedBookIndex.Metadata
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.live_component
|
||||
module={DecentralisedBookIndexWeb.PublisherLive.FormComponent}
|
||||
id={(@publisher && @publisher.id) || :new}
|
||||
title={@page_title}
|
||||
current_user={@current_user}
|
||||
action={@live_action}
|
||||
publisher={@publisher}
|
||||
/>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign_new(:current_user, fn -> nil end)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:params, params)
|
||||
|> apply_action(socket.assigns.live_action, params)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Publisher")
|
||||
|> assign(
|
||||
:publisher,
|
||||
Ash.get!(DecentralisedBookIndex.Metadata.Publisher, id, actor: socket.assigns.current_user)
|
||||
)
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Publisher")
|
||||
|> assign(:publisher, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
Loading…
Reference in new issue