Skip to content

Commit

Permalink
refactor: corrected scroll to target xblock
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Dec 9, 2024
1 parent 61f957e commit de5d7db
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/course-unit/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const messageTypes = {
videoFullScreen: 'plugin.videoFullScreen',
refreshXBlock: 'refreshXBlock',
showMoveXBlockModal: 'showMoveXBlockModal',
completeXBlockMoving: 'completeXBlockMoving',
rollbackMovedXBlock: 'rollbackMovedXBlock',
showMultipleComponentPicker: 'showMultipleComponentPicker',
addSelectedComponentsToBank: 'addSelectedComponentsToBank',
showXBlockLibraryChangesPreview: 'showXBlockLibraryChangesPreview',
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
},
}));
Expand Down
4 changes: 2 additions & 2 deletions src/course-unit/move-modal/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
},
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/xblock-container-iframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const XBlockContainerIframe: FC<XBlockContainerIframeProps> = ({

const handleScrollToXBlock = (scrollOffset: number) => {
window.scrollBy({
top: scrollOffset + 1000,
top: scrollOffset,
behavior: 'smooth',
});
};
Expand Down

0 comments on commit de5d7db

Please sign in to comment.