Update the LiveView to refactor and remove the unused code.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 2 months ago
parent 638c6c3bd1
commit 77514d75a0

@ -21,10 +21,6 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Edit do
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, {:ok,
socket socket
|> stream(
:authors,
Ash.read!(DecentralisedBookIndex.Metadata.Author, actor: socket.assigns[:current_user])
)
|> assign_new(:current_user, fn -> nil end)} |> assign_new(:current_user, fn -> nil end)}
end end
@ -54,7 +50,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Edit do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, _author}}, socket) do
{:noreply, stream_insert(socket, :authors, author)} {:noreply, socket}
end end
end end

@ -72,7 +72,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
end end
def handle_event("save", %{"author" => author_params}, socket) do def handle_event("save", %{"author" => author_params}, socket) do
case AshPhoenix.Form.submit(socket.assigns.form, params: author_params) do case AshPhoenix.Form.submit(socket.assigns.form, params: author_params, actor: socket.assigns.current_user) do
{:ok, author} -> {:ok, author} ->
notify_parent({:saved, author}) notify_parent({:saved, author})

@ -44,23 +44,6 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
params={@params} params={@params}
/> />
<% end %> <% end %>
<.modal
:if={@live_action in [:new, :edit]}
id="author-modal"
show
on_cancel={JS.patch(~p"/authors")}
>
<.live_component
module={DecentralisedBookIndexWeb.AuthorLive.FormComponent}
id={(@author && @author.id) || :new}
title={@page_title}
current_user={@current_user}
action={@live_action}
author={@author}
patch={~p"/authors"}
/>
</.modal>
""" """
end end
@ -118,18 +101,8 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, _author}}, socket) do
{:noreply, stream_insert(socket, :authors, author)} {:noreply, socket}
end
@impl true
def handle_event("delete", %{"id" => id}, socket) do
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 end
defp sort_options do defp sort_options do

@ -11,7 +11,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
<:actions> <:actions>
<%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %> <%= if @current_user != nil and Role.can_moderate?(@current_user.role) do %>
<.link navigate={~p"/authors/#{@author}/edit"}> <.link patch={~p"/authors/#{@author}/edit"}>
<.edit_button> <.edit_button>
Edit Edit
</.edit_button> </.edit_button>

@ -19,10 +19,6 @@ defmodule DecentralisedBookIndexWeb.BookLive.Edit do
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, {:ok,
socket socket
|> stream(
:books,
Ash.read!(DecentralisedBookIndex.Metadata.Book, actor: socket.assigns[:current_user])
)
|> assign_new(:current_user, fn -> nil end)} |> assign_new(:current_user, fn -> nil end)}
end end
@ -47,7 +43,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.Edit do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, book}}, socket) do def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, _book}}, socket) do
{:noreply, stream_insert(socket, :books, book)} {:noreply, socket}
end end
end end

@ -120,16 +120,8 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, book}}, socket) do def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, _book}}, socket) do
{:noreply, stream_insert(socket, :books, book)} {:noreply, socket}
end
@impl true
def handle_event("delete", %{"id" => id}, socket) do
book = Ash.get!(DecentralisedBookIndex.Metadata.Book, id, actor: socket.assigns.current_user)
Ash.destroy!(book, actor: socket.assigns.current_user)
{:noreply, stream_delete(socket, :books, book)}
end end
defp sort_options do defp sort_options do

@ -50,7 +50,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Edit do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do def handle_info({DecentralisedBookIndexWeb.DbiServerLive.FormComponent, {:saved, _dbi_server}}, socket) do
{:noreply, socket} {:noreply, socket}
end end
end end

@ -74,10 +74,6 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
def mount(_params, _session, socket) do def mount(_params, _session, socket) do
{:ok, {:ok,
socket socket
|> stream(
:dbi_servers,
Ash.read!(DecentralisedBookIndex.Metadata.DBIServer, actor: socket.assigns[:current_user])
)
|> assign_new(:current_user, fn -> nil end)} |> assign_new(:current_user, fn -> nil end)}
end end
@ -131,10 +127,10 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
@impl true @impl true
def handle_info( def handle_info(
{DecentralisedBookIndexWeb.DbiServerLive.FormComponent, {:saved, dbi_server}}, {DecentralisedBookIndexWeb.DbiServerLive.FormComponent, {:saved, _dbi_server}},
socket socket
) do ) do
{:noreply, stream_insert(socket, :dbi_servers, dbi_server)} {:noreply, socket}
end end
@impl true @impl true
@ -144,7 +140,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
Ash.destroy!(dbi_server, actor: socket.assigns.current_user) Ash.destroy!(dbi_server, actor: socket.assigns.current_user)
{:noreply, stream_delete(socket, :dbi_servers, dbi_server)} {:noreply, socket}
end end
defp sort_options do defp sort_options do

@ -50,7 +50,7 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Edit do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do def handle_info({DecentralisedBookIndexWeb.PublisherLive.FormComponent, {:saved, _publisher}}, socket) do
{:noreply, socket} {:noreply, socket}
end end
end end

@ -113,10 +113,10 @@ defmodule DecentralisedBookIndexWeb.PublisherLive.Index do
@impl true @impl true
def handle_info( def handle_info(
{DecentralisedBookIndexWeb.PublisherLive.FormComponent, {:saved, publisher}}, {DecentralisedBookIndexWeb.PublisherLive.FormComponent, {:saved, _publisher}},
socket socket
) do ) do
{:noreply, stream_insert(socket, :publishers, publisher)} {:noreply, socket}
end end
defp sort_options do defp sort_options do

@ -50,7 +50,7 @@ defmodule DecentralisedBookIndexWeb.UserLive.Edit do
end end
@impl true @impl true
def handle_info({DecentralisedBookIndexWeb.UserLive.FormComponent, {:saved, author}}, socket) do def handle_info({DecentralisedBookIndexWeb.UserLive.FormComponent, {:saved, _user}}, socket) do
{:noreply, socket} {:noreply, socket}
end end
end end

Loading…
Cancel
Save