@selfcommunity/react-templates 0.4.5-courses.181 → 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.
|
@@ -73,11 +73,10 @@ function Lesson(inProps) {
|
|
|
73
73
|
const availableLessons = (0, react_1.useMemo)(() => {
|
|
74
74
|
if (!(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections))
|
|
75
75
|
return [];
|
|
76
|
-
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 }))));
|
|
77
77
|
}, [scCourse]);
|
|
78
78
|
const [currentLessonIndex, setCurrentLessonIndex] = (0, react_1.useState)(availableLessons.findIndex((lesson) => lesson.id === lessonId));
|
|
79
|
-
const
|
|
80
|
-
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);
|
|
81
80
|
const isNextDisabled = availableLessons.length === 0 || currentLessonIndex >= availableLessons.length - 1 || ((_c = availableLessons[currentLessonIndex + 1]) === null || _c === void 0 ? void 0 : _c.locked);
|
|
82
81
|
const [openDialog, setOpenDialog] = (0, react_1.useState)(false);
|
|
83
82
|
const isCourseAdmin = (0, react_1.useMemo)(() => scCourse && scCourse.join_status === types_1.SCCourseJoinStatusType.CREATOR, [scCourse]);
|
|
@@ -86,12 +85,6 @@ function Lesson(inProps) {
|
|
|
86
85
|
const index = availableLessons.findIndex((lesson) => lesson.id === lessonId);
|
|
87
86
|
setCurrentLessonIndex(index);
|
|
88
87
|
}, [lessonId, availableLessons]);
|
|
89
|
-
(0, react_1.useEffect)(() => {
|
|
90
|
-
var _a;
|
|
91
|
-
if (availableLessons.length > 0 && currentLessonIndex >= 0) {
|
|
92
|
-
setCurrentSection(((_a = availableLessons[currentLessonIndex]) === null || _a === void 0 ? void 0 : _a.section) || null);
|
|
93
|
-
}
|
|
94
|
-
}, [currentLessonIndex, availableLessons]);
|
|
95
88
|
(0, react_1.useEffect)(() => {
|
|
96
89
|
if (scLesson) {
|
|
97
90
|
setCompleted(scLesson.completion_status === types_1.SCCourseLessonCompletionStatusType.COMPLETED);
|
|
@@ -123,7 +116,6 @@ function Lesson(inProps) {
|
|
|
123
116
|
const handleChangeLesson = (l, s) => {
|
|
124
117
|
setLessonId(l.id);
|
|
125
118
|
setSectionId(s.id);
|
|
126
|
-
setCurrentSection(s);
|
|
127
119
|
onLessonChange && onLessonChange(l.id, s.id);
|
|
128
120
|
};
|
|
129
121
|
/**
|
|
@@ -160,7 +152,6 @@ function Lesson(inProps) {
|
|
|
160
152
|
const newLessonIndex = currentLessonIndex - 1;
|
|
161
153
|
const newLesson = availableLessons[newLessonIndex];
|
|
162
154
|
setCurrentLessonIndex(newLessonIndex);
|
|
163
|
-
setCurrentSection(newLesson.section);
|
|
164
155
|
handleChangeLesson(newLesson, newLesson.section);
|
|
165
156
|
};
|
|
166
157
|
/**
|
|
@@ -172,7 +163,6 @@ function Lesson(inProps) {
|
|
|
172
163
|
const newLessonIndex = currentLessonIndex + 1;
|
|
173
164
|
const newLesson = availableLessons[newLessonIndex];
|
|
174
165
|
setCurrentLessonIndex(newLessonIndex);
|
|
175
|
-
setCurrentSection(newLesson.section);
|
|
176
166
|
handleChangeLesson(newLesson, newLesson.section);
|
|
177
167
|
};
|
|
178
168
|
/**
|
|
@@ -71,11 +71,10 @@ export default function Lesson(inProps) {
|
|
|
71
71
|
const availableLessons = useMemo(() => {
|
|
72
72
|
if (!(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections))
|
|
73
73
|
return [];
|
|
74
|
-
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 }))));
|
|
75
75
|
}, [scCourse]);
|
|
76
76
|
const [currentLessonIndex, setCurrentLessonIndex] = useState(availableLessons.findIndex((lesson) => lesson.id === lessonId));
|
|
77
|
-
const
|
|
78
|
-
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);
|
|
79
78
|
const isNextDisabled = availableLessons.length === 0 || currentLessonIndex >= availableLessons.length - 1 || ((_c = availableLessons[currentLessonIndex + 1]) === null || _c === void 0 ? void 0 : _c.locked);
|
|
80
79
|
const [openDialog, setOpenDialog] = useState(false);
|
|
81
80
|
const isCourseAdmin = useMemo(() => scCourse && scCourse.join_status === SCCourseJoinStatusType.CREATOR, [scCourse]);
|
|
@@ -84,12 +83,6 @@ export default function Lesson(inProps) {
|
|
|
84
83
|
const index = availableLessons.findIndex((lesson) => lesson.id === lessonId);
|
|
85
84
|
setCurrentLessonIndex(index);
|
|
86
85
|
}, [lessonId, availableLessons]);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
var _a;
|
|
89
|
-
if (availableLessons.length > 0 && currentLessonIndex >= 0) {
|
|
90
|
-
setCurrentSection(((_a = availableLessons[currentLessonIndex]) === null || _a === void 0 ? void 0 : _a.section) || null);
|
|
91
|
-
}
|
|
92
|
-
}, [currentLessonIndex, availableLessons]);
|
|
93
86
|
useEffect(() => {
|
|
94
87
|
if (scLesson) {
|
|
95
88
|
setCompleted(scLesson.completion_status === SCCourseLessonCompletionStatusType.COMPLETED);
|
|
@@ -121,7 +114,6 @@ export default function Lesson(inProps) {
|
|
|
121
114
|
const handleChangeLesson = (l, s) => {
|
|
122
115
|
setLessonId(l.id);
|
|
123
116
|
setSectionId(s.id);
|
|
124
|
-
setCurrentSection(s);
|
|
125
117
|
onLessonChange && onLessonChange(l.id, s.id);
|
|
126
118
|
};
|
|
127
119
|
/**
|
|
@@ -158,7 +150,6 @@ export default function Lesson(inProps) {
|
|
|
158
150
|
const newLessonIndex = currentLessonIndex - 1;
|
|
159
151
|
const newLesson = availableLessons[newLessonIndex];
|
|
160
152
|
setCurrentLessonIndex(newLessonIndex);
|
|
161
|
-
setCurrentSection(newLesson.section);
|
|
162
153
|
handleChangeLesson(newLesson, newLesson.section);
|
|
163
154
|
};
|
|
164
155
|
/**
|
|
@@ -170,7 +161,6 @@ export default function Lesson(inProps) {
|
|
|
170
161
|
const newLessonIndex = currentLessonIndex + 1;
|
|
171
162
|
const newLesson = availableLessons[newLessonIndex];
|
|
172
163
|
setCurrentLessonIndex(newLessonIndex);
|
|
173
|
-
setCurrentSection(newLesson.section);
|
|
174
164
|
handleChangeLesson(newLesson, newLesson.section);
|
|
175
165
|
};
|
|
176
166
|
/**
|