feat: add task liveview
This commit is contained in:
parent
efa5489225
commit
26b33060ee
4 changed files with 271 additions and 25 deletions
65
lib/putzplan_web/live/task_live/show.ex
Normal file
65
lib/putzplan_web/live/task_live/show.ex
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
defmodule PutzplanWeb.TaskLive.Show do
|
||||
use PutzplanWeb, :live_view
|
||||
on_mount {PutzplanWeb.LiveUserAuth, :live_user_required}
|
||||
|
||||
@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
|
||||
Loading…
Add table
Add a link
Reference in a new issue