From de5d7db95e905ed48ca06e45ecf0391a2b733cef Mon Sep 17 00:00:00 2001 From: Peter Kulko Date: Mon, 9 Dec 2024 08:39:10 +0200 Subject: [PATCH] refactor: corrected scroll to target xblock --- src/course-unit/constants.js | 2 ++ src/course-unit/data/thunk.js | 2 +- src/course-unit/hooks.jsx | 2 +- src/course-unit/move-modal/hooks.tsx | 4 ++-- src/course-unit/xblock-container-iframe/index.tsx | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/course-unit/constants.js b/src/course-unit/constants.js index 91d0432919..b260d289fa 100644 --- a/src/course-unit/constants.js +++ b/src/course-unit/constants.js @@ -52,6 +52,8 @@ export const messageTypes = { videoFullScreen: 'plugin.videoFullScreen', refreshXBlock: 'refreshXBlock', showMoveXBlockModal: 'showMoveXBlockModal', + completeXBlockMoving: 'completeXBlockMoving', + rollbackMovedXBlock: 'rollbackMovedXBlock', showMultipleComponentPicker: 'showMultipleComponentPicker', addSelectedComponentsToBank: 'addSelectedComponentsToBank', showXBlockLibraryChangesPreview: 'showXBlockLibraryChangesPreview', diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js index 403795800d..d7dda6133f 100644 --- a/src/course-unit/data/thunk.js +++ b/src/course-unit/data/thunk.js @@ -308,7 +308,7 @@ export function patchUnitItemQuery({ dispatch(updateCourseOutlineInfoLoadingStatus({ status: RequestStatus.IN_PROGRESS })); const courseUnit = await getCourseUnitData(currentParentLocator); dispatch(fetchCourseItemSuccess(courseUnit)); - callbackFn(); + callbackFn(sourceLocator); } catch (error) { handleResponseErrors(error, dispatch, updateSavingStatus); } finally { diff --git a/src/course-unit/hooks.jsx b/src/course-unit/hooks.jsx index 1af03d71b8..7fb8edaffa 100644 --- a/src/course-unit/hooks.jsx +++ b/src/course-unit/hooks.jsx @@ -150,7 +150,7 @@ export const useCourseUnit = ({ courseId, blockId }) => { currentParentLocator, isMoving: false, callbackFn: () => { - sendMessageToIframe(messageTypes.refreshXBlock, null); + sendMessageToIframe(messageTypes.rollbackMovedXBlock, { locator: sourceLocator }); window.scrollTo({ top: 0, behavior: 'smooth' }); }, })); diff --git a/src/course-unit/move-modal/hooks.tsx b/src/course-unit/move-modal/hooks.tsx index 69ad13470c..d21014e3bb 100644 --- a/src/course-unit/move-modal/hooks.tsx +++ b/src/course-unit/move-modal/hooks.tsx @@ -184,8 +184,8 @@ export const useMoveModal = ({ title: state.sourceXBlockInfo.current.displayName, currentParentLocator: blockId, isMoving: true, - callbackFn: () => { - sendMessageToIframe(messageTypes.refreshXBlock, null); + callbackFn: (sourceLocator: string) => { + sendMessageToIframe(messageTypes.completeXBlockMoving, { locator: sourceLocator }); closeModal(); window.scrollTo({ top: 0, behavior: 'smooth' }); }, diff --git a/src/course-unit/xblock-container-iframe/index.tsx b/src/course-unit/xblock-container-iframe/index.tsx index 7834a51df6..0bad117b56 100644 --- a/src/course-unit/xblock-container-iframe/index.tsx +++ b/src/course-unit/xblock-container-iframe/index.tsx @@ -91,7 +91,7 @@ const XBlockContainerIframe: FC = ({ const handleScrollToXBlock = (scrollOffset: number) => { window.scrollBy({ - top: scrollOffset + 1000, + top: scrollOffset, behavior: 'smooth', }); };