Skip to content

Commit

Permalink
Fixed selecting next task in list after completing the current one
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Dec 22, 2023
1 parent 2465c8e commit 88a2bdc
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions core/systems/assignment/crew_work_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> assign(selected_item_id: nil)
end

defp update_selected_item_id(%{assigns: %{work_items: [{%{id: id}, _}]}} = socket) do
socket |> assign(selected_item_id: id)
end

defp update_selected_item_id(%{assigns: %{work_items: work_items}} = socket) do
{%{id: selected_item_id}, _} =
Enum.find(work_items, List.first(work_items), fn {_, %{status: status}} ->
Expand Down Expand Up @@ -343,20 +339,28 @@ defmodule Systems.Assignment.CrewWorkView do
socket |> Frameworks.Pixel.Flash.put_error("Unsupported event")
end

defp handle_complete_task(
%{
assigns: %{
selected_item: {_, task}
}
} = socket
) do
Crew.Public.activate_task(task)
defp handle_complete_task(%{assigns: %{selected_item: {_, task}}} = socket) do
{:ok, %{crew_task: updated_task}} = Crew.Public.activate_task(task)

socket
|> update_task(updated_task)
|> reset_selection()
|> handle_finished_state()
end

defp update_task(%{assigns: %{work_items: work_items}} = socket, updated_task) do
work_items =
Enum.map(work_items, fn {item, task} ->
if task.id == updated_task.id do
{item, updated_task}
else
{item, task}
end
end)

assign(socket, work_items: work_items)
end

defp reset_selection(%{assigns: %{work_items: work_items}} = socket)
when length(work_items) <= 1 do
socket
Expand Down

0 comments on commit 88a2bdc

Please sign in to comment.