Remove manual record creation

This commit is contained in:
Claudio Ortolina
2024-09-24 09:27:35 +01:00
parent b6ae022a6a
commit 089e61a574
4 changed files with 2 additions and 33 deletions
@@ -80,20 +80,5 @@ defmodule MusicLibraryWeb.RecordLive.FormComponent do
end
end
defp save_record(socket, :new, record_params) do
case Records.create_record(record_params) do
{:ok, record} ->
notify_parent({:saved, record})
{:noreply,
socket
|> put_flash(:info, "Record created successfully")
|> push_patch(to: socket.assigns.patch)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, form: to_form(changeset))}
end
end
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
end
@@ -3,7 +3,6 @@ defmodule MusicLibraryWeb.RecordLive.Index do
import MusicLibraryWeb.Pagination
alias MusicLibrary.Records
alias MusicLibrary.Records.Record
@impl true
def mount(params, _session, socket) do
@@ -36,12 +35,6 @@ defmodule MusicLibraryWeb.RecordLive.Index do
|> assign(:record, Records.get_record!(id))
end
defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Record")
|> assign(:record, %Record{})
end
defp apply_action(socket, :index, params) do
new_socket =
socket
@@ -1,9 +1,6 @@
<.header>
Listing Records
<:actions>
<.link patch={~p"/records/new"}>
<.button>New Record</.button>
</.link>
<.link patch={~p"/records/search"}>
<.button>Search Record</.button>
</.link>
@@ -42,15 +39,10 @@
</:action>
</.table>
<.modal
:if={@live_action in [:new, :edit]}
id="record-modal"
show
on_cancel={JS.patch(~p"/records")}
>
<.modal :if={@live_action == :edit} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
<.live_component
module={MusicLibraryWeb.RecordLive.FormComponent}
id={@record.id || :new}
id={@record.id}
title={@page_title}
action={@live_action}
record={@record}
-1
View File
@@ -21,7 +21,6 @@ defmodule MusicLibraryWeb.Router do
get "/images/:record_id", ImageController, :show
live "/records", RecordLive.Index, :index
live "/records/new", RecordLive.Index, :new
live "/records/search", RecordLive.Index, :search
live "/records/:id/edit", RecordLive.Index, :edit