unfinish tasks

This commit is contained in:
Matthew Ryan Dillon 2021-01-31 16:35:51 -07:00
parent dc146b85c3
commit a804998c4a
4 changed files with 21 additions and 1 deletions

View file

@ -160,6 +160,12 @@ defmodule Planner.Tasks do
|> Repo.update()
end
def unfinish_task_by_id!(id) do
get_task!(id)
|> Task.unfinish_task()
|> Repo.update()
end
def verify_task_id_from_url(task_id) do
task_id =
case UUID.dump(task_id) do

View file

@ -26,6 +26,10 @@ defmodule Planner.Tasks.Task do
change(task, finished_at: now())
end
def unfinish_task(task) do
change(task, finished_at: nil)
end
def preview(task) do
hd(String.split(task.value, "\n"))
end

View file

@ -86,7 +86,11 @@ defmodule TaskComponent do
phx-value-task-id="<%= @task.id %>">
</button>
<% _ -> %>
!
<span
class="pointer"
phx-click="unfinish-task" phx-value-task-id="<%= @task.id %>">
!
</span>
<% end %>
</div>
<div class="ml-5-5">

View file

@ -194,6 +194,12 @@ defmodule PlannerWeb.TasksLive do
{:noreply, push_patch(socket, to: route)}
end
def handle_event("unfinish-task", %{"task-id" => task_id}, socket) do
{_, _} = Tasks.unfinish_task_by_id!(task_id)
route = get_index_route(socket)
{:noreply, push_patch(socket, to: route)}
end
def handle_event("new-task", %{"task" => task_params}, socket) do
add_new_task(task_params, socket.assigns.active_plan, socket)
end