Improve logic and add working "delete" links

This commit is contained in:
Thelonius Kort
2023-02-14 21:02:48 +01:00
parent 7297a907da
commit faf2bb0e2e
8 changed files with 45 additions and 39 deletions

View File

@ -1,7 +1,7 @@
defmodule OutlookWeb.AuthorLive.Show do
use OutlookWeb, :live_view
alias Outlook.Authors
alias Outlook.{Authors,Articles}
@impl true
def mount(_params, _session, socket) do
@ -16,6 +16,15 @@ defmodule OutlookWeb.AuthorLive.Show do
|> assign(:author, Authors.get_author_with_articles!(id))}
end
@impl true
def handle_event("delete_article", %{"id" => id}, socket) do
article = Articles.get_article!(id)
{:ok, _} = Articles.delete_article(article)
{:noreply, socket
|> assign(:author, Authors.get_author_with_articles!(socket.assigns.author.id))}
end
defp page_title(:show), do: "Show Author"
defp page_title(:edit), do: "Edit Author"
end

View File

@ -31,7 +31,7 @@
<.link patch={~p"/articles/#{article}/edit"}>Edit</.link>
</:action>
<:action :let={article}>
<.link phx-click={JS.push("delete", value: %{id: article.id})} data-confirm="Are you sure?">
<.link phx-click={JS.push("delete_article", value: %{id: article.id})} data-confirm="Are you sure?">
Delete
</.link>
</:action>