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

Callback when multiple files added widget in react #326

Open
aquaductape opened this issue Jun 1, 2022 · 4 comments
Open

Callback when multiple files added widget in react #326

aquaductape opened this issue Jun 1, 2022 · 4 comments
Labels

Comments

@aquaductape
Copy link

Question

Similar to this #290, but on onFileSelect only fires after you close dialog. Is there an callback that fires as soon as each file finishes downloading and you can access updated fileInfo?

@aquaductape
Copy link
Author

So it seems like this is the way

onDialogOpen={(dialog) => {
  dialog.fileColl.anyDoneList.add((_, item) => {
    console.log(item); // {uuid, name, size, isStored, isImage, …}
  });
}}

@optlsnd
Copy link

optlsnd commented Jun 2, 2022

@aquaductape yes, anyDoneList will do the trick. You can also use the onAdd and onRemove to handle add/remove events separately

onDialogOpen={(dialog) => {
  dialog.fileColl.onAdd.add((file) => {
    console.log("File added: ", file);
  });
  dialog.fileColl.onRemove.add((file) => {
    console.log("File removed: ", file);
  });
}}

https://codesandbox.io/s/react-widget-react18-onadd-onremove-events-guxf3c?file=/src/index.js:293-554

@aquaductape
Copy link
Author

aquaductape commented Jun 2, 2022

The onAdd and onRemove code is not true, it doesn't return a file, but instead a different object with a lot of methods.

always: ƒ ()
cancel: ƒ ()
catch: ƒ ( fn )
done: ƒ ()
fail: ƒ ()
pipe: ƒ ()
progress: ƒ ()
promise: ƒ ( obj )
state: ƒ ()
then: ƒ ()

I can't find the file on that object, the closest thing i can find relating to the file is the second parameter that's passed but is a number which is the index of the file.

  dialog.fileColl.onAdd.add((obj, fileIndex) => {
    console.log("File added: ", fileIndex);
  });
  dialog.fileColl.onRemove.add((obj, fileIndex) => {
    console.log("File removed: ", fileIndex);
  });

@aquaductape
Copy link
Author

Ok you have to call the promise method

onDialogOpen={(dialog) => {
  dialog.fileColl.onAdd.add(async (state) => {
    const file = await state.promise()
    console.log("File added: ", file);
  });
  dialog.fileColl.onRemove.add(async (state) => {
    const file = await state.promise()
    console.log("File removed: ", file);
  });
}}

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

No branches or pull requests

2 participants