|
|
|
@ -54,6 +54,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|
|
|
|
module={DecentralisedBookIndexWeb.AuthorLive.FormComponent}
|
|
|
|
|
id={(@author && @author.id) || :new}
|
|
|
|
|
title={@page_title}
|
|
|
|
|
current_user={@current_user}
|
|
|
|
|
action={@live_action}
|
|
|
|
|
author={@author}
|
|
|
|
|
patch={~p"/authors"}
|
|
|
|
@ -64,7 +65,13 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def mount(_params, _session, socket) do
|
|
|
|
|
{:ok, stream(socket, :authors, Ash.read!(DecentralisedBookIndex.Metadata.Author))}
|
|
|
|
|
{:ok,
|
|
|
|
|
socket
|
|
|
|
|
|> stream(
|
|
|
|
|
:authors,
|
|
|
|
|
Ash.read!(DecentralisedBookIndex.Metadata.Author, actor: socket.assigns[:current_user])
|
|
|
|
|
)
|
|
|
|
|
|> assign_new(:current_user, fn -> nil end)}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
@ -75,7 +82,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|
|
|
|
defp apply_action(socket, :edit, %{"id" => id}) do
|
|
|
|
|
socket
|
|
|
|
|
|> assign(:page_title, "Edit Author")
|
|
|
|
|
|> assign(:author, Ash.get!(DecentralisedBookIndex.Metadata.Author, id))
|
|
|
|
|
|> assign(
|
|
|
|
|
:author,
|
|
|
|
|
Ash.get!(DecentralisedBookIndex.Metadata.Author, id, actor: socket.assigns.current_user)
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp apply_action(socket, :new, _params) do
|
|
|
|
@ -97,8 +107,10 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def handle_event("delete", %{"id" => id}, socket) do
|
|
|
|
|
author = Ash.get!(DecentralisedBookIndex.Metadata.Author, id)
|
|
|
|
|
Ash.destroy!(author)
|
|
|
|
|
author =
|
|
|
|
|
Ash.get!(DecentralisedBookIndex.Metadata.Author, id, actor: socket.assigns.current_user)
|
|
|
|
|
|
|
|
|
|
Ash.destroy!(author, actor: socket.assigns.current_user)
|
|
|
|
|
|
|
|
|
|
{:noreply, stream_delete(socket, :authors, author)}
|
|
|
|
|
end
|
|
|
|
|