Skip to content

Commit

Permalink
feat: added added redirect to sequence unit
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Jan 8, 2024
1 parent c668b38 commit 42a7db6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/CourseAuthoringRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CourseUpdates } from './course-updates';
import { CourseUnit } from './course-unit';
import CourseExportPage from './export-page/CourseExportPage';
import CourseImportPage from './import-page/CourseImportPage';
import { DECODE_ROUTES } from './constants';

/**
* As of this writing, these routes are mounted at a path prefixed with the following:
Expand Down Expand Up @@ -69,10 +70,12 @@ const CourseAuthoringRoutes = () => {
path="custom-pages/*"
element={<PageWrap><CustomPages courseId={courseId} /></PageWrap>}
/>
<Route
path="/container/:blockId/:sequenceId"
element={process.env.ENABLE_UNIT_PAGE === 'true' ? <PageWrap><CourseUnit courseId={courseId} /></PageWrap> : null}
/>
{DECODE_ROUTES.COURSE_UNIT.map((path) => (
<Route
path={path}
element={process.env.ENABLE_UNIT_PAGE === 'true' ? <PageWrap><CourseUnit courseId={courseId} /></PageWrap> : null}
/>
))}
<Route
path="editor/course-videos/:blockId"
element={process.env.ENABLE_NEW_EDITOR_PAGES === 'true' ? <PageWrap><VideoSelectorContainer courseId={courseId} /></PageWrap> : null}
Expand Down
7 changes: 7 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ export const COURSE_CREATOR_STATES = {
denied: 'denied',
disallowedForThisSite: 'disallowed_for_this_site',
};

export const DECODE_ROUTES = {
COURSE_UNIT: [
'/container/:blockId/:sequenceId',
'/container/:blockId',
],
};
5 changes: 3 additions & 2 deletions src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import { useCourseUnit } from './hooks';
import messages from './messages';

const CourseUnit = ({ courseId }) => {
const { sequenceId, blockId } = useParams();
const { blockId } = useParams();
const intl = useIntl();
const {
isLoading,
sequenceId,
unitTitle,
savingStatus,
isTitleEditFormOpen,
Expand All @@ -32,7 +33,7 @@ const CourseUnit = ({ courseId }) => {
headerNavigationsActions,
handleTitleEdit,
handleInternetConnectionFailed,
} = useCourseUnit({ courseId, blockId, sequenceId });
} = useCourseUnit({ courseId, blockId });

document.title = getPageHeadTitle('', unitTitle);

Expand Down
16 changes: 13 additions & 3 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useContext, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { AppContext } from '@edx/frontend-platform/react';
import { useNavigate } from 'react-router-dom';

import { RequestStatus } from '../data/constants';
import {
Expand All @@ -15,17 +16,18 @@ import {
import { updateSavingStatus } from './data/slice';
import { getUnitViewLivePath, getUnitPreviewPath } from './utils';

const useCourseUnit = ({ courseId, blockId, sequenceId }) => {
const useCourseUnit = ({ courseId, blockId }) => {
const dispatch = useDispatch();

const { config } = useContext(AppContext);
const courseUnit = useSelector(getCourseUnitData);
const savingStatus = useSelector(getSavingStatus);
const loadingStatus = useSelector(getLoadingStatus);

const navigate = useNavigate();
const [isTitleEditFormOpen, toggleTitleEditForm] = useState(false);

const unitTitle = courseUnit.metadata?.displayName || '';
const sequenceId = courseUnit.ancestorInfo?.ancestors[0].id;

const headerNavigationsActions = {
handleViewLive: () => {
Expand Down Expand Up @@ -53,14 +55,22 @@ const useCourseUnit = ({ courseId, blockId, sequenceId }) => {
handleTitleEdit();
};

const handleNavigate = (id) => {
if (sequenceId) {
navigate(`/course/${courseId}/container/${blockId}/${id}`, { replace: true });
}
};

useEffect(() => {
dispatch(fetchCourseUnitQuery(blockId));
dispatch(fetchCourseSectionVerticalData(blockId));
dispatch(fetchSequence(sequenceId));
dispatch(fetchCourse(courseId));
}, [courseId, blockId]);
handleNavigate(sequenceId);
}, [courseId, blockId, sequenceId]);

return {
sequenceId,
courseUnit,
unitTitle,
isLoading: loadingStatus.fetchUnitLoadingStatus === RequestStatus.IN_PROGRESS,
Expand Down

0 comments on commit 42a7db6

Please sign in to comment.