Skip to content

Commit

Permalink
fix: dnd loss of selected index
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenColEvol committed Jan 30, 2024
1 parent 34e54de commit 509c267
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ function Preview() {
const handleDrop = (result: any) => {
if (!result.destination) return;
setFormState(form => {
const newSlides = reorder(
const newForm = {
...form
};
const currentlySelectedUID = form.slides[form.selectedIdx].uid;
newForm.slides = reorder(
form.slides,
result.source.index,
result.destination.index
);
return {
...form,
slides: newSlides
};
const afterReorderIdx = newForm.slides.findIndex(slide => slide.uid === currentlySelectedUID);
newForm.selectedIdx = afterReorderIdx;
return newForm;
});
}

Expand Down

0 comments on commit 509c267

Please sign in to comment.