You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
745 B

defmodule MirageWeb.LinkLive.Show do
use MirageWeb, :live_view
alias Mirage.Links
defp page_title(:show), do: "Show Link"
defp page_title(:edit), do: "Edit Link"
@impl true
def mount(_params, session, socket) do
{:ok, socket |> with_user(session)}
end
@impl true
def handle_params(%{"id" => id}, _, socket) do
link =
id
|> Links.get_link!()
|> Links.preload_link()
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:link, link)}
end
@impl true
def handle_event("delete", %{"id" => id}, socket) do
link = Links.get_link!(id)
{:ok, _} = Links.delete_link(link)
{:noreply, push_redirect(socket, to: "/links")}
end
end