Skip to content

Commit

Permalink
fix: finalize section order on drop instead of hover
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored and steff456 committed Dec 7, 2023
1 parent ad50b9a commit 4bb85ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/course-outline/CourseOutline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ const CourseOutline = ({ courseId }) => {
[hoverIndex, 0, prevSections[dragIndex]],
],
});
const idList = [];
for (let i = 0; i < newList.length; i++) {
idList.push(newList[i].id);
}
handleDragNDrop(idList);
return newList;
});
}, []);

const finalizeSectionOrder = () => {
handleDragNDrop(sections.map((section) => section.id));
}

Check failure on line 102 in src/course-outline/CourseOutline.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon

useEffect(() => {
if (sectionsList) {
setSections(sectionsList);
Expand Down Expand Up @@ -182,6 +181,7 @@ const CourseOutline = ({ courseId }) => {
onDuplicateSubmit={handleDuplicateSectionSubmit}
isSectionsExpanded={isSectionsExpanded}
moveSection={moveSection}
finalizeSectionOrder={finalizeSectionOrder}
/>
))}
</DndProvider>
Expand Down
5 changes: 5 additions & 0 deletions src/course-outline/section-card/SectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SectionCard = ({
onDuplicateSubmit,
isSectionsExpanded,
moveSection,
finalizeSectionOrder,
}) => {
const intl = useIntl();
const dispatch = useDispatch();
Expand Down Expand Up @@ -101,6 +102,9 @@ const SectionCard = ({
collect: (monitor) => ({
isDragging: monitor.isDragging(),
}),
end: () => {
finalizeSectionOrder();
},
});
const opacity = isDragging ? 0 : 1;
drag(drop(moveRef));
Expand Down Expand Up @@ -224,6 +228,7 @@ SectionCard.propTypes = {
onDuplicateSubmit: PropTypes.func.isRequired,
isSectionsExpanded: PropTypes.bool.isRequired,
moveSection: PropTypes.func.isRequired,
finalizeSectionOrder: PropTypes.func.isRequired,
};

export default SectionCard;

0 comments on commit 4bb85ca

Please sign in to comment.