64 lines
1.5 KiB
Elixir
64 lines
1.5 KiB
Elixir
defmodule PutzplanWeb.TaskLive.Show do
|
|
use PutzplanWeb, :live_view
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<.header>
|
|
Task <%= @task.id %>
|
|
<:subtitle>This is a task record from your database.</:subtitle>
|
|
|
|
<:actions>
|
|
<.link patch={~p"/tasks/#{@task}/show/edit"} phx-click={JS.push_focus()}>
|
|
<.button>Edit task</.button>
|
|
</.link>
|
|
</:actions>
|
|
|
|
</.header>
|
|
|
|
<.list>
|
|
|
|
<:item title="Id"><%= @task.id %></:item>
|
|
|
|
<:item title="Description"><%= @task.description %></:item>
|
|
|
|
<:item title="Repetition days"><%= @task.repetition_days %></:item>
|
|
|
|
</.list>
|
|
|
|
<.back navigate={~p"/tasks"}>Back to tasks</.back>
|
|
|
|
|
|
<.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}"}
|
|
/>
|
|
</.modal>
|
|
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
{:ok, socket}
|
|
end
|
|
|
|
@impl true
|
|
def handle_params(%{"id" => id}, _, socket) do
|
|
{:noreply,
|
|
socket
|
|
|> assign(:page_title, page_title(socket.assigns.live_action))
|
|
|> assign(:task, Ash.get!(Putzplan.Tasks.Task, id, actor: socket.assigns.current_user))}
|
|
end
|
|
|
|
defp page_title(:show), do: "Show Task"
|
|
defp page_title(:edit), do: "Edit Task"
|
|
end
|