Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show progress in file input upload #2785

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/livebook_web/live/output/file_input_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule LivebookWeb.Output.FileInputComponent do
~H"""
<form id={"#{@id}-root"} phx-change="validate" phx-target={@myself}>
<label
class="inline-flex flex-col gap-4 p-4 border-2 border-dashed border-gray-200 rounded-lg cursor-pointer"
class="min-w-[50%] inline-flex flex-col gap-4 p-4 border-2 border-dashed border-gray-200 rounded-lg cursor-pointer"
phx-drop-target={@uploads.file.ref}
phx-hook="Dropzone"
id={"#{@id}-upload-dropzone"}
Expand All @@ -56,6 +56,9 @@ defmodule LivebookWeb.Output.FileInputComponent do
<% end %>
</div>
<.live_file_input upload={@uploads.file} class="hidden" accept={@accept} />
<div :for={entry <- @uploads.file.entries} class="delay-200 flex flex-col gap-1">
<.file_entry name="File" entry={entry} on_clear={JS.push("clear_file", target: @myself)} />
</div>
</label>
<p
:for={msg <- LivebookWeb.HTMLHelpers.upload_error_messages(@uploads.file)}
Expand All @@ -72,6 +75,10 @@ defmodule LivebookWeb.Output.FileInputComponent do
{:noreply, socket}
end

def handle_event("clear_file", %{"ref" => ref}, socket) do
{:noreply, cancel_upload(socket, :file, ref)}
end

defp handle_progress(:file, entry, socket) do
if entry.done? do
{file_ref, client_name} =
Expand Down
Loading