defmodule PutzplanWeb.TaskLive.Show do require Ash.Query use PutzplanWeb, :live_view @impl true def render(assigns) do ~H""" <.header> Task <%= @task.description %> <:actions> <.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}> <.button>Edit task <.table id="completed_tasks" rows={@streams.completed_tasks} > <:col :let={{_id, completed_task}} label="Completed by"><%= completed_task.users.name %> <:col :let={{_id, completed_task}} label="Date"><%= completed_task.completion %> <.back navigate={~p"/tasks"}>Back to tasks <.modal :if={@live_action == :edit} id="task-modal" show on_cancel={JS.patch(~p"/tasks/#{@task}")}> <.live_component module={PutzplanWeb.TaskLive.FormComponent} id={@task.id} title={@page_title} action={@live_action} current_user={@current_user} task={@task} patch={~p"/tasks/#{@task}"} /> """ end @impl true def mount(_params, _session, socket) do {:ok, socket} end @impl true def handle_params(%{"id" => id}, _, socket) do task = Ash.get!(Putzplan.Tasks.Task, id, actor: socket.assigns.current_user) {:noreply, socket |> assign(:page_title, page_title(socket.assigns.live_action)) |> assign(:task, task) |> stream( :completed_tasks, Putzplan.Tasks.CompletedTask |> Ash.Query.filter(task_id == ^task.id) |> Ash.read!(actor: socket.assigns[:current_user]) )} end defp page_title(:show), do: "Show Task" defp page_title(:edit), do: "Edit Task" end