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.
 
 
 
 
 

41 lines
938 B

defmodule MirageWeb.NoteLive.Index do
use MirageWeb, :live_view
alias Mirage.Notes
alias Mirage.Notes.Note
@impl true
def mount(_params, %{"user_id" => user_id}, socket) do
{:ok,
socket
|> assign(:notes, Notes.list_notes())
|> assign(:current_user, Mirage.Accounts.get_user!(user_id))}
end
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
defp apply_action(socket, :edit, %{"id" => id}) do
socket
|> assign(:page_title, "Edit Note")
|> assign(:note, Notes.get_note!(id))
end
defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Note")
|> assign(:note, %Note{})
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:page_title, "Listing Notes")
|> assign(:note, nil)
end
defp list_notes do
Notes.list_notes()
end
end