From 54ee84ad2f620565fb02bf33d0fdc39c92811baf Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 24 Sep 2024 09:57:31 +0100 Subject: [PATCH] Can delete records from the record show view --- lib/music_library_web/live/record_live/show.ex | 8 ++++++++ lib/music_library_web/live/record_live/show.html.heex | 3 +++ 2 files changed, 11 insertions(+) diff --git a/lib/music_library_web/live/record_live/show.ex b/lib/music_library_web/live/record_live/show.ex index 3f582b61..414e5918 100644 --- a/lib/music_library_web/live/record_live/show.ex +++ b/lib/music_library_web/live/record_live/show.ex @@ -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" diff --git a/lib/music_library_web/live/record_live/show.html.heex b/lib/music_library_web/live/record_live/show.html.heex index 5292aa05..5dd947dc 100644 --- a/lib/music_library_web/live/record_live/show.html.heex +++ b/lib/music_library_web/live/record_live/show.html.heex @@ -5,6 +5,9 @@ <.link patch={~p"/records/#{@record}/show/edit"} phx-click={JS.push_focus()}> <.button>Edit Metadata + <.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 +