@selfcommunity/react-core 0.6.4-alpha.9 → 0.6.4-courses.101
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/provider/SCRoutingProvider/index.js +1 -0
- package/lib/cjs/components/provider/SCUserProvider/index.js +6 -0
- package/lib/cjs/constants/Cache.d.ts +25 -2
- package/lib/cjs/constants/Cache.js +34 -4
- package/lib/cjs/constants/Notification.d.ts +1 -0
- package/lib/cjs/constants/Notification.js +2 -1
- package/lib/cjs/constants/Preferences.d.ts +8 -0
- package/lib/cjs/constants/Preferences.js +18 -2
- package/lib/cjs/constants/Routes.d.ts +8 -0
- package/lib/cjs/constants/Routes.js +17 -1
- package/lib/cjs/hooks/useSCFetchCourse.d.ts +23 -0
- package/lib/cjs/hooks/useSCFetchCourse.js +81 -0
- package/lib/cjs/hooks/useSCFetchCourses.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchCourses.js +83 -0
- package/lib/cjs/hooks/useSCFetchLesson.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchLesson.js +72 -0
- package/lib/cjs/hooks/useSCFetchLessonCommentObject.d.ts +23 -0
- package/lib/cjs/hooks/useSCFetchLessonCommentObject.js +72 -0
- package/lib/cjs/hooks/useSCFetchLessonCommentObjects.d.ts +48 -0
- package/lib/cjs/hooks/useSCFetchLessonCommentObjects.js +302 -0
- package/lib/cjs/hooks/useSCFetchLiveStream.d.ts +20 -0
- package/lib/cjs/hooks/useSCFetchLiveStream.js +76 -0
- package/lib/cjs/hooks/useSCJoinedCoursesManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCJoinedCoursesManager.js +277 -0
- package/lib/cjs/index.d.ts +8 -2
- package/lib/cjs/index.js +14 -2
- package/lib/cjs/types/context.d.ts +36 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/esm/components/provider/SCRoutingProvider/index.js +2 -1
- package/lib/esm/components/provider/SCUserProvider/index.js +6 -0
- package/lib/esm/constants/Cache.d.ts +25 -2
- package/lib/esm/constants/Cache.js +25 -2
- package/lib/esm/constants/Notification.d.ts +1 -0
- package/lib/esm/constants/Notification.js +2 -1
- package/lib/esm/constants/Preferences.d.ts +8 -0
- package/lib/esm/constants/Preferences.js +16 -0
- package/lib/esm/constants/Routes.d.ts +8 -0
- package/lib/esm/constants/Routes.js +16 -0
- package/lib/esm/hooks/useSCFetchCourse.d.ts +23 -0
- package/lib/esm/hooks/useSCFetchCourse.js +78 -0
- package/lib/esm/hooks/useSCFetchCourses.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchCourses.js +81 -0
- package/lib/esm/hooks/useSCFetchLesson.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchLesson.js +69 -0
- package/lib/esm/hooks/useSCFetchLessonCommentObject.d.ts +23 -0
- package/lib/esm/hooks/useSCFetchLessonCommentObject.js +69 -0
- package/lib/esm/hooks/useSCFetchLessonCommentObjects.d.ts +48 -0
- package/lib/esm/hooks/useSCFetchLessonCommentObjects.js +297 -0
- package/lib/esm/hooks/useSCFetchLiveStream.d.ts +20 -0
- package/lib/esm/hooks/useSCFetchLiveStream.js +73 -0
- package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +38 -0
- package/lib/esm/hooks/useSCJoinedCoursesManager.js +273 -0
- package/lib/esm/index.d.ts +8 -2
- package/lib/esm/index.js +7 -1
- package/lib/esm/types/context.d.ts +36 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/umd/react-core.js +1 -1
- package/lib/umd/react-core.js.LICENSE.txt +2 -0
- package/package.json +132 -127
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
3
|
+
import { SCFeatureName, SCCoursePrivacyType, SCCourseJoinStatusType, SCNotificationTopicType, SCNotificationTypologyType, } from '@selfcommunity/types';
|
|
4
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
5
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
6
|
+
import { Logger } from '@selfcommunity/utils';
|
|
7
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
8
|
+
import { SCNotificationMapping } from '../constants/Notification';
|
|
9
|
+
import { CONFIGURATIONS_COURSES_ENABLED } from '../constants/Preferences';
|
|
10
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
11
|
+
import PubSub from 'pubsub-js';
|
|
12
|
+
/**
|
|
13
|
+
:::info
|
|
14
|
+
This custom hook is used to manage the courses followed.
|
|
15
|
+
:::
|
|
16
|
+
|
|
17
|
+
:::tip How to use it:
|
|
18
|
+
Follow these steps:
|
|
19
|
+
```jsx
|
|
20
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
21
|
+
2. const scJoinedCoursesManager: SCJoinedCoursesManagerType = scUserContext.manager.courses;
|
|
22
|
+
3. scJoinedCoursesManager.isJoined(course)
|
|
23
|
+
```
|
|
24
|
+
:::
|
|
25
|
+
*/
|
|
26
|
+
export default function useSCJoinedCoursesManager(user) {
|
|
27
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
28
|
+
const { preferences, features } = useSCPreferences();
|
|
29
|
+
const authUserId = user ? user.id : null;
|
|
30
|
+
const coursesEnabled = useMemo(() => preferences &&
|
|
31
|
+
features &&
|
|
32
|
+
features.includes(SCFeatureName.TAGGING) &&
|
|
33
|
+
features.includes(SCFeatureName.COURSE) &&
|
|
34
|
+
CONFIGURATIONS_COURSES_ENABLED in preferences &&
|
|
35
|
+
preferences[CONFIGURATIONS_COURSES_ENABLED].value, [preferences, features]);
|
|
36
|
+
const notificationInvitedToJoinCourse = useRef(null);
|
|
37
|
+
const notificationRequestedToJoinCourse = useRef(null);
|
|
38
|
+
const notificationAcceptedToJoinCourse = useRef(null);
|
|
39
|
+
const notificationAddedToCourse = useRef(null);
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
42
|
+
*/
|
|
43
|
+
useDeepCompareEffectNoCheck(() => {
|
|
44
|
+
notificationInvitedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE}`, notificationSubscriber);
|
|
45
|
+
notificationRequestedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE}`, notificationSubscriber);
|
|
46
|
+
notificationAcceptedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE}`, notificationSubscriber);
|
|
47
|
+
notificationAddedToCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_COURSE}`, notificationSubscriber);
|
|
48
|
+
return () => {
|
|
49
|
+
PubSub.unsubscribe(notificationInvitedToJoinCourse.current);
|
|
50
|
+
PubSub.unsubscribe(notificationRequestedToJoinCourse.current);
|
|
51
|
+
PubSub.unsubscribe(notificationAcceptedToJoinCourse.current);
|
|
52
|
+
PubSub.unsubscribe(notificationAddedToCourse.current);
|
|
53
|
+
};
|
|
54
|
+
}, [data]);
|
|
55
|
+
/**
|
|
56
|
+
* Notification subscriber handler
|
|
57
|
+
* @param msg
|
|
58
|
+
* @param dataMsg
|
|
59
|
+
*/
|
|
60
|
+
const notificationSubscriber = (msg, dataMsg) => {
|
|
61
|
+
if (dataMsg.data.course !== undefined) {
|
|
62
|
+
let _status;
|
|
63
|
+
switch (SCNotificationMapping[dataMsg.data.activity_type]) {
|
|
64
|
+
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE:
|
|
65
|
+
_status = SCCourseJoinStatusType.INVITED;
|
|
66
|
+
break;
|
|
67
|
+
case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
|
|
68
|
+
_status = SCCourseJoinStatusType.REQUESTED;
|
|
69
|
+
break;
|
|
70
|
+
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE:
|
|
71
|
+
_status = SCCourseJoinStatusType.JOINED;
|
|
72
|
+
break;
|
|
73
|
+
case SCNotificationTypologyType.USER_ADDED_TO_COURSE:
|
|
74
|
+
_status = SCCourseJoinStatusType.JOINED;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
updateCache([dataMsg.data.course.id]);
|
|
78
|
+
setData((prev) => getDataUpdated(prev, dataMsg.data.course.id, _status));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Memoized refresh all courses
|
|
83
|
+
* It makes a single request to the server and retrieves
|
|
84
|
+
* all the courses followed by the user in a single solution
|
|
85
|
+
* It might be useful for multi-tab sync
|
|
86
|
+
*/
|
|
87
|
+
const refresh = useMemo(() => () => {
|
|
88
|
+
emptyCache();
|
|
89
|
+
if (user) {
|
|
90
|
+
// Only if user is authenticated
|
|
91
|
+
http
|
|
92
|
+
.request({
|
|
93
|
+
url: Endpoints.GetJoinedCourses.url(),
|
|
94
|
+
method: Endpoints.GetJoinedCourses.method,
|
|
95
|
+
})
|
|
96
|
+
.then((res) => {
|
|
97
|
+
if (res.status >= 300) {
|
|
98
|
+
return Promise.reject(res);
|
|
99
|
+
}
|
|
100
|
+
const coursesIds = res.data.results.map((c) => c.id);
|
|
101
|
+
updateCache(coursesIds);
|
|
102
|
+
setData(res.data.results.map((c) => ({ [c.id]: c.join_status })));
|
|
103
|
+
return Promise.resolve(res.data);
|
|
104
|
+
})
|
|
105
|
+
.catch((e) => {
|
|
106
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh the authenticated user courses.');
|
|
107
|
+
Logger.error(SCOPE_SC_CORE, e);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, [data, user, cache]);
|
|
111
|
+
/**
|
|
112
|
+
* Memoized join Course
|
|
113
|
+
* Toggle action
|
|
114
|
+
*/
|
|
115
|
+
const join = useMemo(() => (course, userId) => {
|
|
116
|
+
setLoading(course.id);
|
|
117
|
+
if (userId) {
|
|
118
|
+
return http
|
|
119
|
+
.request({
|
|
120
|
+
url: Endpoints.InviteOrAcceptUsersToCourse.url({ id: course.id }),
|
|
121
|
+
method: Endpoints.InviteOrAcceptUsersToCourse.method,
|
|
122
|
+
data: { users: [userId] },
|
|
123
|
+
})
|
|
124
|
+
.then((res) => {
|
|
125
|
+
if (res.status >= 300) {
|
|
126
|
+
return Promise.reject(res);
|
|
127
|
+
}
|
|
128
|
+
updateCache([course.id]);
|
|
129
|
+
setData((prev) => getDataUpdated(prev, course.id, SCCourseJoinStatusType.JOINED));
|
|
130
|
+
setUnLoading(course.id);
|
|
131
|
+
return Promise.resolve(res.data);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return http
|
|
136
|
+
.request({
|
|
137
|
+
url: Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
|
|
138
|
+
method: Endpoints.JoinOrAcceptInviteToCourse.method,
|
|
139
|
+
})
|
|
140
|
+
.then((res) => {
|
|
141
|
+
if (res.status >= 300) {
|
|
142
|
+
return Promise.reject(res);
|
|
143
|
+
}
|
|
144
|
+
updateCache([course.id]);
|
|
145
|
+
setData((prev) => getDataUpdated(prev, course.id, course.privacy === SCCoursePrivacyType.PRIVATE && course.join_status !== SCCourseJoinStatusType.INVITED
|
|
146
|
+
? SCCourseJoinStatusType.REQUESTED
|
|
147
|
+
: SCCourseJoinStatusType.JOINED));
|
|
148
|
+
setUnLoading(course.id);
|
|
149
|
+
return Promise.resolve(res.data);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}, [data, loading, cache]);
|
|
153
|
+
/**
|
|
154
|
+
* Memoized leave Course
|
|
155
|
+
* Toggle action
|
|
156
|
+
*/
|
|
157
|
+
const leave = useMemo(() => (course) => {
|
|
158
|
+
if (course.join_status !== SCCourseJoinStatusType.REQUESTED) {
|
|
159
|
+
setLoading(course.id);
|
|
160
|
+
return http
|
|
161
|
+
.request({
|
|
162
|
+
url: Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
|
|
163
|
+
method: Endpoints.LeaveOrRemoveCourseRequest.method,
|
|
164
|
+
})
|
|
165
|
+
.then((res) => {
|
|
166
|
+
if (res.status >= 300) {
|
|
167
|
+
return Promise.reject(res);
|
|
168
|
+
}
|
|
169
|
+
updateCache([course.id]);
|
|
170
|
+
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
171
|
+
setUnLoading(course.id);
|
|
172
|
+
return Promise.resolve(res.data);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}, [data, loading, cache]);
|
|
176
|
+
/**
|
|
177
|
+
* Check the authenticated user subscription status to the course
|
|
178
|
+
* Update the courses cached
|
|
179
|
+
* Update courses subscription statuses
|
|
180
|
+
* @param course
|
|
181
|
+
*/
|
|
182
|
+
const checkCourseJoinedStatus = (course) => {
|
|
183
|
+
setLoading(course.id);
|
|
184
|
+
return http
|
|
185
|
+
.request({
|
|
186
|
+
url: Endpoints.GetCourseStatus.url({ id: course.id }),
|
|
187
|
+
method: Endpoints.GetCourseStatus.method,
|
|
188
|
+
})
|
|
189
|
+
.then((res) => {
|
|
190
|
+
if (res.status >= 300) {
|
|
191
|
+
return Promise.reject(res);
|
|
192
|
+
}
|
|
193
|
+
setData((prev) => getDataUpdated(prev, course.id, res.data.status));
|
|
194
|
+
updateCache([course.id]);
|
|
195
|
+
setUnLoading(course.id);
|
|
196
|
+
return Promise.resolve(res.data);
|
|
197
|
+
})
|
|
198
|
+
.catch((e) => {
|
|
199
|
+
setUnLoading(course.id);
|
|
200
|
+
return Promise.reject(e);
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Get updated data
|
|
205
|
+
* @param data
|
|
206
|
+
* @param courseId
|
|
207
|
+
* @param joinStatus
|
|
208
|
+
*/
|
|
209
|
+
const getDataUpdated = (data, courseId, joinStatus) => {
|
|
210
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === courseId);
|
|
211
|
+
let _data;
|
|
212
|
+
if (_index < 0) {
|
|
213
|
+
_data = [...data, ...[{ [courseId]: joinStatus }]];
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
_data = data.map((k, i) => {
|
|
217
|
+
if (parseInt(Object.keys(k)[0]) === courseId) {
|
|
218
|
+
return { [Object.keys(k)[0]]: joinStatus };
|
|
219
|
+
}
|
|
220
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return _data;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Return current course subscription status if exists,
|
|
227
|
+
* otherwise return null
|
|
228
|
+
*/
|
|
229
|
+
const getCurrentCourseCacheStatus = useMemo(() => (course) => {
|
|
230
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === course.id);
|
|
231
|
+
return d.length ? d[0][course.id] : !data.length ? course.join_status : null;
|
|
232
|
+
}, [data]);
|
|
233
|
+
/**
|
|
234
|
+
* Bypass remote check if the course is subscribed
|
|
235
|
+
*/
|
|
236
|
+
const getJoinStatus = useMemo(() => (course) => {
|
|
237
|
+
updateCache([course.id]);
|
|
238
|
+
setData((prev) => getDataUpdated(prev, course.id, course.join_status));
|
|
239
|
+
return course.join_status;
|
|
240
|
+
}, [data, cache]);
|
|
241
|
+
/**
|
|
242
|
+
* Memoized joinStatus
|
|
243
|
+
* If the course is already in cache -> check if the course is in courses,
|
|
244
|
+
* otherwise, check if user joined the course
|
|
245
|
+
*/
|
|
246
|
+
const joinStatus = useMemo(() => (course) => {
|
|
247
|
+
// Cache is valid also for anonymous user
|
|
248
|
+
if (cache.includes(course.id)) {
|
|
249
|
+
return getCurrentCourseCacheStatus(course);
|
|
250
|
+
}
|
|
251
|
+
if (authUserId) {
|
|
252
|
+
if ('join_status' in course) {
|
|
253
|
+
return getJoinStatus(course);
|
|
254
|
+
}
|
|
255
|
+
if (!isLoading(course)) {
|
|
256
|
+
checkCourseJoinedStatus(course);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}, [loading, cache, authUserId]);
|
|
261
|
+
/**
|
|
262
|
+
* Empty cache on logout
|
|
263
|
+
*/
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (!authUserId) {
|
|
266
|
+
emptyCache();
|
|
267
|
+
}
|
|
268
|
+
}, [authUserId]);
|
|
269
|
+
if (!coursesEnabled || !user) {
|
|
270
|
+
return { courses: data, loading, isLoading };
|
|
271
|
+
}
|
|
272
|
+
return { courses: data, loading, isLoading, join, leave, joinStatus, refresh, emptyCache };
|
|
273
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types
|
|
3
3
|
*/
|
|
4
|
-
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './types';
|
|
4
|
+
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -47,6 +47,8 @@ import useSCFetchVote from './hooks/useSCFetchVote';
|
|
|
47
47
|
import useSCFetchFeedObject from './hooks/useSCFetchFeedObject';
|
|
48
48
|
import useSCFetchCommentObject from './hooks/useSCFetchCommentObject';
|
|
49
49
|
import useSCFetchCommentObjects from './hooks/useSCFetchCommentObjects';
|
|
50
|
+
import useSCFetchLessonCommentObject from './hooks/useSCFetchLessonCommentObject';
|
|
51
|
+
import useSCFetchLessonCommentObjects from './hooks/useSCFetchLessonCommentObjects';
|
|
50
52
|
import useSCFetchCustomAdv from './hooks/useSCFetchCustomAdv';
|
|
51
53
|
import useSCFetchTag from './hooks/useSCFetchTag';
|
|
52
54
|
import useSCFetchAddressingTagList from './hooks/useSCFetchAddressingTagList';
|
|
@@ -64,7 +66,11 @@ import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
|
64
66
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
65
67
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
66
68
|
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
69
|
+
import useSCFetchLiveStream from './hooks/useSCFetchLiveStream';
|
|
67
70
|
import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
|
|
71
|
+
import useSCFetchCourse from './hooks/useSCFetchCourse';
|
|
72
|
+
import useSCFetchCourses from './hooks/useSCFetchCourses';
|
|
73
|
+
import useSCFetchLesson from './hooks/useSCFetchLesson';
|
|
68
74
|
/**
|
|
69
75
|
* Routing component
|
|
70
76
|
*/
|
|
@@ -87,4 +93,4 @@ import * as Preferences from './constants/Preferences';
|
|
|
87
93
|
/**
|
|
88
94
|
* List all exports
|
|
89
95
|
*/
|
|
90
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCGoogleApiLoader, };
|
|
96
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, };
|
package/lib/esm/index.js
CHANGED
|
@@ -43,6 +43,8 @@ import useSCFetchVote from './hooks/useSCFetchVote';
|
|
|
43
43
|
import useSCFetchFeedObject from './hooks/useSCFetchFeedObject';
|
|
44
44
|
import useSCFetchCommentObject from './hooks/useSCFetchCommentObject';
|
|
45
45
|
import useSCFetchCommentObjects from './hooks/useSCFetchCommentObjects';
|
|
46
|
+
import useSCFetchLessonCommentObject from './hooks/useSCFetchLessonCommentObject';
|
|
47
|
+
import useSCFetchLessonCommentObjects from './hooks/useSCFetchLessonCommentObjects';
|
|
46
48
|
import useSCFetchCustomAdv from './hooks/useSCFetchCustomAdv';
|
|
47
49
|
import useSCFetchTag from './hooks/useSCFetchTag';
|
|
48
50
|
import useSCFetchAddressingTagList from './hooks/useSCFetchAddressingTagList';
|
|
@@ -60,7 +62,11 @@ import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
|
60
62
|
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
61
63
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
62
64
|
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
65
|
+
import useSCFetchLiveStream from './hooks/useSCFetchLiveStream';
|
|
63
66
|
import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
|
|
67
|
+
import useSCFetchCourse from './hooks/useSCFetchCourse';
|
|
68
|
+
import useSCFetchCourses from './hooks/useSCFetchCourses';
|
|
69
|
+
import useSCFetchLesson from './hooks/useSCFetchLesson';
|
|
64
70
|
/**
|
|
65
71
|
* Routing component
|
|
66
72
|
*/
|
|
@@ -83,4 +89,4 @@ import * as Preferences from './constants/Preferences';
|
|
|
83
89
|
/**
|
|
84
90
|
* List all exports
|
|
85
91
|
*/
|
|
86
|
-
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCGoogleApiLoader, };
|
|
92
|
+
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchLessonCommentObject, useSCFetchLessonCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, useSCFetchCourse, useSCFetchCourses, useSCFetchLesson, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType, SCCourseType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -148,6 +148,7 @@ export interface SCUserContextType {
|
|
|
148
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
149
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
150
|
events?: SCSubscribedEventsManagerType;
|
|
151
|
+
courses?: SCJoinedCoursesManagerType;
|
|
151
152
|
};
|
|
152
153
|
}
|
|
153
154
|
export interface SCSettingsManagerType {
|
|
@@ -254,6 +255,40 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
254
255
|
*/
|
|
255
256
|
emptyCache?: () => void;
|
|
256
257
|
}
|
|
258
|
+
export interface SCJoinedCoursesManagerType {
|
|
259
|
+
/**
|
|
260
|
+
* List of all courses ids followed by the authenticated user
|
|
261
|
+
*/
|
|
262
|
+
courses: number[];
|
|
263
|
+
/**
|
|
264
|
+
* List of all courses in loading state
|
|
265
|
+
*/
|
|
266
|
+
loading: number[];
|
|
267
|
+
/**
|
|
268
|
+
* List of current courses in loading state
|
|
269
|
+
*/
|
|
270
|
+
isLoading: (course: SCCourseType) => boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Handle user joining a course
|
|
273
|
+
*/
|
|
274
|
+
join?: (course: SCCourseType, userId?: number) => Promise<any>;
|
|
275
|
+
/**
|
|
276
|
+
* Handle user leaving a course
|
|
277
|
+
*/
|
|
278
|
+
leave?: (course: SCCourseType) => Promise<any>;
|
|
279
|
+
/**
|
|
280
|
+
* Handles a user join status to a course, caching data
|
|
281
|
+
*/
|
|
282
|
+
joinStatus?: (course: SCCourseType) => string;
|
|
283
|
+
/**
|
|
284
|
+
* Refresh courses
|
|
285
|
+
*/
|
|
286
|
+
refresh?: () => void;
|
|
287
|
+
/**
|
|
288
|
+
* Empty cache to revalidate all courses
|
|
289
|
+
*/
|
|
290
|
+
emptyCache?: () => void;
|
|
291
|
+
}
|
|
257
292
|
export interface SCSubscribedEventsManagerType {
|
|
258
293
|
/**
|
|
259
294
|
* List of all events ids followed by the authenticated user
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './context';
|
|
1
|
+
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType } from './context';
|
|
2
2
|
import { SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType } from './theme';
|
|
3
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, };
|
|
3
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCJoinedCoursesManagerType, };
|