Can delete records from the record show view
This commit is contained in:
@@ -16,6 +16,14 @@ defmodule MusicLibraryWeb.RecordLive.Show do
|
||||
|> assign(:record, Records.get_record!(id))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
record = Records.get_record!(id)
|
||||
{:ok, _} = Records.delete_record(record)
|
||||
|
||||
{:noreply, push_navigate(socket, to: ~p"/records")}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Record"
|
||||
defp page_title(:edit), do: "Edit Metadata"
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<.link patch={~p"/records/#{@record}/show/edit"} phx-click={JS.push_focus()}>
|
||||
<.button>Edit Metadata</.button>
|
||||
</.link>
|
||||
<.link phx-click={JS.push("delete", value: %{id: @record.id})} data-confirm="Are you sure?">
|
||||
<.button class="bg-red-900 hover:bg-red-700">Delete record</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user