bigardone / phoenix-trello

Trello tribute done in Elixir, Phoenix Framework, React and Redux.
https://phoenix-trello.herokuapp.com
MIT License
2.5k stars 409 forks source link

Only change card order if it has changed #31

Closed chrislaskey closed 8 years ago

chrislaskey commented 8 years ago

When working on #30 I noticed an issue when then a card is dragged and dropped back in its original location. This pull request fixes it.

Previously picking up a card and dropping it in the same spot would cause the card to swap positions with the card below it. Now the card stays in its current position and does not dispatch an update event to the phoenix backend.

The logic here is pretty simple - check to see if the targetCard is the same as the card that is currently below the sourceCard. If it is, return early and don't update the position.

The behavior when dragging a card to a different location within the same list, or dragging to another list remains the same.

Definitely open to suggestions for improvement. Was having a hard time coming up with a meaningful variable name.

Thanks again for this project, it's been really fun reading through the code and learning 😃