@selfcommunity/react-ui 0.10.2-courses.152 → 0.10.2-courses.154
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.
- package/lib/cjs/components/CourseDashboard/Student.js +22 -8
- package/lib/cjs/components/EditCourse/Customize.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Customize.js +3 -3
- package/lib/cjs/components/EditCourse/EditCourse.js +4 -4
- package/lib/cjs/components/EditCourse/Lessons/FieldName.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Lessons/FieldName.js +1 -1
- package/lib/cjs/components/EditCourse/Lessons/LessonRow.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Lessons/SectionRow.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Lessons/SectionRow.js +4 -3
- package/lib/cjs/components/EditCourse/Lessons.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Lessons.js +36 -20
- package/lib/cjs/components/EditCourse/Options.d.ts +1 -1
- package/lib/cjs/components/EditCourse/Options.js +2 -2
- package/lib/esm/components/CourseDashboard/Student.js +23 -9
- package/lib/esm/components/EditCourse/Customize.d.ts +1 -1
- package/lib/esm/components/EditCourse/Customize.js +3 -3
- package/lib/esm/components/EditCourse/EditCourse.js +4 -4
- package/lib/esm/components/EditCourse/Lessons/FieldName.d.ts +1 -1
- package/lib/esm/components/EditCourse/Lessons/FieldName.js +1 -1
- package/lib/esm/components/EditCourse/Lessons/LessonRow.d.ts +1 -1
- package/lib/esm/components/EditCourse/Lessons/SectionRow.d.ts +1 -1
- package/lib/esm/components/EditCourse/Lessons/SectionRow.js +4 -3
- package/lib/esm/components/EditCourse/Lessons.d.ts +1 -1
- package/lib/esm/components/EditCourse/Lessons.js +36 -20
- package/lib/esm/components/EditCourse/Options.d.ts +1 -1
- package/lib/esm/components/EditCourse/Options.js +2 -2
- package/lib/umd/react-ui.js +1 -1
- package/package.json +8 -8
|
@@ -48,7 +48,7 @@ const headerCells = [
|
|
|
48
48
|
];
|
|
49
49
|
function Lessons(props) {
|
|
50
50
|
// PROPS
|
|
51
|
-
const { course,
|
|
51
|
+
const { course, setCourse } = props;
|
|
52
52
|
// STATES
|
|
53
53
|
const [sections, setSections] = useState([]);
|
|
54
54
|
// HOOKS
|
|
@@ -82,7 +82,7 @@ function Lessons(props) {
|
|
|
82
82
|
sections_order: tempSections.map((tempSection) => tempSection.id)
|
|
83
83
|
};
|
|
84
84
|
CourseService.patchCourse(course.id, data)
|
|
85
|
-
.then(() =>
|
|
85
|
+
.then(() => setCourse(Object.assign(Object.assign({}, course), { sections: tempSections })))
|
|
86
86
|
.catch((error) => {
|
|
87
87
|
Logger.error(SCOPE_SC_UI, error);
|
|
88
88
|
enqueueSnackbar(_jsx(FormattedMessage, { id: "ui.common.error.action", defaultMessage: "ui.common.error.action" }), {
|
|
@@ -94,24 +94,30 @@ function Lessons(props) {
|
|
|
94
94
|
const handleAddTempSection = useCallback(() => {
|
|
95
95
|
setSections((prevSections) => (prevSections.length > 0 ? [...prevSections, getSection(prevSections.length + 1)] : [getSection(1)]));
|
|
96
96
|
}, [setSections]);
|
|
97
|
-
const handleManageSection = useCallback((section, type) => {
|
|
97
|
+
const handleManageSection = useCallback((section, type, newRow = false) => {
|
|
98
98
|
switch (type) {
|
|
99
99
|
case ActionLessonType.ADD:
|
|
100
|
-
|
|
100
|
+
setCourse(Object.assign(Object.assign({}, course), { num_sections: course.num_sections + 1, sections: [...course.sections, section] }));
|
|
101
101
|
break;
|
|
102
102
|
case ActionLessonType.RENAME:
|
|
103
|
-
|
|
103
|
+
setCourse(Object.assign(Object.assign({}, course), { sections: course.sections.map((prevSection) => {
|
|
104
104
|
if (prevSection.id === section.id) {
|
|
105
105
|
return Object.assign(Object.assign({}, prevSection), { name: section.name });
|
|
106
106
|
}
|
|
107
107
|
return prevSection;
|
|
108
108
|
}) }));
|
|
109
109
|
break;
|
|
110
|
-
case ActionLessonType.DELETE:
|
|
111
|
-
|
|
110
|
+
case ActionLessonType.DELETE: {
|
|
111
|
+
if (newRow) {
|
|
112
|
+
setCourse(Object.assign(Object.assign({}, course), { sections: course.sections.filter((prevSection) => prevSection.id !== section.id) }));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
setCourse(Object.assign(Object.assign({}, course), { num_sections: course.num_sections - 1, num_lessons: course.num_lessons - section.num_lessons, sections: course.sections.filter((prevSection) => prevSection.id !== section.id) }));
|
|
116
|
+
}
|
|
112
117
|
break;
|
|
118
|
+
}
|
|
113
119
|
case ActionLessonType.UPDATE:
|
|
114
|
-
|
|
120
|
+
setCourse(Object.assign(Object.assign({}, course), { sections: course.sections.map((prevSection) => {
|
|
115
121
|
if (prevSection.id === section.id) {
|
|
116
122
|
return Object.assign(Object.assign({}, prevSection), { lessons: section.lessons });
|
|
117
123
|
}
|
|
@@ -119,22 +125,32 @@ function Lessons(props) {
|
|
|
119
125
|
}) }));
|
|
120
126
|
break;
|
|
121
127
|
case type.endsWith(ActionLessonType.UPDATE) && type: {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
if (newRow) {
|
|
129
|
+
setCourse(Object.assign(Object.assign({}, course), { sections: course.sections.map((prevSection) => {
|
|
130
|
+
if (prevSection.id === section.id) {
|
|
131
|
+
return section;
|
|
132
|
+
}
|
|
133
|
+
return prevSection;
|
|
134
|
+
}) }));
|
|
125
135
|
}
|
|
126
|
-
else
|
|
127
|
-
numLessons = course.num_lessons
|
|
136
|
+
else {
|
|
137
|
+
let numLessons = course.num_lessons;
|
|
138
|
+
if (type === ActionLessonType.ADD_UPDATE) {
|
|
139
|
+
numLessons = course.num_lessons + 1;
|
|
140
|
+
}
|
|
141
|
+
else if (type === ActionLessonType.DELETE_UPDATE) {
|
|
142
|
+
numLessons = course.num_lessons - 1;
|
|
143
|
+
}
|
|
144
|
+
setCourse(Object.assign(Object.assign({}, course), { num_lessons: numLessons, sections: course.sections.map((prevSection) => {
|
|
145
|
+
if (prevSection.id === section.id) {
|
|
146
|
+
return section;
|
|
147
|
+
}
|
|
148
|
+
return prevSection;
|
|
149
|
+
}) }));
|
|
128
150
|
}
|
|
129
|
-
setSCCourse(Object.assign(Object.assign({}, course), { num_lessons: numLessons, sections: course.sections.map((prevSection) => {
|
|
130
|
-
if (prevSection.id === section.id) {
|
|
131
|
-
return section;
|
|
132
|
-
}
|
|
133
|
-
return prevSection;
|
|
134
|
-
}) }));
|
|
135
151
|
}
|
|
136
152
|
}
|
|
137
|
-
}, [course
|
|
153
|
+
}, [course]);
|
|
138
154
|
return (_jsxs(Box, { children: [_jsx(Typography, Object.assign({ className: classes.lessonTitle, variant: "h4" }, { children: _jsx(FormattedMessage, { id: "ui.editCourse.tab.lessons", defaultMessage: "ui.editCourse.tab.lessons" }) })), _jsxs(Stack, Object.assign({ className: classes.lessonInfoWrapper }, { children: [_jsxs(Stack, Object.assign({ className: classes.lessonInfo }, { children: [_jsx(Icon, { children: "courses" }), _jsx(Typography, Object.assign({ variant: "body2" }, { children: _jsx(FormattedMessage, { id: "ui.course.type", defaultMessage: "ui.course.type", values: {
|
|
139
155
|
typeOfCourse: intl.formatMessage({
|
|
140
156
|
id: `ui.course.type.${course.type}`,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { SCCourseType } from '@selfcommunity/types';
|
|
3
3
|
interface OptionsProps {
|
|
4
4
|
course: SCCourseType;
|
|
5
|
-
|
|
5
|
+
setCourse: (course: SCCourseType) => void;
|
|
6
6
|
}
|
|
7
7
|
declare function Options(props: OptionsProps): JSX.Element;
|
|
8
8
|
declare const _default: import("react").MemoExoticComponent<typeof Options>;
|
|
@@ -31,7 +31,7 @@ const OPTIONS = {
|
|
|
31
31
|
};
|
|
32
32
|
function Options(props) {
|
|
33
33
|
// PROPS
|
|
34
|
-
const { course,
|
|
34
|
+
const { course, setCourse } = props;
|
|
35
35
|
// STATES
|
|
36
36
|
const [tempOptions, setTempOptions] = useState(null);
|
|
37
37
|
const [canSave, setCanSave] = useState(false);
|
|
@@ -70,7 +70,7 @@ function Options(props) {
|
|
|
70
70
|
setLoading(true);
|
|
71
71
|
CourseService.patchCourse(course.id, Object.assign({ id: course.id }, tempOptions))
|
|
72
72
|
.then((data) => {
|
|
73
|
-
|
|
73
|
+
setCourse(data);
|
|
74
74
|
setTempOptions(null);
|
|
75
75
|
setCanSave(false);
|
|
76
76
|
setLoading(false);
|