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

@ -72,7 +72,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.FormComponent do
end
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} ->
notify_parent({:saved, author})

@ -44,23 +44,6 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
params={@params}
/>
<% 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
@ -118,18 +101,8 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Index do
end
@impl true
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, author}}, socket) do
{:noreply, stream_insert(socket, :authors, author)}
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)}
def handle_info({DecentralisedBookIndexWeb.AuthorLive.FormComponent, {:saved, _author}}, socket) do
{:noreply, socket}
end
defp sort_options do

@ -11,7 +11,7 @@ defmodule DecentralisedBookIndexWeb.AuthorLive.Show do
<:actions>
<%= 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
</.edit_button>

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

@ -120,16 +120,8 @@ defmodule DecentralisedBookIndexWeb.BookLive.Index do
end
@impl true
def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, book}}, socket) do
{:noreply, stream_insert(socket, :books, book)}
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)}
def handle_info({DecentralisedBookIndexWeb.BookLive.FormComponent, {:saved, _book}}, socket) do
{:noreply, socket}
end
defp sort_options do

@ -50,7 +50,7 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Edit do
end
@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}
end
end

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

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

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

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

Loading…
Cancel
Save