phoenix_live_view icon indicating copy to clipboard operation
phoenix_live_view copied to clipboard

Lacking a way to reset upload errors

Open DaTrader opened this issue 6 months ago • 2 comments

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 avatar Aug 27 '24 16:08 DaTrader