@selfcommunity/react-core 0.6.7-payments.189 → 0.6.7-payments.192
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/hooks/useSCJoinedCoursesManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCJoinedCoursesManager.js +25 -68
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +0 -17
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +18 -57
- package/lib/esm/hooks/useSCJoinedCoursesManager.d.ts +1 -1
- package/lib/esm/hooks/useSCJoinedCoursesManager.js +26 -68
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +0 -17
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +18 -57
- package/lib/umd/react-core.js +1 -1
- package/package.json +5 -5
|
@@ -30,7 +30,7 @@ export default function useSCJoinedCoursesManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
join: (course: SCCourseType
|
|
33
|
+
join: (course: SCCourseType) => Promise<any>;
|
|
34
34
|
leave: (course: SCCourseType) => Promise<any>;
|
|
35
35
|
joinStatus: (course: SCCourseType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -36,27 +36,15 @@ function useSCJoinedCoursesManager(user) {
|
|
|
36
36
|
Preferences_1.CONFIGURATIONS_COURSES_ENABLED in preferences &&
|
|
37
37
|
preferences[Preferences_1.CONFIGURATIONS_COURSES_ENABLED].value, [preferences, features]);
|
|
38
38
|
const notificationInvitedToJoinCourse = (0, react_1.useRef)(null);
|
|
39
|
-
// const notificationRequestedToJoinCourse = useRef(null);
|
|
40
|
-
// const notificationAcceptedToJoinCourse = useRef(null);
|
|
41
39
|
const notificationAddedToCourse = (0, react_1.useRef)(null);
|
|
42
40
|
/**
|
|
43
41
|
* Subscribe to notification types user_follow, user_unfollow
|
|
44
42
|
*/
|
|
45
43
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
46
44
|
notificationInvitedToJoinCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE}`, notificationSubscriber);
|
|
47
|
-
/* notificationRequestedToJoinCourse.current = PubSub.subscribe(
|
|
48
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE}`,
|
|
49
|
-
notificationSubscriber
|
|
50
|
-
);
|
|
51
|
-
notificationAcceptedToJoinCourse.current = PubSub.subscribe(
|
|
52
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE}`,
|
|
53
|
-
notificationSubscriber
|
|
54
|
-
); */
|
|
55
45
|
notificationAddedToCourse.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_COURSE}`, notificationSubscriber);
|
|
56
46
|
return () => {
|
|
57
47
|
pubsub_js_1.default.unsubscribe(notificationInvitedToJoinCourse.current);
|
|
58
|
-
// PubSub.unsubscribe(notificationRequestedToJoinCourse.current);
|
|
59
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinCourse.current);
|
|
60
48
|
pubsub_js_1.default.unsubscribe(notificationAddedToCourse.current);
|
|
61
49
|
};
|
|
62
50
|
}, [data]);
|
|
@@ -73,12 +61,6 @@ function useSCJoinedCoursesManager(user) {
|
|
|
73
61
|
case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE:
|
|
74
62
|
_status = types_1.SCCourseJoinStatusType.INVITED;
|
|
75
63
|
break;
|
|
76
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
|
|
77
|
-
_status = SCCourseJoinStatusType.REQUESTED;
|
|
78
|
-
break;
|
|
79
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE:
|
|
80
|
-
_status = SCCourseJoinStatusType.JOINED;
|
|
81
|
-
break; */
|
|
82
64
|
case types_1.SCNotificationTypologyType.USER_ADDED_TO_COURSE:
|
|
83
65
|
if (dataMsg.data.notification_obj.course && ((_a = dataMsg.data.notification_obj.course.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
84
66
|
_status = types_1.SCCourseJoinStatusType.PAYMENT_WAITING;
|
|
@@ -126,67 +108,42 @@ function useSCJoinedCoursesManager(user) {
|
|
|
126
108
|
* Memoized join Course
|
|
127
109
|
* Toggle action
|
|
128
110
|
*/
|
|
129
|
-
const join = (0, react_1.useMemo)(() => (course,
|
|
111
|
+
const join = (0, react_1.useMemo)(() => (course) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
130
112
|
setLoading(course.id);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
})
|
|
138
|
-
.then((res) => {
|
|
139
|
-
if (res.status >= 300) {
|
|
140
|
-
return Promise.reject(res);
|
|
141
|
-
}
|
|
142
|
-
updateCache([course.id]);
|
|
143
|
-
setData((prev) => getDataUpdated(prev, course.id, types_1.SCCourseJoinStatusType.JOINED));
|
|
144
|
-
setUnLoading(course.id);
|
|
145
|
-
return Promise.resolve(res.data);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
return api_services_1.http
|
|
150
|
-
.request({
|
|
151
|
-
url: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
|
|
152
|
-
method: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.method,
|
|
153
|
-
})
|
|
154
|
-
.then((res) => {
|
|
155
|
-
if (res.status >= 300) {
|
|
156
|
-
return Promise.reject(res);
|
|
157
|
-
}
|
|
158
|
-
updateCache([course.id]);
|
|
159
|
-
setData((prev) => getDataUpdated(prev, course.id, course.privacy === types_1.SCCoursePrivacyType.PRIVATE && course.join_status !== types_1.SCCourseJoinStatusType.INVITED
|
|
160
|
-
? types_1.SCCourseJoinStatusType.REQUESTED
|
|
161
|
-
: types_1.SCCourseJoinStatusType.JOINED));
|
|
162
|
-
setUnLoading(course.id);
|
|
163
|
-
return Promise.resolve(res.data);
|
|
164
|
-
});
|
|
113
|
+
const res = yield api_services_1.http.request({
|
|
114
|
+
url: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
|
|
115
|
+
method: api_services_1.Endpoints.JoinOrAcceptInviteToCourse.method,
|
|
116
|
+
});
|
|
117
|
+
if (res.status >= 300) {
|
|
118
|
+
return Promise.reject(res);
|
|
165
119
|
}
|
|
166
|
-
|
|
120
|
+
updateCache([course.id]);
|
|
121
|
+
setData((prev) => getDataUpdated(prev, course.id, course.privacy === types_1.SCCoursePrivacyType.PRIVATE && course.join_status !== types_1.SCCourseJoinStatusType.INVITED
|
|
122
|
+
? types_1.SCCourseJoinStatusType.REQUESTED
|
|
123
|
+
: types_1.SCCourseJoinStatusType.JOINED));
|
|
124
|
+
setUnLoading(course.id);
|
|
125
|
+
return yield Promise.resolve(res.data);
|
|
126
|
+
}), [data, loading, cache]);
|
|
167
127
|
/**
|
|
168
128
|
* Memoized leave Course
|
|
169
129
|
* Toggle action
|
|
170
130
|
*/
|
|
171
|
-
const leave = (0, react_1.useMemo)(() => (course) => {
|
|
172
|
-
if (course.
|
|
131
|
+
const leave = (0, react_1.useMemo)(() => (course) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (data[course.id] !== types_1.SCCourseJoinStatusType.REQUESTED) {
|
|
173
133
|
setLoading(course.id);
|
|
174
|
-
|
|
175
|
-
.request({
|
|
134
|
+
const res = yield api_services_1.http.request({
|
|
176
135
|
url: api_services_1.Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
|
|
177
136
|
method: api_services_1.Endpoints.LeaveOrRemoveCourseRequest.method,
|
|
178
|
-
})
|
|
179
|
-
.then((res) => {
|
|
180
|
-
if (res.status >= 300) {
|
|
181
|
-
return Promise.reject(res);
|
|
182
|
-
}
|
|
183
|
-
updateCache([course.id]);
|
|
184
|
-
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
185
|
-
setUnLoading(course.id);
|
|
186
|
-
return Promise.resolve(res.data);
|
|
187
137
|
});
|
|
138
|
+
if (res.status >= 300) {
|
|
139
|
+
return Promise.reject(res);
|
|
140
|
+
}
|
|
141
|
+
updateCache([course.id]);
|
|
142
|
+
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
143
|
+
setUnLoading(course.id);
|
|
144
|
+
return yield Promise.resolve(res.data);
|
|
188
145
|
}
|
|
189
|
-
}, [data, loading, cache]);
|
|
146
|
+
}), [data, loading, cache]);
|
|
190
147
|
/**
|
|
191
148
|
* Check the authenticated user subscription status to the course
|
|
192
149
|
* Update the courses cached
|
|
@@ -45,20 +45,9 @@ function useSCSubscribedEventsManager(user) {
|
|
|
45
45
|
*/
|
|
46
46
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
47
47
|
notificationInvitedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
48
|
-
/* notificationRequestedToJoinEvent.current = PubSub.subscribe(
|
|
49
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`,
|
|
50
|
-
notificationSubscriber
|
|
51
|
-
);
|
|
52
|
-
notificationAcceptedToJoinEvent.current = PubSub.subscribe(
|
|
53
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`,
|
|
54
|
-
notificationSubscriber
|
|
55
|
-
);
|
|
56
|
-
*/
|
|
57
48
|
notificationAddedToEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
|
|
58
49
|
return () => {
|
|
59
50
|
pubsub_js_1.default.unsubscribe(notificationInvitedToJoinEvent.current);
|
|
60
|
-
// PubSub.unsubscribe(notificationRequestedToJoinEvent.current);
|
|
61
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinEvent.current);
|
|
62
51
|
pubsub_js_1.default.unsubscribe(notificationAddedToEvent.current);
|
|
63
52
|
};
|
|
64
53
|
}, [data]);
|
|
@@ -74,12 +63,6 @@ function useSCSubscribedEventsManager(user) {
|
|
|
74
63
|
case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
|
|
75
64
|
_status = types_1.SCEventSubscriptionStatusType.INVITED;
|
|
76
65
|
break;
|
|
77
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
|
|
78
|
-
_status = SCEventSubscriptionStatusType.REQUESTED;
|
|
79
|
-
break;
|
|
80
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
|
|
81
|
-
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
82
|
-
break; */
|
|
83
66
|
case types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT:
|
|
84
67
|
_status = types_1.SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
85
68
|
break;
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
subscribe: (group: SCGroupType
|
|
33
|
+
subscribe: (group: SCGroupType) => Promise<any>;
|
|
34
34
|
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -37,29 +37,15 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
37
37
|
Preferences_1.CONFIGURATIONS_GROUPS_ENABLED in preferences &&
|
|
38
38
|
preferences[Preferences_1.CONFIGURATIONS_GROUPS_ENABLED].value, [preferences, features]);
|
|
39
39
|
const notificationInvitedToJoinGroup = (0, react_1.useRef)(null);
|
|
40
|
-
// const notificationRequestedToJoinGroup = useRef(null);
|
|
41
|
-
// const notificationAcceptedToJoinGroup = useRef(null);
|
|
42
40
|
const notificationAddedToGroup = (0, react_1.useRef)(null);
|
|
43
41
|
/**
|
|
44
42
|
* Subscribe to notification types user_follow, user_unfollow
|
|
45
43
|
*/
|
|
46
44
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
47
45
|
notificationInvitedToJoinGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP}`, notificationSubscriber);
|
|
48
|
-
/*
|
|
49
|
-
notificationRequestedToJoinGroup.current = PubSub.subscribe(
|
|
50
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP}`,
|
|
51
|
-
notificationSubscriber
|
|
52
|
-
);
|
|
53
|
-
notificationAcceptedToJoinGroup.current = PubSub.subscribe(
|
|
54
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP}`,
|
|
55
|
-
notificationSubscriber
|
|
56
|
-
);
|
|
57
|
-
*/
|
|
58
46
|
notificationAddedToGroup.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP}`, notificationSubscriber);
|
|
59
47
|
return () => {
|
|
60
48
|
pubsub_js_1.default.unsubscribe(notificationInvitedToJoinGroup.current);
|
|
61
|
-
// PubSub.unsubscribe(notificationRequestedToJoinGroup.current);
|
|
62
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinGroup.current);
|
|
63
49
|
pubsub_js_1.default.unsubscribe(notificationAddedToGroup.current);
|
|
64
50
|
};
|
|
65
51
|
}, [data]);
|
|
@@ -76,12 +62,6 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
76
62
|
case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP:
|
|
77
63
|
_status = types_1.SCGroupSubscriptionStatusType.INVITED;
|
|
78
64
|
break;
|
|
79
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP:
|
|
80
|
-
_status = SCGroupSubscriptionStatusType.REQUESTED;
|
|
81
|
-
break;
|
|
82
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP:
|
|
83
|
-
_status = SCGroupSubscriptionStatusType.SUBSCRIBED;
|
|
84
|
-
break; */
|
|
85
65
|
case types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP:
|
|
86
66
|
if (dataMsg.data.notification_obj.group && ((_a = dataMsg.data.notification_obj.group.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
87
67
|
_status = types_1.SCGroupSubscriptionStatusType.PAYMENT_WAITING;
|
|
@@ -129,50 +109,31 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
129
109
|
* Memoized subscribe Group
|
|
130
110
|
* Toggle action
|
|
131
111
|
*/
|
|
132
|
-
const subscribe = (0, react_1.useMemo)(() => (group
|
|
112
|
+
const subscribe = (0, react_1.useMemo)(() => (group) => {
|
|
133
113
|
setLoading(group.id);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
return api_services_1.http
|
|
153
|
-
.request({
|
|
154
|
-
url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
155
|
-
method: api_services_1.Endpoints.SubscribeToGroup.method,
|
|
156
|
-
})
|
|
157
|
-
.then((res) => {
|
|
158
|
-
if (res.status >= 300) {
|
|
159
|
-
return Promise.reject(res);
|
|
160
|
-
}
|
|
161
|
-
updateCache([group.id]);
|
|
162
|
-
setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE && group.subscription_status !== types_1.SCGroupSubscriptionStatusType.INVITED
|
|
163
|
-
? types_1.SCGroupSubscriptionStatusType.REQUESTED
|
|
164
|
-
: types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
165
|
-
setUnLoading(group.id);
|
|
166
|
-
return Promise.resolve(res.data);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
114
|
+
return api_services_1.http
|
|
115
|
+
.request({
|
|
116
|
+
url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
117
|
+
method: api_services_1.Endpoints.SubscribeToGroup.method,
|
|
118
|
+
})
|
|
119
|
+
.then((res) => {
|
|
120
|
+
if (res.status >= 300) {
|
|
121
|
+
return Promise.reject(res);
|
|
122
|
+
}
|
|
123
|
+
updateCache([group.id]);
|
|
124
|
+
setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE && group.subscription_status !== types_1.SCGroupSubscriptionStatusType.INVITED
|
|
125
|
+
? types_1.SCGroupSubscriptionStatusType.REQUESTED
|
|
126
|
+
: types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
127
|
+
setUnLoading(group.id);
|
|
128
|
+
return Promise.resolve(res.data);
|
|
129
|
+
});
|
|
169
130
|
}, [data, loading, cache]);
|
|
170
131
|
/**
|
|
171
132
|
* Memoized subscribe Group
|
|
172
133
|
* Toggle action
|
|
173
134
|
*/
|
|
174
135
|
const unsubscribe = (0, react_1.useMemo)(() => (group) => {
|
|
175
|
-
if (group.
|
|
136
|
+
if (data[group.id] !== types_1.SCGroupSubscriptionStatusType.REQUESTED) {
|
|
176
137
|
setLoading(group.id);
|
|
177
138
|
return api_services_1.http
|
|
178
139
|
.request({
|
|
@@ -30,7 +30,7 @@ export default function useSCJoinedCoursesManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
join: (course: SCCourseType
|
|
33
|
+
join: (course: SCCourseType) => Promise<any>;
|
|
34
34
|
leave: (course: SCCourseType) => Promise<any>;
|
|
35
35
|
joinStatus: (course: SCCourseType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { useEffect, useMemo, useRef } from 'react';
|
|
2
3
|
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
3
4
|
import { SCFeatureName, SCCoursePrivacyType, SCCourseJoinStatusType, SCNotificationTopicType, SCNotificationTypologyType, } from '@selfcommunity/types';
|
|
@@ -33,27 +34,15 @@ export default function useSCJoinedCoursesManager(user) {
|
|
|
33
34
|
CONFIGURATIONS_COURSES_ENABLED in preferences &&
|
|
34
35
|
preferences[CONFIGURATIONS_COURSES_ENABLED].value, [preferences, features]);
|
|
35
36
|
const notificationInvitedToJoinCourse = useRef(null);
|
|
36
|
-
// const notificationRequestedToJoinCourse = useRef(null);
|
|
37
|
-
// const notificationAcceptedToJoinCourse = useRef(null);
|
|
38
37
|
const notificationAddedToCourse = useRef(null);
|
|
39
38
|
/**
|
|
40
39
|
* Subscribe to notification types user_follow, user_unfollow
|
|
41
40
|
*/
|
|
42
41
|
useDeepCompareEffectNoCheck(() => {
|
|
43
42
|
notificationInvitedToJoinCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE}`, notificationSubscriber);
|
|
44
|
-
/* notificationRequestedToJoinCourse.current = PubSub.subscribe(
|
|
45
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE}`,
|
|
46
|
-
notificationSubscriber
|
|
47
|
-
);
|
|
48
|
-
notificationAcceptedToJoinCourse.current = PubSub.subscribe(
|
|
49
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE}`,
|
|
50
|
-
notificationSubscriber
|
|
51
|
-
); */
|
|
52
43
|
notificationAddedToCourse.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_COURSE}`, notificationSubscriber);
|
|
53
44
|
return () => {
|
|
54
45
|
PubSub.unsubscribe(notificationInvitedToJoinCourse.current);
|
|
55
|
-
// PubSub.unsubscribe(notificationRequestedToJoinCourse.current);
|
|
56
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinCourse.current);
|
|
57
46
|
PubSub.unsubscribe(notificationAddedToCourse.current);
|
|
58
47
|
};
|
|
59
48
|
}, [data]);
|
|
@@ -70,12 +59,6 @@ export default function useSCJoinedCoursesManager(user) {
|
|
|
70
59
|
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_COURSE:
|
|
71
60
|
_status = SCCourseJoinStatusType.INVITED;
|
|
72
61
|
break;
|
|
73
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
|
|
74
|
-
_status = SCCourseJoinStatusType.REQUESTED;
|
|
75
|
-
break;
|
|
76
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_COURSE:
|
|
77
|
-
_status = SCCourseJoinStatusType.JOINED;
|
|
78
|
-
break; */
|
|
79
62
|
case SCNotificationTypologyType.USER_ADDED_TO_COURSE:
|
|
80
63
|
if (dataMsg.data.notification_obj.course && ((_a = dataMsg.data.notification_obj.course.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
81
64
|
_status = SCCourseJoinStatusType.PAYMENT_WAITING;
|
|
@@ -123,67 +106,42 @@ export default function useSCJoinedCoursesManager(user) {
|
|
|
123
106
|
* Memoized join Course
|
|
124
107
|
* Toggle action
|
|
125
108
|
*/
|
|
126
|
-
const join = useMemo(() => (course,
|
|
109
|
+
const join = useMemo(() => (course) => __awaiter(this, void 0, void 0, function* () {
|
|
127
110
|
setLoading(course.id);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
135
|
-
.then((res) => {
|
|
136
|
-
if (res.status >= 300) {
|
|
137
|
-
return Promise.reject(res);
|
|
138
|
-
}
|
|
139
|
-
updateCache([course.id]);
|
|
140
|
-
setData((prev) => getDataUpdated(prev, course.id, SCCourseJoinStatusType.JOINED));
|
|
141
|
-
setUnLoading(course.id);
|
|
142
|
-
return Promise.resolve(res.data);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
return http
|
|
147
|
-
.request({
|
|
148
|
-
url: Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
|
|
149
|
-
method: Endpoints.JoinOrAcceptInviteToCourse.method,
|
|
150
|
-
})
|
|
151
|
-
.then((res) => {
|
|
152
|
-
if (res.status >= 300) {
|
|
153
|
-
return Promise.reject(res);
|
|
154
|
-
}
|
|
155
|
-
updateCache([course.id]);
|
|
156
|
-
setData((prev) => getDataUpdated(prev, course.id, course.privacy === SCCoursePrivacyType.PRIVATE && course.join_status !== SCCourseJoinStatusType.INVITED
|
|
157
|
-
? SCCourseJoinStatusType.REQUESTED
|
|
158
|
-
: SCCourseJoinStatusType.JOINED));
|
|
159
|
-
setUnLoading(course.id);
|
|
160
|
-
return Promise.resolve(res.data);
|
|
161
|
-
});
|
|
111
|
+
const res = yield http.request({
|
|
112
|
+
url: Endpoints.JoinOrAcceptInviteToCourse.url({ id: course.id }),
|
|
113
|
+
method: Endpoints.JoinOrAcceptInviteToCourse.method,
|
|
114
|
+
});
|
|
115
|
+
if (res.status >= 300) {
|
|
116
|
+
return Promise.reject(res);
|
|
162
117
|
}
|
|
163
|
-
|
|
118
|
+
updateCache([course.id]);
|
|
119
|
+
setData((prev) => getDataUpdated(prev, course.id, course.privacy === SCCoursePrivacyType.PRIVATE && course.join_status !== SCCourseJoinStatusType.INVITED
|
|
120
|
+
? SCCourseJoinStatusType.REQUESTED
|
|
121
|
+
: SCCourseJoinStatusType.JOINED));
|
|
122
|
+
setUnLoading(course.id);
|
|
123
|
+
return yield Promise.resolve(res.data);
|
|
124
|
+
}), [data, loading, cache]);
|
|
164
125
|
/**
|
|
165
126
|
* Memoized leave Course
|
|
166
127
|
* Toggle action
|
|
167
128
|
*/
|
|
168
|
-
const leave = useMemo(() => (course) => {
|
|
169
|
-
if (course.
|
|
129
|
+
const leave = useMemo(() => (course) => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (data[course.id] !== SCCourseJoinStatusType.REQUESTED) {
|
|
170
131
|
setLoading(course.id);
|
|
171
|
-
|
|
172
|
-
.request({
|
|
132
|
+
const res = yield http.request({
|
|
173
133
|
url: Endpoints.LeaveOrRemoveCourseRequest.url({ id: course.id }),
|
|
174
134
|
method: Endpoints.LeaveOrRemoveCourseRequest.method,
|
|
175
|
-
})
|
|
176
|
-
.then((res) => {
|
|
177
|
-
if (res.status >= 300) {
|
|
178
|
-
return Promise.reject(res);
|
|
179
|
-
}
|
|
180
|
-
updateCache([course.id]);
|
|
181
|
-
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
182
|
-
setUnLoading(course.id);
|
|
183
|
-
return Promise.resolve(res.data);
|
|
184
135
|
});
|
|
136
|
+
if (res.status >= 300) {
|
|
137
|
+
return Promise.reject(res);
|
|
138
|
+
}
|
|
139
|
+
updateCache([course.id]);
|
|
140
|
+
setData((prev) => getDataUpdated(prev, course.id, null));
|
|
141
|
+
setUnLoading(course.id);
|
|
142
|
+
return yield Promise.resolve(res.data);
|
|
185
143
|
}
|
|
186
|
-
}, [data, loading, cache]);
|
|
144
|
+
}), [data, loading, cache]);
|
|
187
145
|
/**
|
|
188
146
|
* Check the authenticated user subscription status to the course
|
|
189
147
|
* Update the courses cached
|
|
@@ -42,20 +42,9 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
42
42
|
*/
|
|
43
43
|
useDeepCompareEffectNoCheck(() => {
|
|
44
44
|
notificationInvitedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
45
|
-
/* notificationRequestedToJoinEvent.current = PubSub.subscribe(
|
|
46
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`,
|
|
47
|
-
notificationSubscriber
|
|
48
|
-
);
|
|
49
|
-
notificationAcceptedToJoinEvent.current = PubSub.subscribe(
|
|
50
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`,
|
|
51
|
-
notificationSubscriber
|
|
52
|
-
);
|
|
53
|
-
*/
|
|
54
45
|
notificationAddedToEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
|
|
55
46
|
return () => {
|
|
56
47
|
PubSub.unsubscribe(notificationInvitedToJoinEvent.current);
|
|
57
|
-
// PubSub.unsubscribe(notificationRequestedToJoinEvent.current);
|
|
58
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinEvent.current);
|
|
59
48
|
PubSub.unsubscribe(notificationAddedToEvent.current);
|
|
60
49
|
};
|
|
61
50
|
}, [data]);
|
|
@@ -71,12 +60,6 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
71
60
|
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
|
|
72
61
|
_status = SCEventSubscriptionStatusType.INVITED;
|
|
73
62
|
break;
|
|
74
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
|
|
75
|
-
_status = SCEventSubscriptionStatusType.REQUESTED;
|
|
76
|
-
break;
|
|
77
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
|
|
78
|
-
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
79
|
-
break; */
|
|
80
63
|
case SCNotificationTypologyType.USER_ADDED_TO_EVENT:
|
|
81
64
|
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
82
65
|
break;
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
subscribe: (group: SCGroupType
|
|
33
|
+
subscribe: (group: SCGroupType) => Promise<any>;
|
|
34
34
|
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -34,29 +34,15 @@ export default function useSCSubscribedGroupsManager(user) {
|
|
|
34
34
|
CONFIGURATIONS_GROUPS_ENABLED in preferences &&
|
|
35
35
|
preferences[CONFIGURATIONS_GROUPS_ENABLED].value, [preferences, features]);
|
|
36
36
|
const notificationInvitedToJoinGroup = useRef(null);
|
|
37
|
-
// const notificationRequestedToJoinGroup = useRef(null);
|
|
38
|
-
// const notificationAcceptedToJoinGroup = useRef(null);
|
|
39
37
|
const notificationAddedToGroup = useRef(null);
|
|
40
38
|
/**
|
|
41
39
|
* Subscribe to notification types user_follow, user_unfollow
|
|
42
40
|
*/
|
|
43
41
|
useDeepCompareEffectNoCheck(() => {
|
|
44
42
|
notificationInvitedToJoinGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP}`, notificationSubscriber);
|
|
45
|
-
/*
|
|
46
|
-
notificationRequestedToJoinGroup.current = PubSub.subscribe(
|
|
47
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP}`,
|
|
48
|
-
notificationSubscriber
|
|
49
|
-
);
|
|
50
|
-
notificationAcceptedToJoinGroup.current = PubSub.subscribe(
|
|
51
|
-
`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP}`,
|
|
52
|
-
notificationSubscriber
|
|
53
|
-
);
|
|
54
|
-
*/
|
|
55
43
|
notificationAddedToGroup.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_GROUP}`, notificationSubscriber);
|
|
56
44
|
return () => {
|
|
57
45
|
PubSub.unsubscribe(notificationInvitedToJoinGroup.current);
|
|
58
|
-
// PubSub.unsubscribe(notificationRequestedToJoinGroup.current);
|
|
59
|
-
// PubSub.unsubscribe(notificationAcceptedToJoinGroup.current);
|
|
60
46
|
PubSub.unsubscribe(notificationAddedToGroup.current);
|
|
61
47
|
};
|
|
62
48
|
}, [data]);
|
|
@@ -73,12 +59,6 @@ export default function useSCSubscribedGroupsManager(user) {
|
|
|
73
59
|
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP:
|
|
74
60
|
_status = SCGroupSubscriptionStatusType.INVITED;
|
|
75
61
|
break;
|
|
76
|
-
/* case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP:
|
|
77
|
-
_status = SCGroupSubscriptionStatusType.REQUESTED;
|
|
78
|
-
break;
|
|
79
|
-
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP:
|
|
80
|
-
_status = SCGroupSubscriptionStatusType.SUBSCRIBED;
|
|
81
|
-
break; */
|
|
82
62
|
case SCNotificationTypologyType.USER_ADDED_TO_GROUP:
|
|
83
63
|
if (dataMsg.data.notification_obj.group && ((_a = dataMsg.data.notification_obj.group.paywalls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
84
64
|
_status = SCGroupSubscriptionStatusType.PAYMENT_WAITING;
|
|
@@ -126,50 +106,31 @@ export default function useSCSubscribedGroupsManager(user) {
|
|
|
126
106
|
* Memoized subscribe Group
|
|
127
107
|
* Toggle action
|
|
128
108
|
*/
|
|
129
|
-
const subscribe = useMemo(() => (group
|
|
109
|
+
const subscribe = useMemo(() => (group) => {
|
|
130
110
|
setLoading(group.id);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
return http
|
|
150
|
-
.request({
|
|
151
|
-
url: Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
152
|
-
method: Endpoints.SubscribeToGroup.method,
|
|
153
|
-
})
|
|
154
|
-
.then((res) => {
|
|
155
|
-
if (res.status >= 300) {
|
|
156
|
-
return Promise.reject(res);
|
|
157
|
-
}
|
|
158
|
-
updateCache([group.id]);
|
|
159
|
-
setData((prev) => getDataUpdated(prev, group.id, group.privacy === SCGroupPrivacyType.PRIVATE && group.subscription_status !== SCGroupSubscriptionStatusType.INVITED
|
|
160
|
-
? SCGroupSubscriptionStatusType.REQUESTED
|
|
161
|
-
: SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
162
|
-
setUnLoading(group.id);
|
|
163
|
-
return Promise.resolve(res.data);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
111
|
+
return http
|
|
112
|
+
.request({
|
|
113
|
+
url: Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
114
|
+
method: Endpoints.SubscribeToGroup.method,
|
|
115
|
+
})
|
|
116
|
+
.then((res) => {
|
|
117
|
+
if (res.status >= 300) {
|
|
118
|
+
return Promise.reject(res);
|
|
119
|
+
}
|
|
120
|
+
updateCache([group.id]);
|
|
121
|
+
setData((prev) => getDataUpdated(prev, group.id, group.privacy === SCGroupPrivacyType.PRIVATE && group.subscription_status !== SCGroupSubscriptionStatusType.INVITED
|
|
122
|
+
? SCGroupSubscriptionStatusType.REQUESTED
|
|
123
|
+
: SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
124
|
+
setUnLoading(group.id);
|
|
125
|
+
return Promise.resolve(res.data);
|
|
126
|
+
});
|
|
166
127
|
}, [data, loading, cache]);
|
|
167
128
|
/**
|
|
168
129
|
* Memoized subscribe Group
|
|
169
130
|
* Toggle action
|
|
170
131
|
*/
|
|
171
132
|
const unsubscribe = useMemo(() => (group) => {
|
|
172
|
-
if (group.
|
|
133
|
+
if (data[group.id] !== SCGroupSubscriptionStatusType.REQUESTED) {
|
|
173
134
|
setLoading(group.id);
|
|
174
135
|
return http
|
|
175
136
|
.request({
|