m-inan / react-upload-gallery

React for Upload Image Gallery. Sorted by drag & drop and Customizable
MIT License
80 stars 44 forks source link

Not possible to use onSortEnd sorting callback #14

Closed IvanAddolorato closed 4 years ago

IvanAddolorato commented 4 years ago

Hello @m-inan

First, I want to thank you for such a great component. It is very flexible and easy to use.

This issue is due the impossibility to use the sorting callback onSortEnd, as it explicitly overriden in the line referenced below:

https://github.com/m-inan/react-upload-gallery/blob/e21bdeb76e68dbedbc0b7e34ae27f520bf2392b0/src/DragArea.js#L19

I think that this can be solved by doing something like:

onSortEnd={(params, e) => { setSort(arrayMove(images, params.oldIndex, params.newIndex)); props.onSortEnd(params, e); }}

What do you think?

Thanks and looking forward for an answer.

Ivan.-

m-inan commented 4 years ago

@IvanAddolorato Do you just want callbacks here or do you need with data ? Like oldIndex, newIndex

IvanAddolorato commented 4 years ago

Thanks for quick reply.

I need the data to make some actions based on it.

m-inan commented 4 years ago

@IvanAddolorato You can use it this way. https://github.com/m-inan/react-upload-gallery/commit/a2090a2855e01bc79ae9fdd5e58043dd5957b663

<Rug
  onSortEnd={(images: any, diff: any) => {
    console.log(images, diff);
  }}
/>

I would be very glad if you can test it on the last commit and return it. Then I can add the feature to the document and send it as a new package.

IvanAddolorato commented 4 years ago

I have just tested it and works perfect.

From my side, this is ready to be packaged and released.

Thanks so much!

m-inan commented 4 years ago

Thanks for the suggestion. You can use the feature with the 0.2.0 version.

IvanAddolorato commented 4 years ago

Great!