My space on the web https://inhji.de
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.
 
 
 
 
 

46 lines
1.1 KiB

defmodule MirageWeb.ShowNoteLive do
use MirageWeb, :live_view
alias Mirage.Notes
alias Mirage.Notes.NoteLink
@impl true
def mount(_params, %{"user_id" => user_id}, socket) do
current_user = user_id && Mirage.Accounts.get_user!(user_id)
{:ok, socket |> assign(%{current_user: current_user})}
end
@impl true
def handle_params(%{"id" => note_id}, _uri, socket) do
note =
note_id
|> Notes.get_note!()
|> Notes.preload_note()
link_changeset = NoteLink.changeset(%NoteLink{}, %{note_id: note_id})
{:noreply, socket |> assign(%{note: note, link_changeset: link_changeset})}
end
@impl true
def handle_event("save_link", %{"note_link" => link}, socket) do
case Notes.create_note_link(link) do
{:ok, _link} ->
note_id = socket.assigns.note.id
note =
note_id
|> Notes.get_note!()
|> Notes.preload_note()
{:noreply,
socket
|> assign(%{
note: note,
link_changeset: NoteLink.changeset(%NoteLink{}, %{note_id: note_id})
})}
_ ->
{:noreply, socket}
end
end
end