@selfcommunity/react-templates 0.4.5-courses.180 → 0.4.5-courses.182

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,11 @@ export interface LessonProps {
32
32
  * @default false
33
33
  */
34
34
  editMode?: boolean;
35
+ /**
36
+ * Renders preview mode
37
+ * @default false
38
+ */
39
+ previewMode?: boolean;
35
40
  /**
36
41
  * Callback fired on edit mode close
37
42
  * @default null
@@ -20,6 +20,7 @@ const classes = {
20
20
  containerRoot: `${constants_1.PREFIX}-container-root`,
21
21
  navigation: `${constants_1.PREFIX}-navigation`,
22
22
  navigationTitle: `${constants_1.PREFIX}-navigation-title`,
23
+ previewInfo: `${constants_1.PREFIX}-preview-info`,
23
24
  button: `${constants_1.PREFIX}-button`
24
25
  };
25
26
  const Root = (0, styles_1.styled)(material_1.Box, {
@@ -33,6 +34,14 @@ const Container = (0, styles_1.styled)(material_1.Box, {
33
34
  overridesResolver: (props, styles) => styles.containerRoot,
34
35
  shouldForwardProp: (prop) => prop !== 'open'
35
36
  })(() => ({}));
37
+ function getUrlLesson(course, lesson) {
38
+ return {
39
+ id: course.id,
40
+ slug: course.slug,
41
+ section_id: lesson.section_id,
42
+ lesson_id: lesson.id
43
+ };
44
+ }
36
45
  function Lesson(inProps) {
37
46
  var _a, _b, _c;
38
47
  // PROPS
@@ -40,15 +49,19 @@ function Lesson(inProps) {
40
49
  props: inProps,
41
50
  name: constants_1.PREFIX
42
51
  });
43
- const { className = null, courseId, sectionId, lessonId, LessonAppbarProps = {}, LessonDrawerProps = {}, editMode = false, onEditModeClose = null, onLessonChange = null, onActivePanelChange = null } = props, rest = tslib_1.__rest(props, ["className", "courseId", "sectionId", "lessonId", "LessonAppbarProps", "LessonDrawerProps", "editMode", "onEditModeClose", "onLessonChange", "onActivePanelChange"]);
52
+ const { className = null, courseId, sectionId, lessonId, LessonAppbarProps = {}, LessonDrawerProps = {}, editMode = false, previewMode = false, onEditModeClose = null, onLessonChange = null, onActivePanelChange = null } = props, rest = tslib_1.__rest(props, ["className", "courseId", "sectionId", "lessonId", "LessonAppbarProps", "LessonDrawerProps", "editMode", "previewMode", "onEditModeClose", "onLessonChange", "onActivePanelChange"]);
44
53
  // HOOKS
45
54
  const theme = (0, material_1.useTheme)();
46
55
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
47
56
  const [_lessonId, setLessonId] = (0, react_1.useState)(lessonId);
48
57
  const [_sectionId, setSectionId] = (0, react_1.useState)(sectionId);
49
58
  const { scLesson, setSCLesson } = (0, react_core_1.useSCFetchLesson)({ id: _lessonId, courseId, sectionId: _sectionId });
50
- const { scCourse, setSCCourse } = (0, react_core_1.useSCFetchCourse)({ id: courseId, params: { view: editMode ? api_services_1.CourseInfoViewType.EDIT : api_services_1.CourseInfoViewType.USER } });
59
+ const { scCourse, setSCCourse } = (0, react_core_1.useSCFetchCourse)({
60
+ id: courseId,
61
+ params: { view: editMode || previewMode ? api_services_1.CourseInfoViewType.EDIT : api_services_1.CourseInfoViewType.USER }
62
+ });
51
63
  const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
64
+ const scRoutingContext = (0, react_core_1.useSCRouting)();
52
65
  // STATE
53
66
  const [activePanel, setActivePanel] = (0, react_1.useState)(null);
54
67
  const [settings, setSettings] = (0, react_1.useState)(null);
@@ -60,11 +73,10 @@ function Lesson(inProps) {
60
73
  const availableLessons = (0, react_1.useMemo)(() => {
61
74
  if (!(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections))
62
75
  return [];
63
- return scCourse.sections.flatMap((section) => section.lessons.map((lesson) => (Object.assign(Object.assign({}, lesson), { section }))));
76
+ return scCourse.sections.flatMap((section) => section.lessons.filter((lesson) => !lesson.locked).map((lesson) => (Object.assign(Object.assign({}, lesson), { section }))));
64
77
  }, [scCourse]);
65
78
  const [currentLessonIndex, setCurrentLessonIndex] = (0, react_1.useState)(availableLessons.findIndex((lesson) => lesson.id === lessonId));
66
- const [currentSection, setCurrentSection] = (0, react_1.useState)(((_b = availableLessons[currentLessonIndex]) === null || _b === void 0 ? void 0 : _b.section) || null);
67
- const isPrevDisabled = availableLessons.length === 0 || currentLessonIndex <= 0;
79
+ const isPrevDisabled = availableLessons.length === 0 || currentLessonIndex <= 0 || ((_b = availableLessons[currentLessonIndex - 1]) === null || _b === void 0 ? void 0 : _b.locked);
68
80
  const isNextDisabled = availableLessons.length === 0 || currentLessonIndex >= availableLessons.length - 1 || ((_c = availableLessons[currentLessonIndex + 1]) === null || _c === void 0 ? void 0 : _c.locked);
69
81
  const [openDialog, setOpenDialog] = (0, react_1.useState)(false);
70
82
  const isCourseAdmin = (0, react_1.useMemo)(() => scCourse && scCourse.join_status === types_1.SCCourseJoinStatusType.CREATOR, [scCourse]);
@@ -73,12 +85,6 @@ function Lesson(inProps) {
73
85
  const index = availableLessons.findIndex((lesson) => lesson.id === lessonId);
74
86
  setCurrentLessonIndex(index);
75
87
  }, [lessonId, availableLessons]);
76
- (0, react_1.useEffect)(() => {
77
- var _a;
78
- if (availableLessons.length > 0 && currentLessonIndex >= 0) {
79
- setCurrentSection(((_a = availableLessons[currentLessonIndex]) === null || _a === void 0 ? void 0 : _a.section) || null);
80
- }
81
- }, [currentLessonIndex, availableLessons]);
82
88
  (0, react_1.useEffect)(() => {
83
89
  if (scLesson) {
84
90
  setCompleted(scLesson.completion_status === types_1.SCCourseLessonCompletionStatusType.COMPLETED);
@@ -110,7 +116,6 @@ function Lesson(inProps) {
110
116
  const handleChangeLesson = (l, s) => {
111
117
  setLessonId(l.id);
112
118
  setSectionId(s.id);
113
- setCurrentSection(s);
114
119
  onLessonChange && onLessonChange(l.id, s.id);
115
120
  };
116
121
  /**
@@ -147,7 +152,6 @@ function Lesson(inProps) {
147
152
  const newLessonIndex = currentLessonIndex - 1;
148
153
  const newLesson = availableLessons[newLessonIndex];
149
154
  setCurrentLessonIndex(newLessonIndex);
150
- setCurrentSection(newLesson.section);
151
155
  handleChangeLesson(newLesson, newLesson.section);
152
156
  };
153
157
  /**
@@ -159,7 +163,6 @@ function Lesson(inProps) {
159
163
  const newLessonIndex = currentLessonIndex + 1;
160
164
  const newLesson = availableLessons[newLessonIndex];
161
165
  setCurrentLessonIndex(newLessonIndex);
162
- setCurrentSection(newLesson.section);
163
166
  handleChangeLesson(newLesson, newLesson.section);
164
167
  };
165
168
  /**
@@ -198,6 +201,9 @@ function Lesson(inProps) {
198
201
  if (!scLesson || !scCourse) {
199
202
  return (0, jsx_runtime_1.jsx)(react_ui_1.HiddenPlaceholder, {});
200
203
  }
201
- return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.LessonAppbar, Object.assign({ showComments: scLesson.comments_enabled, editMode: editMode, activePanel: activePanel, title: scCourse.name, handleOpen: handleOpenDrawer, onSave: handleLessonUpdate, updating: updating }, LessonAppbarProps)), (0, jsx_runtime_1.jsxs)(Container, Object.assign({ open: Boolean(activePanel) || editMode, className: classes.containerRoot }, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.navigation }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", color: "text.secondary" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.number", defaultMessage: "templates.lesson.number", values: { from: currentLessonIndex + 1, to: availableLessons.length } }) })) })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.navigationTitle }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5" }, { children: scLesson.name })), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handlePrev, disabled: isPrevDisabled }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_back" }) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleNext, disabled: isNextDisabled }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_next" }) }))] })] })), (0, jsx_runtime_1.jsx)(react_ui_1.LessonObject, { course: scCourse, lesson: scLesson, editMode: editMode, onContentChange: handleLessonContentEdit, onMediaChange: handleLessonMediaEdit }), !isCourseAdmin && !editMode && ((0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ className: classes.button, loading: loading, size: "small", variant: completed ? 'outlined' : 'contained', startIcon: !completed && (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_next" }), endIcon: completed && (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "circle_checked" }), onClick: toggleLessonCompletion }, { children: completed ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.button.completed", defaultMessage: "templates.lesson.button.completed" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.button.complete", defaultMessage: "templates.lesson.button.complete" })) })))] })), (0, jsx_runtime_1.jsx)(react_ui_1.LessonDrawer, Object.assign({ course: scCourse, lesson: scLesson, editMode: isMobile ? activePanel === react_ui_1.SCLessonActionsType.SETTINGS : editMode, activePanel: activePanel, handleClose: handleCloseDrawer, handleChangeLesson: handleChangeLesson, LessonEditFormProps: { lesson: scLesson, onSave: handleLessonUpdate, updating: updating, onSettingsChange: handleSettingsChange } }, LessonDrawerProps))] })), openDialog && (0, jsx_runtime_1.jsx)(react_ui_1.CourseCompletedDialog, { course: scCourse, onClose: handleCloseDialog })] }));
204
+ return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.LessonAppbar, Object.assign({ showComments: scLesson.comments_enabled, editMode: editMode, activePanel: activePanel, title: scCourse.name, handleOpen: handleOpenDrawer, onSave: handleLessonUpdate, updating: updating }, LessonAppbarProps)), (0, jsx_runtime_1.jsxs)(Container, Object.assign({ open: Boolean(activePanel) || editMode, className: classes.containerRoot }, { children: [previewMode && ((0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ severity: "info", className: classes.previewInfo }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body1" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.previewMode", defaultMessage: "templates.lesson.previewMode", values: {
205
+ link: (...chunks) => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.COURSE_LESSON_EDIT_ROUTE_NAME, getUrlLesson(scCourse, scLesson)) }, { children: chunks }))),
206
+ linkBack: (...chunks) => (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.COURSE_DASHBOARD_ROUTE_NAME, scCourse) }, { children: chunks }))
207
+ } }) })) }))), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.navigation }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", color: "text.secondary" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.number", defaultMessage: "templates.lesson.number", values: { from: currentLessonIndex + 1, to: availableLessons.length } }) })) })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.navigationTitle }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5" }, { children: scLesson.name })), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handlePrev, disabled: isPrevDisabled }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_back" }) })), (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: handleNext, disabled: isNextDisabled }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_next" }) }))] })] })), (0, jsx_runtime_1.jsx)(react_ui_1.LessonObject, { course: scCourse, lesson: scLesson, editMode: editMode, onContentChange: handleLessonContentEdit, onMediaChange: handleLessonMediaEdit }), !isCourseAdmin && !editMode && !previewMode && ((0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ className: classes.button, loading: loading, size: "small", variant: completed ? 'outlined' : 'contained', startIcon: !completed && (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "arrow_next" }), endIcon: completed && (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "circle_checked" }), onClick: toggleLessonCompletion }, { children: completed ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.button.completed", defaultMessage: "templates.lesson.button.completed" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.lesson.button.complete", defaultMessage: "templates.lesson.button.complete" })) })))] })), (0, jsx_runtime_1.jsx)(react_ui_1.LessonDrawer, Object.assign({ course: scCourse, lesson: scLesson, editMode: isMobile ? activePanel === react_ui_1.SCLessonActionsType.SETTINGS : editMode, previewMode: previewMode, activePanel: activePanel, handleClose: handleCloseDrawer, handleChangeLesson: handleChangeLesson, LessonEditFormProps: { lesson: scLesson, onSave: handleLessonUpdate, updating: updating, onSettingsChange: handleSettingsChange } }, LessonDrawerProps))] })), openDialog && (0, jsx_runtime_1.jsx)(react_ui_1.CourseCompletedDialog, { course: scCourse, onClose: handleCloseDialog })] }));
202
208
  }
203
209
  exports.default = Lesson;
@@ -32,6 +32,11 @@ export interface LessonProps {
32
32
  * @default false
33
33
  */
34
34
  editMode?: boolean;
35
+ /**
36
+ * Renders preview mode
37
+ * @default false
38
+ */
39
+ previewMode?: boolean;
35
40
  /**
36
41
  * Callback fired on edit mode close
37
42
  * @default null
@@ -3,10 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
4
4
  import { styled } from '@mui/material/styles';
5
5
  import { useThemeProps } from '@mui/system';
6
- import { Box, Icon, IconButton, Typography, useMediaQuery, useTheme } from '@mui/material';
6
+ import { Box, Icon, IconButton, Typography, useMediaQuery, useTheme, Alert } from '@mui/material';
7
7
  import { PREFIX } from './constants';
8
8
  import { SCCourseJoinStatusType, SCCourseLessonCompletionStatusType } from '@selfcommunity/types';
9
- import { useSCFetchCourse, useSCFetchLesson } from '@selfcommunity/react-core';
9
+ import { SCRoutes, useSCFetchCourse, useSCFetchLesson, useSCRouting, Link } from '@selfcommunity/react-core';
10
10
  import classNames from 'classnames';
11
11
  import { CourseCompletedDialog, HiddenPlaceholder, LessonAppbar, LessonDrawer, LessonObject, SCLessonActionsType } from '@selfcommunity/react-ui';
12
12
  import { CourseInfoViewType, CourseService } from '@selfcommunity/api-services';
@@ -18,6 +18,7 @@ const classes = {
18
18
  containerRoot: `${PREFIX}-container-root`,
19
19
  navigation: `${PREFIX}-navigation`,
20
20
  navigationTitle: `${PREFIX}-navigation-title`,
21
+ previewInfo: `${PREFIX}-preview-info`,
21
22
  button: `${PREFIX}-button`
22
23
  };
23
24
  const Root = styled(Box, {
@@ -31,6 +32,14 @@ const Container = styled(Box, {
31
32
  overridesResolver: (props, styles) => styles.containerRoot,
32
33
  shouldForwardProp: (prop) => prop !== 'open'
33
34
  })(() => ({}));
35
+ function getUrlLesson(course, lesson) {
36
+ return {
37
+ id: course.id,
38
+ slug: course.slug,
39
+ section_id: lesson.section_id,
40
+ lesson_id: lesson.id
41
+ };
42
+ }
34
43
  export default function Lesson(inProps) {
35
44
  var _a, _b, _c;
36
45
  // PROPS
@@ -38,15 +47,19 @@ export default function Lesson(inProps) {
38
47
  props: inProps,
39
48
  name: PREFIX
40
49
  });
41
- const { className = null, courseId, sectionId, lessonId, LessonAppbarProps = {}, LessonDrawerProps = {}, editMode = false, onEditModeClose = null, onLessonChange = null, onActivePanelChange = null } = props, rest = __rest(props, ["className", "courseId", "sectionId", "lessonId", "LessonAppbarProps", "LessonDrawerProps", "editMode", "onEditModeClose", "onLessonChange", "onActivePanelChange"]);
50
+ const { className = null, courseId, sectionId, lessonId, LessonAppbarProps = {}, LessonDrawerProps = {}, editMode = false, previewMode = false, onEditModeClose = null, onLessonChange = null, onActivePanelChange = null } = props, rest = __rest(props, ["className", "courseId", "sectionId", "lessonId", "LessonAppbarProps", "LessonDrawerProps", "editMode", "previewMode", "onEditModeClose", "onLessonChange", "onActivePanelChange"]);
42
51
  // HOOKS
43
52
  const theme = useTheme();
44
53
  const isMobile = useMediaQuery(theme.breakpoints.down('md'));
45
54
  const [_lessonId, setLessonId] = useState(lessonId);
46
55
  const [_sectionId, setSectionId] = useState(sectionId);
47
56
  const { scLesson, setSCLesson } = useSCFetchLesson({ id: _lessonId, courseId, sectionId: _sectionId });
48
- const { scCourse, setSCCourse } = useSCFetchCourse({ id: courseId, params: { view: editMode ? CourseInfoViewType.EDIT : CourseInfoViewType.USER } });
57
+ const { scCourse, setSCCourse } = useSCFetchCourse({
58
+ id: courseId,
59
+ params: { view: editMode || previewMode ? CourseInfoViewType.EDIT : CourseInfoViewType.USER }
60
+ });
49
61
  const { enqueueSnackbar } = useSnackbar();
62
+ const scRoutingContext = useSCRouting();
50
63
  // STATE
51
64
  const [activePanel, setActivePanel] = useState(null);
52
65
  const [settings, setSettings] = useState(null);
@@ -58,11 +71,10 @@ export default function Lesson(inProps) {
58
71
  const availableLessons = useMemo(() => {
59
72
  if (!(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections))
60
73
  return [];
61
- return scCourse.sections.flatMap((section) => section.lessons.map((lesson) => (Object.assign(Object.assign({}, lesson), { section }))));
74
+ return scCourse.sections.flatMap((section) => section.lessons.filter((lesson) => !lesson.locked).map((lesson) => (Object.assign(Object.assign({}, lesson), { section }))));
62
75
  }, [scCourse]);
63
76
  const [currentLessonIndex, setCurrentLessonIndex] = useState(availableLessons.findIndex((lesson) => lesson.id === lessonId));
64
- const [currentSection, setCurrentSection] = useState(((_b = availableLessons[currentLessonIndex]) === null || _b === void 0 ? void 0 : _b.section) || null);
65
- const isPrevDisabled = availableLessons.length === 0 || currentLessonIndex <= 0;
77
+ const isPrevDisabled = availableLessons.length === 0 || currentLessonIndex <= 0 || ((_b = availableLessons[currentLessonIndex - 1]) === null || _b === void 0 ? void 0 : _b.locked);
66
78
  const isNextDisabled = availableLessons.length === 0 || currentLessonIndex >= availableLessons.length - 1 || ((_c = availableLessons[currentLessonIndex + 1]) === null || _c === void 0 ? void 0 : _c.locked);
67
79
  const [openDialog, setOpenDialog] = useState(false);
68
80
  const isCourseAdmin = useMemo(() => scCourse && scCourse.join_status === SCCourseJoinStatusType.CREATOR, [scCourse]);
@@ -71,12 +83,6 @@ export default function Lesson(inProps) {
71
83
  const index = availableLessons.findIndex((lesson) => lesson.id === lessonId);
72
84
  setCurrentLessonIndex(index);
73
85
  }, [lessonId, availableLessons]);
74
- useEffect(() => {
75
- var _a;
76
- if (availableLessons.length > 0 && currentLessonIndex >= 0) {
77
- setCurrentSection(((_a = availableLessons[currentLessonIndex]) === null || _a === void 0 ? void 0 : _a.section) || null);
78
- }
79
- }, [currentLessonIndex, availableLessons]);
80
86
  useEffect(() => {
81
87
  if (scLesson) {
82
88
  setCompleted(scLesson.completion_status === SCCourseLessonCompletionStatusType.COMPLETED);
@@ -108,7 +114,6 @@ export default function Lesson(inProps) {
108
114
  const handleChangeLesson = (l, s) => {
109
115
  setLessonId(l.id);
110
116
  setSectionId(s.id);
111
- setCurrentSection(s);
112
117
  onLessonChange && onLessonChange(l.id, s.id);
113
118
  };
114
119
  /**
@@ -145,7 +150,6 @@ export default function Lesson(inProps) {
145
150
  const newLessonIndex = currentLessonIndex - 1;
146
151
  const newLesson = availableLessons[newLessonIndex];
147
152
  setCurrentLessonIndex(newLessonIndex);
148
- setCurrentSection(newLesson.section);
149
153
  handleChangeLesson(newLesson, newLesson.section);
150
154
  };
151
155
  /**
@@ -157,7 +161,6 @@ export default function Lesson(inProps) {
157
161
  const newLessonIndex = currentLessonIndex + 1;
158
162
  const newLesson = availableLessons[newLessonIndex];
159
163
  setCurrentLessonIndex(newLessonIndex);
160
- setCurrentSection(newLesson.section);
161
164
  handleChangeLesson(newLesson, newLesson.section);
162
165
  };
163
166
  /**
@@ -196,5 +199,8 @@ export default function Lesson(inProps) {
196
199
  if (!scLesson || !scCourse) {
197
200
  return _jsx(HiddenPlaceholder, {});
198
201
  }
199
- return (_jsxs(Fragment, { children: [_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: [_jsx(LessonAppbar, Object.assign({ showComments: scLesson.comments_enabled, editMode: editMode, activePanel: activePanel, title: scCourse.name, handleOpen: handleOpenDrawer, onSave: handleLessonUpdate, updating: updating }, LessonAppbarProps)), _jsxs(Container, Object.assign({ open: Boolean(activePanel) || editMode, className: classes.containerRoot }, { children: [_jsx(Box, Object.assign({ className: classes.navigation }, { children: _jsx(Typography, Object.assign({ variant: "body2", color: "text.secondary" }, { children: _jsx(FormattedMessage, { id: "templates.lesson.number", defaultMessage: "templates.lesson.number", values: { from: currentLessonIndex + 1, to: availableLessons.length } }) })) })), _jsxs(Box, Object.assign({ className: classes.navigationTitle }, { children: [_jsx(Typography, Object.assign({ variant: "h5" }, { children: scLesson.name })), _jsxs(Box, { children: [_jsx(IconButton, Object.assign({ onClick: handlePrev, disabled: isPrevDisabled }, { children: _jsx(Icon, { children: "arrow_back" }) })), _jsx(IconButton, Object.assign({ onClick: handleNext, disabled: isNextDisabled }, { children: _jsx(Icon, { children: "arrow_next" }) }))] })] })), _jsx(LessonObject, { course: scCourse, lesson: scLesson, editMode: editMode, onContentChange: handleLessonContentEdit, onMediaChange: handleLessonMediaEdit }), !isCourseAdmin && !editMode && (_jsx(LoadingButton, Object.assign({ className: classes.button, loading: loading, size: "small", variant: completed ? 'outlined' : 'contained', startIcon: !completed && _jsx(Icon, { children: "arrow_next" }), endIcon: completed && _jsx(Icon, { children: "circle_checked" }), onClick: toggleLessonCompletion }, { children: completed ? (_jsx(FormattedMessage, { id: "templates.lesson.button.completed", defaultMessage: "templates.lesson.button.completed" })) : (_jsx(FormattedMessage, { id: "templates.lesson.button.complete", defaultMessage: "templates.lesson.button.complete" })) })))] })), _jsx(LessonDrawer, Object.assign({ course: scCourse, lesson: scLesson, editMode: isMobile ? activePanel === SCLessonActionsType.SETTINGS : editMode, activePanel: activePanel, handleClose: handleCloseDrawer, handleChangeLesson: handleChangeLesson, LessonEditFormProps: { lesson: scLesson, onSave: handleLessonUpdate, updating: updating, onSettingsChange: handleSettingsChange } }, LessonDrawerProps))] })), openDialog && _jsx(CourseCompletedDialog, { course: scCourse, onClose: handleCloseDialog })] }));
202
+ return (_jsxs(Fragment, { children: [_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: [_jsx(LessonAppbar, Object.assign({ showComments: scLesson.comments_enabled, editMode: editMode, activePanel: activePanel, title: scCourse.name, handleOpen: handleOpenDrawer, onSave: handleLessonUpdate, updating: updating }, LessonAppbarProps)), _jsxs(Container, Object.assign({ open: Boolean(activePanel) || editMode, className: classes.containerRoot }, { children: [previewMode && (_jsx(Alert, Object.assign({ severity: "info", className: classes.previewInfo }, { children: _jsx(Typography, Object.assign({ variant: "body1" }, { children: _jsx(FormattedMessage, { id: "templates.lesson.previewMode", defaultMessage: "templates.lesson.previewMode", values: {
203
+ link: (...chunks) => (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.COURSE_LESSON_EDIT_ROUTE_NAME, getUrlLesson(scCourse, scLesson)) }, { children: chunks }))),
204
+ linkBack: (...chunks) => _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.COURSE_DASHBOARD_ROUTE_NAME, scCourse) }, { children: chunks }))
205
+ } }) })) }))), _jsx(Box, Object.assign({ className: classes.navigation }, { children: _jsx(Typography, Object.assign({ variant: "body2", color: "text.secondary" }, { children: _jsx(FormattedMessage, { id: "templates.lesson.number", defaultMessage: "templates.lesson.number", values: { from: currentLessonIndex + 1, to: availableLessons.length } }) })) })), _jsxs(Box, Object.assign({ className: classes.navigationTitle }, { children: [_jsx(Typography, Object.assign({ variant: "h5" }, { children: scLesson.name })), _jsxs(Box, { children: [_jsx(IconButton, Object.assign({ onClick: handlePrev, disabled: isPrevDisabled }, { children: _jsx(Icon, { children: "arrow_back" }) })), _jsx(IconButton, Object.assign({ onClick: handleNext, disabled: isNextDisabled }, { children: _jsx(Icon, { children: "arrow_next" }) }))] })] })), _jsx(LessonObject, { course: scCourse, lesson: scLesson, editMode: editMode, onContentChange: handleLessonContentEdit, onMediaChange: handleLessonMediaEdit }), !isCourseAdmin && !editMode && !previewMode && (_jsx(LoadingButton, Object.assign({ className: classes.button, loading: loading, size: "small", variant: completed ? 'outlined' : 'contained', startIcon: !completed && _jsx(Icon, { children: "arrow_next" }), endIcon: completed && _jsx(Icon, { children: "circle_checked" }), onClick: toggleLessonCompletion }, { children: completed ? (_jsx(FormattedMessage, { id: "templates.lesson.button.completed", defaultMessage: "templates.lesson.button.completed" })) : (_jsx(FormattedMessage, { id: "templates.lesson.button.complete", defaultMessage: "templates.lesson.button.complete" })) })))] })), _jsx(LessonDrawer, Object.assign({ course: scCourse, lesson: scLesson, editMode: isMobile ? activePanel === SCLessonActionsType.SETTINGS : editMode, previewMode: previewMode, activePanel: activePanel, handleClose: handleCloseDrawer, handleChangeLesson: handleChangeLesson, LessonEditFormProps: { lesson: scLesson, onSave: handleLessonUpdate, updating: updating, onSettingsChange: handleSettingsChange } }, LessonDrawerProps))] })), openDialog && _jsx(CourseCompletedDialog, { course: scCourse, onClose: handleCloseDialog })] }));
200
206
  }