@selfcommunity/react-templates 0.4.8-alpha.9 → 0.4.8-payments.143
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/CategoryFeed/CategoryFeed.js +2 -1
- package/lib/cjs/components/Course/Course.d.ts +26 -0
- package/lib/cjs/components/Course/Course.js +39 -0
- package/lib/cjs/components/Course/constants.d.ts +1 -0
- package/lib/cjs/components/Course/constants.js +4 -0
- package/lib/cjs/components/Course/index.d.ts +4 -0
- package/lib/cjs/components/Course/index.js +9 -0
- package/lib/cjs/components/Lesson/Lesson.d.ts +65 -0
- package/lib/cjs/components/Lesson/Lesson.js +144 -0
- package/lib/cjs/components/Lesson/constants.d.ts +1 -0
- package/lib/cjs/components/Lesson/constants.js +4 -0
- package/lib/cjs/components/Lesson/index.d.ts +3 -0
- package/lib/cjs/components/Lesson/index.js +5 -0
- package/lib/cjs/index.d.ts +3 -1
- package/lib/cjs/index.js +7 -1
- package/lib/esm/components/CategoryFeed/CategoryFeed.js +4 -3
- package/lib/esm/components/Course/Course.d.ts +26 -0
- package/lib/esm/components/Course/Course.js +35 -0
- package/lib/esm/components/Course/constants.d.ts +1 -0
- package/lib/esm/components/Course/constants.js +1 -0
- package/lib/esm/components/Course/index.d.ts +4 -0
- package/lib/esm/components/Course/index.js +4 -0
- package/lib/esm/components/Lesson/Lesson.d.ts +65 -0
- package/lib/esm/components/Lesson/Lesson.js +141 -0
- package/lib/esm/components/Lesson/constants.d.ts +1 -0
- package/lib/esm/components/Lesson/constants.js +1 -0
- package/lib/esm/components/Lesson/index.d.ts +3 -0
- package/lib/esm/components/Lesson/index.js +2 -0
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +3 -1
- package/lib/umd/595.js +2 -0
- package/lib/umd/60a7fdeaadfe844bc015.woff2 +0 -0
- package/lib/umd/{e0b2b8a5f2f737384ae5.svg → 6158171e38cbff3c3340.svg} +9 -3
- package/lib/umd/{c3528e120c4e831db2ae.woff → b6dbec3d5816ff8baef1.woff} +0 -0
- package/lib/umd/{2aa155858f48b8f3911a.eot → ba74e493633796d551d1.ttf} +0 -0
- package/lib/umd/{a221d3aba0f6753cfbb7.ttf → c473ce30406a3dad83e1.eot} +0 -0
- package/lib/umd/react-templates.js +1 -1
- package/package.json +6 -6
- package/lib/umd/36f3af7f155d916c26ff.woff2 +0 -0
- package/lib/umd/920.js +0 -2
- /package/lib/umd/{920.js.LICENSE.txt → 595.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { useThemeProps } from '@mui/system';
|
|
6
|
+
import { Box, Icon, IconButton, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
7
|
+
import { PREFIX } from './constants';
|
|
8
|
+
import { useSCFetchCourse, useSCFetchLesson } from '@selfcommunity/react-core';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { getCurrentSectionAndLessonIndex, HiddenPlaceholder, LessonAppbar, LessonDrawer, LessonObject, SCLessonActionsType } from '@selfcommunity/react-ui';
|
|
11
|
+
import { CourseInfoViewType, CourseService } from '@selfcommunity/api-services';
|
|
12
|
+
import { FormattedMessage } from 'react-intl';
|
|
13
|
+
const classes = {
|
|
14
|
+
root: `${PREFIX}-root`,
|
|
15
|
+
containerRoot: `${PREFIX}-container-root`,
|
|
16
|
+
navigation: `${PREFIX}-navigation`,
|
|
17
|
+
navigationTitle: `${PREFIX}-navigation-title`
|
|
18
|
+
};
|
|
19
|
+
const Root = styled(Box, {
|
|
20
|
+
name: PREFIX,
|
|
21
|
+
slot: 'Root',
|
|
22
|
+
overridesResolver: (props, styles) => [styles.root]
|
|
23
|
+
})(() => ({}));
|
|
24
|
+
const Container = styled(Box, {
|
|
25
|
+
name: PREFIX,
|
|
26
|
+
slot: 'ContainerRoot',
|
|
27
|
+
overridesResolver: (props, styles) => styles.containerRoot,
|
|
28
|
+
shouldForwardProp: (prop) => prop !== 'open'
|
|
29
|
+
})(() => ({}));
|
|
30
|
+
export default function Lesson(inProps) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
|
+
// PROPS
|
|
33
|
+
const props = useThemeProps({
|
|
34
|
+
props: inProps,
|
|
35
|
+
name: PREFIX
|
|
36
|
+
});
|
|
37
|
+
const { className = null, course, courseId, sectionId, lesson = null, lessonId, LessonAppbarProps = {}, LessonDrawerProps = {}, editMode = false, onEditModeClose = null, onLessonChange = null, onActivePanelChange = null } = props, rest = __rest(props, ["className", "course", "courseId", "sectionId", "lesson", "lessonId", "LessonAppbarProps", "LessonDrawerProps", "editMode", "onEditModeClose", "onLessonChange", "onActivePanelChange"]);
|
|
38
|
+
// HOOKS
|
|
39
|
+
const theme = useTheme();
|
|
40
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
41
|
+
const [_lessonId, setLessonId] = useState(lessonId);
|
|
42
|
+
const [_sectionId, setSectionId] = useState(sectionId);
|
|
43
|
+
const { scCourse } = useSCFetchCourse({ id: courseId, course, params: { view: editMode ? CourseInfoViewType.EDIT : CourseInfoViewType.USER } });
|
|
44
|
+
const { scLesson, setSCLesson } = useSCFetchLesson({ id: _lessonId, lesson, courseId, sectionId: _sectionId });
|
|
45
|
+
// STATE
|
|
46
|
+
const [activePanel, setActivePanel] = useState(null);
|
|
47
|
+
const [settings, setSettings] = useState(null);
|
|
48
|
+
const [updating, setUpdating] = useState(false);
|
|
49
|
+
const [lessonContent, setLessonContent] = useState('');
|
|
50
|
+
const [lessonMedias, setLessonMedias] = useState((_a = scLesson === null || scLesson === void 0 ? void 0 : scLesson.medias) !== null && _a !== void 0 ? _a : []);
|
|
51
|
+
// HANDLERS
|
|
52
|
+
/**
|
|
53
|
+
* Handles lesson settings change
|
|
54
|
+
* @param newSettings
|
|
55
|
+
*/
|
|
56
|
+
const handleSettingsChange = (newSettings) => {
|
|
57
|
+
setSettings(newSettings);
|
|
58
|
+
};
|
|
59
|
+
const handleOpenDrawer = (panel) => {
|
|
60
|
+
setActivePanel((prevPanel) => (prevPanel === panel ? null : panel));
|
|
61
|
+
onActivePanelChange && onActivePanelChange(panel);
|
|
62
|
+
};
|
|
63
|
+
const handleCloseDrawer = () => {
|
|
64
|
+
setActivePanel(null);
|
|
65
|
+
onEditModeClose && onEditModeClose();
|
|
66
|
+
onActivePanelChange && onActivePanelChange(null);
|
|
67
|
+
};
|
|
68
|
+
const handleLessonContentEdit = (html) => {
|
|
69
|
+
setLessonContent(html);
|
|
70
|
+
};
|
|
71
|
+
const handleLessonMediaEdit = (medias) => {
|
|
72
|
+
setLessonMedias(medias);
|
|
73
|
+
};
|
|
74
|
+
const handleChangeLesson = (l, s) => {
|
|
75
|
+
setLessonId(l.id);
|
|
76
|
+
setSectionId(s.id);
|
|
77
|
+
setCurrentSection(s);
|
|
78
|
+
onLessonChange && onLessonChange(l.id, s.id);
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Handles Lesson Edit
|
|
82
|
+
*/
|
|
83
|
+
const handleLessonUpdate = () => {
|
|
84
|
+
setUpdating(true);
|
|
85
|
+
const mediaIds = lessonMedias.map((media) => media.id);
|
|
86
|
+
const data = Object.assign(Object.assign({}, settings), { type: scLesson.type, name: scLesson.name, text: lessonContent, medias: mediaIds });
|
|
87
|
+
CourseService.updateCourseLesson(scCourse.id, sectionId, scLesson.id, data)
|
|
88
|
+
.then((data) => {
|
|
89
|
+
setUpdating(false);
|
|
90
|
+
setSCLesson(data);
|
|
91
|
+
})
|
|
92
|
+
.catch((error) => {
|
|
93
|
+
setUpdating(false);
|
|
94
|
+
console.log(error);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const currentData = useMemo(() => {
|
|
98
|
+
if (!scCourse || !scLesson)
|
|
99
|
+
return null;
|
|
100
|
+
return getCurrentSectionAndLessonIndex(scCourse, scLesson.section_id, scLesson.id);
|
|
101
|
+
}, [scCourse, scLesson]);
|
|
102
|
+
const [currentSectionIndex, setCurrentSectionIndex] = useState((currentData === null || currentData === void 0 ? void 0 : currentData.currentSectionIndex) || 0);
|
|
103
|
+
const [currentLessonIndex, setCurrentLessonIndex] = useState((currentData === null || currentData === void 0 ? void 0 : currentData.currentLessonIndex) || 0);
|
|
104
|
+
const [currentSection, setCurrentSection] = useState(((_b = scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections) === null || _b === void 0 ? void 0 : _b[currentSectionIndex]) || null);
|
|
105
|
+
const handlePrev = () => {
|
|
106
|
+
if (currentLessonIndex > 0) {
|
|
107
|
+
const newLessonIndex = currentLessonIndex - 1;
|
|
108
|
+
setCurrentLessonIndex(newLessonIndex);
|
|
109
|
+
handleChangeLesson(currentSection.lessons[newLessonIndex], currentSection);
|
|
110
|
+
}
|
|
111
|
+
else if (currentSectionIndex > 0) {
|
|
112
|
+
const prevSectionIndex = currentSectionIndex - 1;
|
|
113
|
+
const prevSection = scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections[prevSectionIndex];
|
|
114
|
+
const newLessonIndex = prevSection.lessons.length - 1;
|
|
115
|
+
setCurrentSectionIndex(prevSectionIndex);
|
|
116
|
+
setCurrentLessonIndex(newLessonIndex);
|
|
117
|
+
handleChangeLesson(prevSection.lessons[newLessonIndex], prevSection);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const handleNext = () => {
|
|
121
|
+
if (currentLessonIndex < currentSection.lessons.length - 1) {
|
|
122
|
+
const newLessonIndex = currentLessonIndex + 1;
|
|
123
|
+
setCurrentLessonIndex(newLessonIndex);
|
|
124
|
+
handleChangeLesson(currentSection.lessons[newLessonIndex], currentSection);
|
|
125
|
+
}
|
|
126
|
+
else if (currentSectionIndex < (scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections.length) - 1) {
|
|
127
|
+
const newSectionIndex = currentSectionIndex + 1;
|
|
128
|
+
setCurrentSectionIndex(newSectionIndex);
|
|
129
|
+
setCurrentLessonIndex(0);
|
|
130
|
+
handleChangeLesson(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections[newSectionIndex].lessons[0], scCourse.sections[newSectionIndex]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const isPrevDisabled = !(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections) || (currentSectionIndex === 0 && currentLessonIndex === 0);
|
|
134
|
+
const isNextDisabled = !(scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections) ||
|
|
135
|
+
(currentSectionIndex === (scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections.length) - 1 && currentLessonIndex === ((_c = currentSection === null || currentSection === void 0 ? void 0 : currentSection.lessons) === null || _c === void 0 ? void 0 : _c.length) - 1) ||
|
|
136
|
+
((_e = (_d = scCourse === null || scCourse === void 0 ? void 0 : scCourse.sections[currentSectionIndex + 1]) === null || _d === void 0 ? void 0 : _d.lessons[0]) === null || _e === void 0 ? void 0 : _e.locked);
|
|
137
|
+
if (!scLesson || !scCourse) {
|
|
138
|
+
return _jsx(HiddenPlaceholder, {});
|
|
139
|
+
}
|
|
140
|
+
return (_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: (_f = currentSection === null || currentSection === void 0 ? void 0 : currentSection.lessons) === null || _f === void 0 ? void 0 : _f.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 })] })), _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))] })));
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX = "SCLessonTemplate";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PREFIX = 'SCLessonTemplate';
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ import Group, { GroupProps, GroupSkeleton } from './components/Group';
|
|
|
11
11
|
import GroupFeed, { GroupFeedProps, GroupFeedSkeleton } from './components/GroupFeed';
|
|
12
12
|
import Event, { EventProps, EventSkeleton } from './components/Event';
|
|
13
13
|
import EventFeed, { EventFeedProps, EventFeedSkeleton } from './components/EventFeed';
|
|
14
|
-
|
|
14
|
+
import Lesson, { LessonProps } from './components/Lesson';
|
|
15
|
+
import Course, { CourseProps, TeacherSkeleton, StudentSkeleton } from './components/Course';
|
|
16
|
+
export { Category, CategoryProps, CategorySkeleton, CategoryFeed, CategoryFeedProps, CategoryFeedSkeleton, Course, CourseProps, TeacherSkeleton, StudentSkeleton, ExploreFeed, ExploreFeedProps, ExploreFeedSkeleton, FeedObjectDetail, FeedObjectDetailProps, FeedObjectDetailSkeleton, MainFeed, MainFeedProps, MainFeedSkeleton, NotificationFeed, NotificationFeedProps, NotificationFeedSkeleton, UserFeed, UserFeedProps, UserFeedSkeleton, UserProfile, UserProfileProps, UserProfileSkeleton, LoyaltyProgramDetail, LoyaltyProgramDetailProps, LoyaltyProgramDetailSkeleton, GroupFeed, GroupFeedProps, GroupFeedSkeleton, Group, GroupProps, GroupSkeleton, Event, EventProps, EventSkeleton, EventFeed, EventFeedProps, EventFeedSkeleton, Lesson, LessonProps };
|
package/lib/esm/index.js
CHANGED
|
@@ -11,4 +11,6 @@ import Group, { GroupSkeleton } from './components/Group';
|
|
|
11
11
|
import GroupFeed, { GroupFeedSkeleton } from './components/GroupFeed';
|
|
12
12
|
import Event, { EventSkeleton } from './components/Event';
|
|
13
13
|
import EventFeed, { EventFeedSkeleton } from './components/EventFeed';
|
|
14
|
-
|
|
14
|
+
import Lesson from './components/Lesson';
|
|
15
|
+
import Course, { TeacherSkeleton, StudentSkeleton } from './components/Course';
|
|
16
|
+
export { Category, CategorySkeleton, CategoryFeed, CategoryFeedSkeleton, Course, TeacherSkeleton, StudentSkeleton, ExploreFeed, ExploreFeedSkeleton, FeedObjectDetail, FeedObjectDetailSkeleton, MainFeed, MainFeedSkeleton, NotificationFeed, NotificationFeedSkeleton, UserFeed, UserFeedSkeleton, UserProfile, UserProfileSkeleton, LoyaltyProgramDetail, LoyaltyProgramDetailSkeleton, GroupFeed, GroupFeedSkeleton, Group, GroupSkeleton, Event, EventSkeleton, EventFeed, EventFeedSkeleton, Lesson };
|