Skip to content

Commit

Permalink
fix issue with canceled work uploads coming back (#802)
Browse files Browse the repository at this point in the history
Fixes: #416

They needed to be canceled, not just removed from the list.
  • Loading branch information
zkat authored Apr 20, 2024
1 parent 9acd644 commit f3996e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ defmodule BanchanWeb.WorkLive.Components.WorkUploads do

def handle_event("remove_upload", params, socket) do
{idx, ""} = params["idx"] |> Integer.parse()
to_remove = Enum.at(socket.assigns.work_uploads, idx)
new_uploads = List.delete_at(socket.assigns.work_uploads, idx)

notify_changed(new_uploads, socket)

case to_remove do
{:live, entry} ->
notify_canceled(entry.ref, socket)

_ ->
nil
end

{:noreply, socket}
end

Expand All @@ -100,6 +108,14 @@ defmodule BanchanWeb.WorkLive.Components.WorkUploads do
nil
end

defp notify_canceled(_, %{assigns: %{send_updates_to: nil}}) do
nil
end

defp notify_canceled(ref, %{assigns: %{id: id, send_updates_to: pid}}) do
send(pid, {:canceled_upload, id, ref})
end

def render(assigns) do
~F"""
<bc-work-uploads id={@id} class={@class} :hook="SortableHook">
Expand Down
4 changes: 4 additions & 0 deletions lib/banchan_web/live/work_live/work.ex
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ defmodule BanchanWeb.WorkLive.Work do
end
end

def handle_info({:canceled_upload, _, ref}, socket) do
{:noreply, cancel_upload(socket, :uploads, ref)}
end

def handle_info({:updated_uploads, _, uploads}, socket) do
uploads_param =
uploads
Expand Down

0 comments on commit f3996e2

Please sign in to comment.