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

Lacking a way to reset upload errors #3401

Open
DaTrader opened this issue Aug 27, 2024 · 2 comments
Open

Lacking a way to reset upload errors #3401

DaTrader opened this issue Aug 27, 2024 · 2 comments

Comments

@DaTrader
Copy link

Environment

  • Phoenix LiveView version (mix deps): 0.20.17

Actual behavior

In my UC uploading a file is just one of the available media sources, others being selecting a giphy or a media url from a proprietary library.

Now, let's consider the following scenario:

  1. The user tries to upload a file
  2. An upload error is returned and presented
  3. The user selects a media from another library and the selected image/video is shown in place of the previous error
  4. The user cancels the selected media
  5. The upload error from step 2 is shown again for nothing has changed there

I've tried circumventing this by "resetting" the allowed uploads by invoking disallow_upload/2 and then calling the allow_upload/3 in the step 3 but the disallow_upload/2 raises the following exception:

[error] GenServer #PID<0.1255.0> terminating
** (RuntimeError) unable to disallow_upload for an upload with active entries
    (phoenix_live_view 0.20.17) lib/phoenix_live_view/upload.ex:65: Phoenix.LiveView.Upload.disallow_upload/2

Expected behavior

I'm aware I could "patch" the above by introducing a flag (assign) in the step no. 3 upon which I will no longer display the upload errors for as long as the flag is there, but wouldn't it be nice to be able to actually reset the uploads instead of doing the workaround?

eg.

disallow_upload( socket, :my_media, force: true)
@DaTrader
Copy link
Author

UPDATE:

Actually, the problem cannot be solved that easily because if I use an assigned flag to ignore the last upload error I also need to reset the flag at some point and it's not obvious when, for the user may as well drag and drop a media to upload it and then I would need to do a flag reset on a subsequent detection of dragover in JS as well as on a click opening the browser's file explorer, all in order to avoid ignoring a new upload error.

Force-resetting the upload(s) would be a far better way of dealing with this issue.

@DaTrader
Copy link
Author

UPDATE 2:

Another reason why the option to force-reset with disallow_upload/2 would be useful is to reset the file types (extensions). In my UC there's a need to do it dynamically because the permitted file type list depends on certain settings the user is permitted to change on the go (within the same LiveComponent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant