Remove manual record creation
This commit is contained in:
@@ -80,20 +80,5 @@ defmodule MusicLibraryWeb.RecordLive.FormComponent do
|
|||||||
end
|
end
|
||||||
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})
|
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ defmodule MusicLibraryWeb.RecordLive.Index do
|
|||||||
import MusicLibraryWeb.Pagination
|
import MusicLibraryWeb.Pagination
|
||||||
|
|
||||||
alias MusicLibrary.Records
|
alias MusicLibrary.Records
|
||||||
alias MusicLibrary.Records.Record
|
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(params, _session, socket) do
|
def mount(params, _session, socket) do
|
||||||
@@ -36,12 +35,6 @@ defmodule MusicLibraryWeb.RecordLive.Index do
|
|||||||
|> assign(:record, Records.get_record!(id))
|
|> assign(:record, Records.get_record!(id))
|
||||||
end
|
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
|
defp apply_action(socket, :index, params) do
|
||||||
new_socket =
|
new_socket =
|
||||||
socket
|
socket
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
<.header>
|
<.header>
|
||||||
Listing Records
|
Listing Records
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link patch={~p"/records/new"}>
|
|
||||||
<.button>New Record</.button>
|
|
||||||
</.link>
|
|
||||||
<.link patch={~p"/records/search"}>
|
<.link patch={~p"/records/search"}>
|
||||||
<.button>Search Record</.button>
|
<.button>Search Record</.button>
|
||||||
</.link>
|
</.link>
|
||||||
@@ -42,15 +39,10 @@
|
|||||||
</:action>
|
</:action>
|
||||||
</.table>
|
</.table>
|
||||||
|
|
||||||
<.modal
|
<.modal :if={@live_action == :edit} id="record-modal" show on_cancel={JS.patch(~p"/records")}>
|
||||||
:if={@live_action in [:new, :edit]}
|
|
||||||
id="record-modal"
|
|
||||||
show
|
|
||||||
on_cancel={JS.patch(~p"/records")}
|
|
||||||
>
|
|
||||||
<.live_component
|
<.live_component
|
||||||
module={MusicLibraryWeb.RecordLive.FormComponent}
|
module={MusicLibraryWeb.RecordLive.FormComponent}
|
||||||
id={@record.id || :new}
|
id={@record.id}
|
||||||
title={@page_title}
|
title={@page_title}
|
||||||
action={@live_action}
|
action={@live_action}
|
||||||
record={@record}
|
record={@record}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/images/:record_id", ImageController, :show
|
get "/images/:record_id", ImageController, :show
|
||||||
|
|
||||||
live "/records", RecordLive.Index, :index
|
live "/records", RecordLive.Index, :index
|
||||||
live "/records/new", RecordLive.Index, :new
|
|
||||||
live "/records/search", RecordLive.Index, :search
|
live "/records/search", RecordLive.Index, :search
|
||||||
live "/records/:id/edit", RecordLive.Index, :edit
|
live "/records/:id/edit", RecordLive.Index, :edit
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user