80 lines
2.1 KiB
Elixir
80 lines
2.1 KiB
Elixir
defmodule PutzplanWeb.CompletedTaskLive.Index do
|
|
use PutzplanWeb, :live_view
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<.header>
|
|
Listing Completed tasks
|
|
<:actions>
|
|
<.link patch={~p"/completed_tasks/new"}>
|
|
<.button>New Completed task</.button>
|
|
</.link>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<.table
|
|
id="completed_tasks"
|
|
rows={@streams.completed_tasks}
|
|
row_click={fn {_id, completed_task} -> JS.navigate(~p"/completed_tasks/#{completed_task}") end}
|
|
>
|
|
<:col :let={{_id, completed_task}} label="Id">{completed_task.id}</:col>
|
|
|
|
<:action :let={{_id, completed_task}}>
|
|
<div class="sr-only">
|
|
<.link navigate={~p"/completed_tasks/#{completed_task}"}>Show</.link>
|
|
</div>
|
|
</:action>
|
|
</.table>
|
|
|
|
<.modal
|
|
:if={@live_action == :new}
|
|
id="completed_task-modal"
|
|
show
|
|
on_cancel={JS.patch(~p"/completed_tasks")}
|
|
>
|
|
<.live_component
|
|
module={PutzplanWeb.CompletedTaskLive.FormComponent}
|
|
current_user={@current_user}
|
|
id={:new}
|
|
title={@page_title}
|
|
action={@live_action}
|
|
completed_task={@completed_task}
|
|
patch={~p"/completed_tasks"}
|
|
/>
|
|
</.modal>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
{:ok,
|
|
socket
|
|
|> stream(
|
|
:completed_tasks,
|
|
Ash.read!(Putzplan.Tasks.CompletedTask, actor: socket.assigns[:current_user])
|
|
)
|
|
|> assign_new(:current_user, fn -> nil end)}
|
|
end
|
|
|
|
@impl true
|
|
def handle_params(params, _url, socket) do
|
|
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
|
end
|
|
|
|
defp apply_action(socket, :new, _params) do
|
|
socket
|
|
|> assign(:page_title, "New Completed task")
|
|
end
|
|
|
|
defp apply_action(socket, :index, _params) do
|
|
socket
|
|
|> assign(:page_title, "Listing Completed tasks")
|
|
|> assign(:completed_task, nil)
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({PutzplanWeb.CompletedTaskLive.FormComponent, {:saved, completed_task}}, socket) do
|
|
{:noreply, stream_insert(socket, :completed_tasks, completed_task)}
|
|
end
|
|
end
|