From 3eae62dada0cad9bd1f2d9acf82217ded2b6bc16 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Tue, 9 Jan 2024 01:04:44 +0200 Subject: [PATCH] fix: replacing LMS endpoints with CMS endpoints --- src/course-unit/course-sequence/Sequence.jsx | 4 + src/course-unit/course-sequence/hooks.js | 18 ++-- .../SequenceNavigation.jsx | 8 +- .../SequenceNavigationTabs.jsx | 5 +- .../sequence-navigation/UnitButton.jsx | 4 +- src/course-unit/data/api.js | 8 +- src/course-unit/data/selectors.js | 1 + src/course-unit/data/thunk.js | 100 ++++++++++-------- src/course-unit/data/utils.js | 23 ++++ src/course-unit/hooks.jsx | 6 +- 10 files changed, 115 insertions(+), 62 deletions(-) diff --git a/src/course-unit/course-sequence/Sequence.jsx b/src/course-unit/course-sequence/Sequence.jsx index 1f90096f1c..f94ff8639f 100644 --- a/src/course-unit/course-sequence/Sequence.jsx +++ b/src/course-unit/course-sequence/Sequence.jsx @@ -17,6 +17,8 @@ const Sequence = ({ const intl = useIntl(); const { IN_PROGRESS, FAILED, SUCCESSFUL } = RequestStatus; const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth; + const STORE = useSelector(state => state); + console.log('STORE', STORE); const { sequenceStatus, sequenceMightBeUnit } = useSelector(state => state.courseUnit); const defaultContent = ( @@ -31,6 +33,8 @@ const Sequence = ({ ); + console.log('sequenceStatus =============', sequenceStatus); + // If sequence might be a unit, we want to keep showing a spinner - the courseware container will redirect us when // it knows which sequence to actually go to. const loading = sequenceStatus === IN_PROGRESS || (sequenceStatus === FAILED && sequenceMightBeUnit); diff --git a/src/course-unit/course-sequence/hooks.js b/src/course-unit/course-sequence/hooks.js index 0dc3c303e2..5e48c18b93 100644 --- a/src/course-unit/course-sequence/hooks.js +++ b/src/course-unit/course-sequence/hooks.js @@ -4,18 +4,24 @@ import { useWindowSize } from '@edx/paragon'; import { useModel } from '../../generic/model-store'; import { RequestStatus } from '../../data/constants'; -import { getCourseSectionVertical, getSequenceStatus, sequenceIdsSelector } from '../data/selectors'; +import { + getCourseSectionVertical, + getCourseSectionVerticalLoadingStatus, + getSequenceStatus, + sequenceIdsSelector +} from '../data/selectors'; export function useSequenceNavigationMetadata(currentSequenceId, currentUnitId) { const { SUCCESSFUL } = RequestStatus; const sequenceIds = useSelector(sequenceIdsSelector); - const sequenceStatus = useSelector(getSequenceStatus); + const { courseSectionVerticalLoadingStatus } = useSelector(getCourseSectionVerticalLoadingStatus); + const sequenceStatus = courseSectionVerticalLoadingStatus; const { nextUrl, prevUrl } = useSelector(getCourseSectionVertical); const sequence = useModel('sequences', currentSequenceId); const { courseId, status } = useSelector(state => state.courseDetail); - + // console.log('sequence >>>', sequence); const isCourseOrSequenceNotSuccessful = status !== SUCCESSFUL || sequenceStatus !== SUCCESSFUL; - const areIdsNotValid = !currentSequenceId || !currentUnitId || !sequence.unitIds; + const areIdsNotValid = !currentSequenceId || !currentUnitId || !sequence?.unitIds; const isNotSuccessfulCompletion = isCourseOrSequenceNotSuccessful || areIdsNotValid; // If we don't know the sequence and unit yet, then assume no. @@ -24,13 +30,13 @@ export function useSequenceNavigationMetadata(currentSequenceId, currentUnitId) } const sequenceIndex = sequenceIds.indexOf(currentSequenceId); - const unitIndex = sequence.unitIds.indexOf(currentUnitId); + const unitIndex = sequence?.unitIds.indexOf(currentUnitId); const isFirstSequence = sequenceIndex === 0; const isFirstUnitInSequence = unitIndex === 0; const isFirstUnit = isFirstSequence && isFirstUnitInSequence; const isLastSequence = sequenceIndex === sequenceIds.length - 1; - const isLastUnitInSequence = unitIndex === sequence.unitIds.length - 1; + const isLastUnitInSequence = unitIndex === sequence?.unitIds.length - 1; const isLastUnit = isLastSequence && isLastUnitInSequence; const nextSequenceId = sequenceIndex < sequenceIds.length - 1 ? sequenceIds[sequenceIndex + 1] : null; diff --git a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx index 189d7786d4..5f92dd916e 100644 --- a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx +++ b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigation.jsx @@ -16,6 +16,7 @@ import { RequestStatus } from '../../../data/constants'; import messages from '../messages'; import { useSequenceNavigationMetadata } from '../hooks'; import SequenceNavigationTabs from './SequenceNavigationTabs'; +import { getCourseSectionVertical } from '../../data/selectors'; const SequenceNavigation = ({ intl, @@ -24,14 +25,15 @@ const SequenceNavigation = ({ className, }) => { const { sequenceStatus } = useSelector(state => state.courseUnit); + const MODELS = useSelector(state => state.models); const { isFirstUnit, isLastUnit, nextLink, previousLink, } = useSequenceNavigationMetadata(sequenceId, unitId); const sequence = useModel('sequences', sequenceId); - const shouldDisplayNotificationTriggerInSequence = useWindowSize().width < breakpoints.small.minWidth; + console.log('MODELS >>>', MODELS); const renderUnitButtons = () => { - if (sequence.unitIds?.length === 0 || unitId === null) { + if (sequence?.unitIds?.length === 0 || unitId === null) { return (
); @@ -39,7 +41,7 @@ const SequenceNavigation = ({ return ( ); diff --git a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx index 822474f6bf..1c72c4facc 100644 --- a/src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx +++ b/src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx @@ -8,16 +8,19 @@ import { useIndexOfLastVisibleChild } from '../hooks'; import messages from '../messages'; import SequenceNavigationDropdown from './SequenceNavigationDropdown'; import UnitButton from './UnitButton'; +import { useSelector } from 'react-redux'; const SequenceNavigationTabs = ({ unitIds, unitId }) => { const intl = useIntl(); + + // const { courseId } = useSelector(state => state.courseDetails); const [ indexOfLastVisibleChild, containerRef, invisibleStyle, ] = useIndexOfLastVisibleChild(); const shouldDisplayDropdown = indexOfLastVisibleChild === -1; - + // console.log('courseId', courseId); return (
diff --git a/src/course-unit/course-sequence/sequence-navigation/UnitButton.jsx b/src/course-unit/course-sequence/sequence-navigation/UnitButton.jsx index 1e86fcc5b3..038abc971e 100644 --- a/src/course-unit/course-sequence/sequence-navigation/UnitButton.jsx +++ b/src/course-unit/course-sequence/sequence-navigation/UnitButton.jsx @@ -8,8 +8,8 @@ import UnitIcon from './UnitIcon'; const UnitButton = ({ title, contentType, isActive, unitId, className, showTitle, }) => { - const { courseId, sequenceId } = useSelector(state => state.courseUnit); - + const { sequenceId } = useSelector(state => state.courseUnit); + const { courseId } = useSelector(state => state.courseDetail); return (