Skip to content

Commit

Permalink
feat: add auto scroll to subsection and improve scroll behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 11, 2023
1 parent 8dbc4fe commit 4e30ebf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/course-outline/CourseOutline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const CourseOutline = ({ courseId }) => {
onOpenDeleteModal={openDeleteModal}
onEditSubmit={handleEditSubmit}
onDuplicateSubmit={handleDuplicateSubsectionSubmit}
ref={listRef}
/>
))}
</SectionCard>
Expand Down
8 changes: 4 additions & 4 deletions src/course-outline/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const CHECKLIST_FILTERS = /** @type {const} */ ({
});

export const COURSE_BLOCK_NAMES = /** @type {const} */ ({
chapter: { 'id': 'chapter', 'name': 'Section' },
sequential: { 'id': 'sequential', 'name': 'Subsection' },
vertical: { 'id': 'vertical', 'name': 'Unit' },
})
chapter: { id: 'chapter', name: 'Section' },
sequential: { id: 'sequential', name: 'Subsection' },
vertical: { id: 'vertical', name: 'Unit' },
});

export const LAUNCH_CHECKLIST = /** @type {const} */ ({
data: [
Expand Down
10 changes: 5 additions & 5 deletions src/course-outline/subsection-card/SubsectionCard.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import { forwardRef, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import { useIntl } from '@edx/frontend-platform/i18n';
Expand All @@ -11,7 +11,7 @@ import CardHeader from '../card-header/CardHeader';
import { getItemStatus } from '../utils';
import messages from './messages';

const SubsectionCard = ({
const SubsectionCard = forwardRef(({
section,
subsection,
children,
Expand All @@ -20,7 +20,7 @@ const SubsectionCard = ({
savingStatus,
onOpenDeleteModal,
onDuplicateSubmit,
}) => {
}, lastItemRef) => {
const intl = useIntl();
const dispatch = useDispatch();
const [isExpanded, setIsExpanded] = useState(false);
Expand Down Expand Up @@ -71,7 +71,7 @@ const SubsectionCard = ({
}, [savingStatus]);

return (
<div className="subsection-card" data-testid="subsection-card">
<div className="subsection-card" data-testid="subsection-card" ref={lastItemRef}>
<CardHeader
title={displayName}
status={subsectionStatus}
Expand Down Expand Up @@ -107,7 +107,7 @@ const SubsectionCard = ({
)}
</div>
);
};
});

SubsectionCard.defaultProps = {
children: null,
Expand Down
6 changes: 5 additions & 1 deletion src/course-outline/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ const getHighlightsFormValues = (currentHighlights) => {
};

const scrollToElement = (ref) => {
ref.current?.scrollIntoView({ behavior: 'smooth' });
ref.current?.scrollIntoView({
block: 'end',
inline: 'nearest',
behavior: 'smooth',
});
};

export {
Expand Down

0 comments on commit 4e30ebf

Please sign in to comment.