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

files array passed to onStatusChange is updated after handler is fired for 'removed' #126

Open
fridaystreet opened this issue Sep 18, 2020 · 0 comments

Comments

@fridaystreet
Copy link

fridaystreet commented Sep 18, 2020

Thanks for the great library. Just been trying to put an overlay type dropzone together that appears over the top of a form on drag. In order to do this I needed to control the display of the dropzone component with some state change. All good there so far.

I'm listening to the drag enter, drag leave events on the form so as to swicth dropzone on and off. That all works fine if I haven't dropped any files in the zone. Once I do this, the drag leave is never fired (to be expected).

What I wanted to do was listen to the 'removed' event and if there are no files left, then I'll trigger my state change to hide the dropzone and display the form again.

The trouble is that when onStateChanged is fired for the remove event, it is done, before the file is removed from the files array. Sort of feels like if the event is 'removed' then the files array passed to onStatusChange should reflect the files without the last removed element.

see here this.files.splice(index, 1) is called after this.handleChangeStatus(fileWithMeta).

  handleRemove = (fileWithMeta: IFileWithMeta) => {
    const index = this.files.findIndex(f => f === fileWithMeta)
    if (index !== -1) {
      URL.revokeObjectURL(fileWithMeta.meta.previewUrl || '')
      fileWithMeta.meta.status = 'removed'
      this.handleChangeStatus(fileWithMeta)
      this.files.splice(index, 1)
      this.forceUpdate()
    }
  }

Is there a particular design reason why it's not removed first? If not I'm happy to submit a PR if you are happy to take one?

Cheers
Paul

@fridaystreet fridaystreet changed the title array of files passed to onStatusChange is updated after handler is fired for 'removed' files array passed to onStatusChange is updated after handler is fired for 'removed' Sep 18, 2020
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