Skip to content

Commit

Permalink
refactor: refactoring after review
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Jan 9, 2024
1 parent 75f7e1c commit 4590594
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/course-unit/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

export const UNIT_ICON_TYPES = ['video', 'other', 'vertical', 'problem', 'lock'];

export const typeToIconMapping = {
export const TYPE_ICONS_MAP = {
video: VideoCameraIcon,
other: BookOpenIcon,
vertical: FormatListBulletedIcon,
Expand Down
4 changes: 4 additions & 0 deletions src/course-unit/course-sequence/CourseSequence.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
width: 100%;
}

.sequence-load-failure-msg {
max-width: 30em;
}

.sequence-navigation {
.btn {
flex-grow: 1;
Expand Down
4 changes: 2 additions & 2 deletions src/course-unit/course-sequence/Sequence.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import classNames from 'classnames';
import { breakpoints, useWindowSize } from '@edx/paragon';
import { injectIntl, useIntl } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';

import Loading from '../../generic/Loading';
import { RequestStatus } from '../../data/constants';
Expand Down Expand Up @@ -48,7 +48,7 @@ const Sequence = ({

// sequence status 'failed' and any other unexpected sequence status.
return (
<p className="text-center py-5 mx-auto" style={{ maxWidth: '30em' }}>
<p className="sequence-load-failure-msg text-center py-5 mx-auto">
{intl.formatMessage(messages.sequenceLoadFailure)}
</p>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const SequenceNavigation = ({
};

const renderPreviousButton = () => {
const buttonText = intl.formatMessage(messages.prevBtnText);
const disabled = isFirstUnit;
const prevArrow = isRtl(getLocale()) ? ChevronRightIcon : ChevronLeftIcon;

Expand All @@ -59,7 +60,7 @@ const SequenceNavigation = ({
as={disabled ? undefined : Link}
to={disabled ? undefined : previousLink}
>
{shouldDisplayNotificationTriggerInSequence ? null : intl.formatMessage(messages.prevBtnText)}
{shouldDisplayNotificationTriggerInSequence ? null : buttonText}
</Button>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import UnitIcon from './UnitIcon';
const UnitButton = ({
title, contentType, isActive, unitId, className, showTitle,
}) => {
const { courseId, sequenceId } = useSelector(state => state.courseUnit);
const courseId = useSelector(state => state.courseUnit.courseId);
const sequenceId = useSelector(state => state.courseUnit.sequenceId);

return (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import PropTypes from 'prop-types';
import { Icon } from '@edx/paragon';
import { BookOpen as BookOpenIcon } from '@edx/paragon/icons';

import { typeToIconMapping, UNIT_ICON_TYPES } from '../../constants';
import { TYPE_ICONS_MAP, UNIT_ICON_TYPES } from '../../constants';

const UnitIcon = ({ type }) => {
const icon = typeToIconMapping[type] || BookOpenIcon;
const icon = TYPE_ICONS_MAP[type] || BookOpenIcon;

return <Icon src={icon} screenReaderText={type} />;
};
Expand Down
4 changes: 2 additions & 2 deletions src/course-unit/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export async function getCourseSectionVerticalData(unitId) {
* @returns {Promise<Object>} A Promise that resolves to the normalized learning sequences outline data.
*/
export async function getLearningSequencesOutline(courseId) {
const outlineUrl = new URL(getLearningSequencesOutlineApiUrl(courseId));
const { data } = await getAuthenticatedHttpClient().get(outlineUrl.href, {});
const { href } = new URL(getLearningSequencesOutlineApiUrl(courseId));
const { data } = await getAuthenticatedHttpClient().get(href, {});

return normalizeLearningSequencesData(data);
}
Expand Down
25 changes: 17 additions & 8 deletions src/course-unit/data/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createSelector } from '@reduxjs/toolkit';

import { RequestStatus } from '../../data/constants';

export const getCourseUnitData = (state) => state.courseUnit.unit;
Expand All @@ -10,12 +12,19 @@ export const getSequenceStatus = (state) => state.courseUnit.sequenceStatus;

export const getCourseSectionVertical = (state) => state.courseUnit.courseSectionVertical;

export function sequenceIdsSelector(state) {
if (state.courseUnit.courseStatus !== RequestStatus.SUCCESSFUL) {
return [];
}
const { sectionIds = [] } = state.models.coursewareMeta[state.courseDetail.courseId];
export const getCourseStatus = state => state.courseUnit.courseStatus;
export const getCoursewareMeta = state => state.models.coursewareMeta;
export const getSections = state => state.models.sections;
export const getCourseId = state => state.courseDetail.courseId;

export const sequenceIdsSelector = createSelector(
[getCourseStatus, getCoursewareMeta, getSections, getCourseId],
(courseStatus, coursewareMeta, sections, courseId) => {
if (courseStatus !== RequestStatus.SUCCESSFUL) {
return [];
}

return sectionIds
.flatMap(sectionId => state.models.sections[sectionId].sequenceIds);
}
const sectionIds = coursewareMeta[courseId].sectionIds || [];
return sectionIds.flatMap(sectionId => sections[sectionId].sequenceIds);
},
);

0 comments on commit 4590594

Please sign in to comment.