@selfcommunity/react-core 0.4.50-events.38 → 0.4.50-events.40
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/SCPreferencesProvider/index.js +2 -1
- package/lib/cjs/components/provider/SCUserProvider/index.js +6 -0
- package/lib/cjs/constants/Cache.d.ts +1 -0
- package/lib/cjs/constants/Cache.js +3 -2
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.js +15 -5
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +283 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/types/context.d.ts +40 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +2 -1
- package/lib/esm/components/provider/SCUserProvider/index.js +6 -0
- package/lib/esm/constants/Cache.d.ts +1 -0
- package/lib/esm/constants/Cache.js +1 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/esm/hooks/useSCFetchEvent.js +16 -6
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +279 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/types/context.d.ts +40 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCPreferences = exports.SCPreferencesContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
5
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
6
|
const utils_1 = require("@selfcommunity/utils");
|
|
7
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
8
8
|
const Errors_1 = require("../../../constants/Errors");
|
|
9
9
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
10
10
|
/**
|
|
@@ -54,6 +54,7 @@ function SCPreferencesProvider({ children = null }) {
|
|
|
54
54
|
.catch((_error) => {
|
|
55
55
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, _error);
|
|
56
56
|
setError(_error);
|
|
57
|
+
// setLoading(false);
|
|
57
58
|
});
|
|
58
59
|
}, []);
|
|
59
60
|
/**
|
|
@@ -20,6 +20,7 @@ const useSCSubscribedIncubatorsManager_1 = tslib_1.__importDefault(require("../.
|
|
|
20
20
|
const useSCBlockedUsersManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCBlockedUsersManager"));
|
|
21
21
|
const Session = tslib_1.__importStar(require("../../../constants/Session"));
|
|
22
22
|
const useSCSubscribedGroupsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedGroupsManager"));
|
|
23
|
+
const useSCSubscribedEventsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedEventsManager"));
|
|
23
24
|
/**
|
|
24
25
|
* SCUserContext (Authentication Context)
|
|
25
26
|
*
|
|
@@ -72,6 +73,7 @@ function SCUserProvider({ children }) {
|
|
|
72
73
|
const categoriesManager = (0, useSCFollowedCategoriesManager_1.default)(state.user, updateUser);
|
|
73
74
|
const blockedUsersManager = (0, useSCBlockedUsersManager_1.default)(state.user);
|
|
74
75
|
const subscribedGroupsManager = (0, useSCSubscribedGroupsManager_1.default)(state.user);
|
|
76
|
+
const subscribedEventsManager = (0, useSCSubscribedEventsManager_1.default)(state.user);
|
|
75
77
|
/**
|
|
76
78
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
77
79
|
*/
|
|
@@ -123,6 +125,7 @@ function SCUserProvider({ children }) {
|
|
|
123
125
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
124
126
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
125
127
|
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
128
|
+
subscribedEventsManager.refresh && subscribedEventsManager.refresh();
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
/**
|
|
@@ -219,6 +222,7 @@ function SCUserProvider({ children }) {
|
|
|
219
222
|
incubators: subscribedIncubatorsManager,
|
|
220
223
|
blockedUsers: blockedUsersManager,
|
|
221
224
|
groups: subscribedGroupsManager,
|
|
225
|
+
events: subscribedEventsManager,
|
|
222
226
|
},
|
|
223
227
|
}), [
|
|
224
228
|
state,
|
|
@@ -237,6 +241,8 @@ function SCUserProvider({ children }) {
|
|
|
237
241
|
subscribedIncubatorsManager.incubators,
|
|
238
242
|
subscribedGroupsManager.loading,
|
|
239
243
|
subscribedGroupsManager.groups,
|
|
244
|
+
subscribedEventsManager.loading,
|
|
245
|
+
subscribedEventsManager.events,
|
|
240
246
|
]);
|
|
241
247
|
/**
|
|
242
248
|
* We only want to render the underlying app after we
|
|
@@ -61,6 +61,7 @@ export declare const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_cSug
|
|
|
61
61
|
export declare const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = "_cPopWidget_";
|
|
62
62
|
export declare const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFolWidget_";
|
|
63
63
|
export declare const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFoldWidget_";
|
|
64
|
+
export declare const USER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uEvents_";
|
|
64
65
|
export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
|
|
65
66
|
export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
|
|
66
67
|
export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Cache prefixes
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
6
|
+
exports.RELATED_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.getPmSnippetObjectCacheKey = exports.PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY = exports.getPmSnippetsObjectCacheKey = exports.PM_SNIPPETS_OBJECT_CACHE_PREFIX_KEY = exports.getAdvObjectCacheKey = exports.ADV_OBJECT_CACHE_PREFIX_KEY = exports.getFeedSPCacheKey = exports.FEED_CACHE_SP_KEY = exports.getVirtualizedScrollStateCacheKey = exports.VIRTUALIZED_SCROLL_STATE_CACHE_PREFIX_KEY = exports.getStateFeedCacheKey = exports.FEED_STATE_CACHE_PREFIX_KEY = exports.getFeedCacheKey = exports.FEED_CACHE_PREFIX_KEY = exports.getBroadcastMessagesObjectCacheKey = exports.BROADCAST_MESSAGES_OBJECT_CACHE_PREFIX_KEY = exports.getContributorsCachePrefixKeys = exports.getContributorsCacheKey = exports.CONTRIBUTORS_CACHE_PREFIX_KEY = exports.getIncubatorObjectCacheKey = exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = exports.getGroupsObjectCacheKey = exports.GROUPS_OBJECT_CACHE_PREFIX_KEY = exports.getGroupObjectCacheKey = exports.GROUP_OBJECT_CACHE_PREFIX_KEY = exports.getEventObjectCacheKey = exports.EVENT_OBJECT_CACHE_PREFIX_KEY = exports.getCategoryObjectCacheKey = exports.CATEGORY_OBJECT_CACHE_PREFIX_KEY = exports.getCategoriesObjectCacheKey = exports.CATEGORIES_OBJECT_CACHE_PREFIX_KEY = exports.getCommentObjectsCachePrefixKeys = exports.getCommentObjectsCacheKey = exports.COMMENT_OBJECTS_CACHE_PREFIX_KEY = exports.getCommentObjectCacheKey = exports.COMMENT_OBJECT_CACHE_PREFIX_KEY = exports.getFeedObjectCacheKey = exports.FEED_OBJECT_CACHE_PREFIX_KEY = void 0;
|
|
7
|
+
exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_PEOPLE_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
8
8
|
/** FEED OBJECT **/
|
|
9
9
|
exports.FEED_OBJECT_CACHE_PREFIX_KEY = '_fo_';
|
|
10
10
|
const getFeedObjectCacheKey = (id, type) => `${exports.FEED_OBJECT_CACHE_PREFIX_KEY}${type}_${id}`;
|
|
@@ -89,6 +89,7 @@ exports.CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_cSugWidget_';
|
|
|
89
89
|
exports.CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = '_cPopWidget_';
|
|
90
90
|
exports.USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFolWidget_';
|
|
91
91
|
exports.USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFoldWidget_';
|
|
92
|
+
exports.USER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uEvents_';
|
|
92
93
|
exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
|
|
93
94
|
exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
|
|
94
95
|
exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
|
|
@@ -7,11 +7,13 @@ import { CacheStrategies } from '@selfcommunity/utils';
|
|
|
7
7
|
* @param object
|
|
8
8
|
* @param object.id
|
|
9
9
|
* @param object.event
|
|
10
|
+
* @param object.autosubscribe
|
|
10
11
|
* @param object.cacheStrategy
|
|
11
12
|
*/
|
|
12
|
-
export default function useSCFetchEvent({ id, event, cacheStrategy, }: {
|
|
13
|
+
export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrategy, }: {
|
|
13
14
|
id?: number | string;
|
|
14
15
|
event?: SCEventType;
|
|
16
|
+
autoSubscribe?: boolean;
|
|
15
17
|
cacheStrategy?: CacheStrategies;
|
|
16
18
|
}): {
|
|
17
19
|
scEvent: SCEventType;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const Errors_1 = require("../constants/Errors");
|
|
5
|
+
const types_1 = require("@selfcommunity/types");
|
|
5
6
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
7
|
const utils_1 = require("@selfcommunity/utils");
|
|
7
8
|
const Cache_1 = require("../constants/Cache");
|
|
@@ -14,9 +15,10 @@ const SCUserProvider_1 = require("../components/provider/SCUserProvider");
|
|
|
14
15
|
* @param object
|
|
15
16
|
* @param object.id
|
|
16
17
|
* @param object.event
|
|
18
|
+
* @param object.autosubscribe
|
|
17
19
|
* @param object.cacheStrategy
|
|
18
20
|
*/
|
|
19
|
-
function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
21
|
+
function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
20
22
|
const __eventId = event ? event.id : id;
|
|
21
23
|
// CONTEXT
|
|
22
24
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
@@ -51,10 +53,18 @@ function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.Cach
|
|
|
51
53
|
* If id attempt to get the event by id
|
|
52
54
|
*/
|
|
53
55
|
(0, react_1.useEffect)(() => {
|
|
54
|
-
if (__eventId && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
|
|
56
|
+
if (__eventId && scUserContext.user !== undefined && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
|
|
55
57
|
fetchEvent()
|
|
56
|
-
.then((
|
|
57
|
-
|
|
58
|
+
.then((event) => {
|
|
59
|
+
if (autoSubscribe && authUserId !== null && event.privacy === types_1.SCEventPrivacyType.PUBLIC && !event.subscription_status) {
|
|
60
|
+
// Auto subscribe the event
|
|
61
|
+
api_services_1.EventService.subscribeToEvent(event.id).then(() => {
|
|
62
|
+
setSCEvent(event);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setSCEvent(event);
|
|
67
|
+
}
|
|
58
68
|
})
|
|
59
69
|
.catch((err) => {
|
|
60
70
|
utils_1.LRUCache.delete(__eventCacheKey);
|
|
@@ -63,7 +73,7 @@ function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.Cach
|
|
|
63
73
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
64
74
|
});
|
|
65
75
|
}
|
|
66
|
-
}, [__eventId, authUserId]);
|
|
76
|
+
}, [__eventId, authUserId, scUserContext.user]);
|
|
67
77
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
68
78
|
if (event) {
|
|
69
79
|
setSCEvent(event);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SCEventType, SCUserType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to manage the events followed.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
:::tip How to use it:
|
|
8
|
+
Follow these steps:
|
|
9
|
+
```jsx
|
|
10
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
11
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
12
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
*/
|
|
16
|
+
export default function useSCSubscribedEventsManager(user?: SCUserType): {
|
|
17
|
+
events: any[];
|
|
18
|
+
loading: any[];
|
|
19
|
+
isLoading: (v: number | {
|
|
20
|
+
id: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
toggleEventAttendance?: undefined;
|
|
23
|
+
toggleEventNonattendance?: undefined;
|
|
24
|
+
subscriptionStatus?: undefined;
|
|
25
|
+
refresh?: undefined;
|
|
26
|
+
emptyCache?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
events: any[];
|
|
29
|
+
loading: any[];
|
|
30
|
+
isLoading: (v: number | {
|
|
31
|
+
id: number;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
toggleEventAttendance: (event: SCEventType, userId?: number) => Promise<any>;
|
|
34
|
+
toggleEventNonattendance: (event: SCEventType) => Promise<any>;
|
|
35
|
+
subscriptionStatus: (event: SCEventType) => string;
|
|
36
|
+
refresh: () => void;
|
|
37
|
+
emptyCache: () => void;
|
|
38
|
+
};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
|
+
const types_1 = require("@selfcommunity/types");
|
|
7
|
+
const useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
8
|
+
const Errors_1 = require("../constants/Errors");
|
|
9
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
10
|
+
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
11
|
+
const Notification_1 = require("../constants/Notification");
|
|
12
|
+
const use_deep_compare_effect_1 = require("use-deep-compare-effect");
|
|
13
|
+
const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
|
|
14
|
+
/**
|
|
15
|
+
:::info
|
|
16
|
+
This custom hook is used to manage the events followed.
|
|
17
|
+
:::
|
|
18
|
+
|
|
19
|
+
:::tip How to use it:
|
|
20
|
+
Follow these steps:
|
|
21
|
+
```jsx
|
|
22
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
23
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
24
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
25
|
+
```
|
|
26
|
+
:::
|
|
27
|
+
*/
|
|
28
|
+
function useSCSubscribedEventsManager(user) {
|
|
29
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = (0, useSCCachingManager_1.default)();
|
|
30
|
+
const { features } = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
31
|
+
const authUserId = user ? user.id : null;
|
|
32
|
+
const eventsEnabled = (0, react_1.useMemo)(() => features && features.includes(types_1.SCFeatureName.EVENT) && features.includes(types_1.SCFeatureName.TAGGING), [features]);
|
|
33
|
+
const notificationInvitedToJoinEvent = (0, react_1.useRef)(null);
|
|
34
|
+
const notificationRequestedToJoinEvent = (0, react_1.useRef)(null);
|
|
35
|
+
const notificationAcceptedToJoinEvent = (0, react_1.useRef)(null);
|
|
36
|
+
const notificationAddedToEvent = (0, react_1.useRef)(null);
|
|
37
|
+
/**
|
|
38
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
39
|
+
*/
|
|
40
|
+
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
41
|
+
notificationInvitedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
42
|
+
notificationRequestedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
43
|
+
notificationAcceptedToJoinEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
44
|
+
notificationAddedToEvent.current = pubsub_js_1.default.subscribe(`${types_1.SCNotificationTopicType.INTERACTION}.${types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
|
|
45
|
+
return () => {
|
|
46
|
+
pubsub_js_1.default.unsubscribe(notificationInvitedToJoinEvent.current);
|
|
47
|
+
pubsub_js_1.default.unsubscribe(notificationRequestedToJoinEvent.current);
|
|
48
|
+
pubsub_js_1.default.unsubscribe(notificationAcceptedToJoinEvent.current);
|
|
49
|
+
pubsub_js_1.default.unsubscribe(notificationAddedToEvent.current);
|
|
50
|
+
};
|
|
51
|
+
}, [data]);
|
|
52
|
+
/**
|
|
53
|
+
* Notification subscriber handler
|
|
54
|
+
* @param msg
|
|
55
|
+
* @param dataMsg
|
|
56
|
+
*/
|
|
57
|
+
const notificationSubscriber = (msg, dataMsg) => {
|
|
58
|
+
if (dataMsg.data.event !== undefined) {
|
|
59
|
+
let _status;
|
|
60
|
+
switch (Notification_1.SCNotificationMapping[dataMsg.data.activity_type]) {
|
|
61
|
+
case types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
|
|
62
|
+
_status = types_1.SCEventSubscriptionStatusType.INVITED;
|
|
63
|
+
break;
|
|
64
|
+
case types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
|
|
65
|
+
_status = types_1.SCEventSubscriptionStatusType.REQUESTED;
|
|
66
|
+
break;
|
|
67
|
+
case types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
|
|
68
|
+
_status = types_1.SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
69
|
+
break;
|
|
70
|
+
case types_1.SCNotificationTypologyType.USER_ADDED_TO_EVENT:
|
|
71
|
+
_status = types_1.SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
updateCache([dataMsg.data.event.id]);
|
|
75
|
+
setData((prev) => getDataUpdated(prev, dataMsg.data.event.id, _status));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Memoized refresh all events
|
|
80
|
+
* It makes a single request to the server and retrieves
|
|
81
|
+
* all the events followed by the user in a single solution
|
|
82
|
+
* It might be useful for multi-tab sync
|
|
83
|
+
*/
|
|
84
|
+
const refresh = (0, react_1.useMemo)(() => () => {
|
|
85
|
+
emptyCache();
|
|
86
|
+
if (user) {
|
|
87
|
+
// Only if user is authenticated
|
|
88
|
+
api_services_1.http
|
|
89
|
+
.request({
|
|
90
|
+
url: api_services_1.Endpoints.GetUserEvents.url(),
|
|
91
|
+
method: api_services_1.Endpoints.GetUserEvents.method,
|
|
92
|
+
})
|
|
93
|
+
.then((res) => {
|
|
94
|
+
if (res.status >= 300) {
|
|
95
|
+
return Promise.reject(res);
|
|
96
|
+
}
|
|
97
|
+
const eventsIds = res.data.results.map((e) => e.id);
|
|
98
|
+
updateCache(eventsIds);
|
|
99
|
+
setData(res.data.results.map((e) => ({ [e.id]: e.subscription_status })));
|
|
100
|
+
return Promise.resolve(res.data);
|
|
101
|
+
})
|
|
102
|
+
.catch((e) => {
|
|
103
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to refresh the authenticated user events.');
|
|
104
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, e);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}, [data, user, cache]);
|
|
108
|
+
/**
|
|
109
|
+
* Memoized toggleEventAttendance Event
|
|
110
|
+
* Toggle action
|
|
111
|
+
*/
|
|
112
|
+
const toggleEventAttendance = (0, react_1.useMemo)(() => (event, userId) => {
|
|
113
|
+
setLoading(event.id);
|
|
114
|
+
if (userId) {
|
|
115
|
+
return api_services_1.http
|
|
116
|
+
.request({
|
|
117
|
+
url: api_services_1.Endpoints.InviteOrAcceptEventRequest.url({ id: event.id }),
|
|
118
|
+
method: api_services_1.Endpoints.InviteOrAcceptEventRequest.method,
|
|
119
|
+
data: { users: [userId] },
|
|
120
|
+
})
|
|
121
|
+
.then((res) => {
|
|
122
|
+
if (res.status >= 300) {
|
|
123
|
+
return Promise.reject(res);
|
|
124
|
+
}
|
|
125
|
+
updateCache([event.id]);
|
|
126
|
+
setData((prev) => getDataUpdated(prev, event.id, types_1.SCEventSubscriptionStatusType.SUBSCRIBED));
|
|
127
|
+
setUnLoading(event.id);
|
|
128
|
+
return Promise.resolve(res.data);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const requestConfig = event.subscription_status === types_1.SCEventSubscriptionStatusType.GOING
|
|
133
|
+
? {
|
|
134
|
+
url: api_services_1.Endpoints.RemoveGoingToEvent.url({ id: event.id }),
|
|
135
|
+
method: api_services_1.Endpoints.RemoveGoingToEvent.method,
|
|
136
|
+
}
|
|
137
|
+
: {
|
|
138
|
+
url: api_services_1.Endpoints.GoToEvent.url({ id: event.id }),
|
|
139
|
+
method: api_services_1.Endpoints.GoToEvent.method,
|
|
140
|
+
};
|
|
141
|
+
return api_services_1.http.request(requestConfig).then((res) => {
|
|
142
|
+
if (res.status >= 300) {
|
|
143
|
+
return Promise.reject(res);
|
|
144
|
+
}
|
|
145
|
+
updateCache([event.id]);
|
|
146
|
+
setData((prev) => getDataUpdated(prev, event.id, event.privacy === types_1.SCEventPrivacyType.PRIVATE && event.subscription_status !== types_1.SCEventSubscriptionStatusType.INVITED
|
|
147
|
+
? types_1.SCEventSubscriptionStatusType.REQUESTED
|
|
148
|
+
: event.subscription_status === types_1.SCEventSubscriptionStatusType.GOING
|
|
149
|
+
? types_1.SCEventSubscriptionStatusType.SUBSCRIBED
|
|
150
|
+
: types_1.SCEventSubscriptionStatusType.GOING));
|
|
151
|
+
setUnLoading(event.id);
|
|
152
|
+
return Promise.resolve(res.data);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, [data, loading, cache]);
|
|
156
|
+
/**
|
|
157
|
+
* Memoized toggleEventNonattendance Event
|
|
158
|
+
* Toggle action
|
|
159
|
+
*/
|
|
160
|
+
const toggleEventNonattendance = (0, react_1.useMemo)(() => (event) => {
|
|
161
|
+
if (event.subscription_status !== types_1.SCEventSubscriptionStatusType.REQUESTED) {
|
|
162
|
+
setLoading(event.id);
|
|
163
|
+
const requestConfig = event.subscription_status === types_1.SCEventSubscriptionStatusType.NOT_GOING
|
|
164
|
+
? {
|
|
165
|
+
url: api_services_1.Endpoints.RemoveNotGoingToEvent.url({ id: event.id }),
|
|
166
|
+
method: api_services_1.Endpoints.RemoveNotGoingToEvent.method,
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
url: api_services_1.Endpoints.NotGoingToEvent.url({ id: event.id }),
|
|
170
|
+
method: api_services_1.Endpoints.NotGoingToEvent.method,
|
|
171
|
+
};
|
|
172
|
+
return api_services_1.http.request(requestConfig).then((res) => {
|
|
173
|
+
if (res.status >= 300) {
|
|
174
|
+
return Promise.reject(res);
|
|
175
|
+
}
|
|
176
|
+
updateCache([event.id]);
|
|
177
|
+
setData((prev) => getDataUpdated(prev, event.id, event.subscription_status === types_1.SCEventSubscriptionStatusType.NOT_GOING
|
|
178
|
+
? types_1.SCEventSubscriptionStatusType.SUBSCRIBED
|
|
179
|
+
: types_1.SCEventSubscriptionStatusType.NOT_GOING));
|
|
180
|
+
setUnLoading(event.id);
|
|
181
|
+
return Promise.resolve(res.data);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}, [data, loading, cache]);
|
|
185
|
+
/**
|
|
186
|
+
* Check the authenticated user subscription status to the event
|
|
187
|
+
* Update the events cached
|
|
188
|
+
* Update events subscription statuses
|
|
189
|
+
* @param event
|
|
190
|
+
*/
|
|
191
|
+
const checkEventSubscriptionStatus = (event) => {
|
|
192
|
+
setLoading(event.id);
|
|
193
|
+
return api_services_1.http
|
|
194
|
+
.request({
|
|
195
|
+
url: api_services_1.Endpoints.GetEventSubscriptionStatus.url({ id: event.id }),
|
|
196
|
+
method: api_services_1.Endpoints.GetEventSubscriptionStatus.method,
|
|
197
|
+
})
|
|
198
|
+
.then((res) => {
|
|
199
|
+
if (res.status >= 300) {
|
|
200
|
+
return Promise.reject(res);
|
|
201
|
+
}
|
|
202
|
+
setData((prev) => getDataUpdated(prev, event.id, res.data.status));
|
|
203
|
+
updateCache([event.id]);
|
|
204
|
+
setUnLoading(event.id);
|
|
205
|
+
return Promise.resolve(res.data);
|
|
206
|
+
})
|
|
207
|
+
.catch((e) => {
|
|
208
|
+
setUnLoading(event.id);
|
|
209
|
+
return Promise.reject(e);
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Get updated data
|
|
214
|
+
* @param data
|
|
215
|
+
* @param eventId
|
|
216
|
+
* @param subscriptionStatus
|
|
217
|
+
*/
|
|
218
|
+
const getDataUpdated = (data, eventId, subscriptionStatus) => {
|
|
219
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === eventId);
|
|
220
|
+
let _data;
|
|
221
|
+
if (_index < 0) {
|
|
222
|
+
_data = [...data, ...[{ [eventId]: subscriptionStatus }]];
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
_data = data.map((k, i) => {
|
|
226
|
+
if (parseInt(Object.keys(k)[0]) === eventId) {
|
|
227
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
228
|
+
}
|
|
229
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return _data;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Return current event subscription status if exists,
|
|
236
|
+
* otherwise return null
|
|
237
|
+
*/
|
|
238
|
+
const getCurrentEventCacheStatus = (0, react_1.useMemo)(() => (event) => {
|
|
239
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === event.id);
|
|
240
|
+
return d.length ? d[0][event.id] : !data.length ? event.subscription_status : null;
|
|
241
|
+
}, [data]);
|
|
242
|
+
/**
|
|
243
|
+
* Bypass remote check if the event is subscribed
|
|
244
|
+
*/
|
|
245
|
+
const getSubscriptionStatus = (0, react_1.useMemo)(() => (event) => {
|
|
246
|
+
updateCache([event.id]);
|
|
247
|
+
setData((prev) => getDataUpdated(prev, event.id, event.subscription_status));
|
|
248
|
+
return event.subscription_status;
|
|
249
|
+
}, [data, cache]);
|
|
250
|
+
/**
|
|
251
|
+
* Memoized subscriptionStatus
|
|
252
|
+
* If event is already in cache -> check if the event is in events,
|
|
253
|
+
* otherwise, check if user toggleEventAttendance the event
|
|
254
|
+
*/
|
|
255
|
+
const subscriptionStatus = (0, react_1.useMemo)(() => (event) => {
|
|
256
|
+
// Cache is valid also for anonymous user
|
|
257
|
+
if (cache.includes(event === null || event === void 0 ? void 0 : event.id)) {
|
|
258
|
+
return getCurrentEventCacheStatus(event);
|
|
259
|
+
}
|
|
260
|
+
if (authUserId) {
|
|
261
|
+
if ('subscription_status' in event) {
|
|
262
|
+
return getSubscriptionStatus(event);
|
|
263
|
+
}
|
|
264
|
+
if (!isLoading(event)) {
|
|
265
|
+
checkEventSubscriptionStatus(event);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}, [loading, cache, authUserId]);
|
|
270
|
+
/**
|
|
271
|
+
* Empty cache on logout
|
|
272
|
+
*/
|
|
273
|
+
(0, react_1.useEffect)(() => {
|
|
274
|
+
if (!authUserId) {
|
|
275
|
+
emptyCache();
|
|
276
|
+
}
|
|
277
|
+
}, [authUserId]);
|
|
278
|
+
if (!eventsEnabled || !user) {
|
|
279
|
+
return { events: data, loading, isLoading };
|
|
280
|
+
}
|
|
281
|
+
return { events: data, loading, isLoading, toggleEventAttendance, toggleEventNonattendance, subscriptionStatus, refresh, emptyCache };
|
|
282
|
+
}
|
|
283
|
+
exports.default = useSCSubscribedEventsManager;
|
package/lib/cjs/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 } 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 } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -82,4 +82,4 @@ import * as Locale from './constants/Locale';
|
|
|
82
82
|
/**
|
|
83
83
|
* List all exports
|
|
84
84
|
*/
|
|
85
|
-
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, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent };
|
|
85
|
+
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, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -147,6 +147,7 @@ export interface SCUserContextType {
|
|
|
147
147
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
148
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
149
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
|
+
events?: SCSubscribedEventsManagerType;
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
export interface SCSettingsManagerType {
|
|
@@ -253,6 +254,44 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
253
254
|
*/
|
|
254
255
|
emptyCache?: () => void;
|
|
255
256
|
}
|
|
257
|
+
export interface SCSubscribedEventsManagerType {
|
|
258
|
+
/**
|
|
259
|
+
* List of all events ids followed by the authenticated user
|
|
260
|
+
*/
|
|
261
|
+
events: number[];
|
|
262
|
+
/**
|
|
263
|
+
* List of all events in loading state
|
|
264
|
+
*/
|
|
265
|
+
loading: number[];
|
|
266
|
+
/**
|
|
267
|
+
* List of current events in loading state
|
|
268
|
+
*/
|
|
269
|
+
isLoading: (event: SCEventType) => boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Handle user subscription to an event
|
|
272
|
+
*/
|
|
273
|
+
subscribe?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* Handle user going to an event
|
|
276
|
+
*/
|
|
277
|
+
toggleEventAttendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
278
|
+
/**
|
|
279
|
+
* Handle user not going to an event
|
|
280
|
+
*/
|
|
281
|
+
toggleEventNonattendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
282
|
+
/**
|
|
283
|
+
* Handles a user subscription status to an event, caching data
|
|
284
|
+
*/
|
|
285
|
+
subscriptionStatus?: (event: SCEventType) => string;
|
|
286
|
+
/**
|
|
287
|
+
* Refresh groups
|
|
288
|
+
*/
|
|
289
|
+
refresh?: () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Empty cache to revalidate all groups
|
|
292
|
+
*/
|
|
293
|
+
emptyCache?: () => void;
|
|
294
|
+
}
|
|
256
295
|
export interface SCSubscribedGroupsManagerType {
|
|
257
296
|
/**
|
|
258
297
|
* List of all groups ids followed by the authenticated user
|
package/lib/cjs/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 } 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 } 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, };
|
|
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, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
1
|
import { FeatureService, PreferenceService } from '@selfcommunity/api-services';
|
|
3
2
|
import { Logger } from '@selfcommunity/utils';
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
4
4
|
import { SCOPE_SC_CORE } from '../../../constants/Errors';
|
|
5
5
|
import { useSCContext } from '../SCContextProvider';
|
|
6
6
|
/**
|
|
@@ -50,6 +50,7 @@ export default function SCPreferencesProvider({ children = null }) {
|
|
|
50
50
|
.catch((_error) => {
|
|
51
51
|
Logger.error(SCOPE_SC_CORE, _error);
|
|
52
52
|
setError(_error);
|
|
53
|
+
// setLoading(false);
|
|
53
54
|
});
|
|
54
55
|
}, []);
|
|
55
56
|
/**
|
|
@@ -16,6 +16,7 @@ import useSCSubscribedIncubatorsManager from '../../../hooks/useSCSubscribedIncu
|
|
|
16
16
|
import useSCBlockedUsersManager from '../../../hooks/useSCBlockedUsersManager';
|
|
17
17
|
import * as Session from '../../../constants/Session';
|
|
18
18
|
import useSCSubscribedGroupsManager from '../../../hooks/useSCSubscribedGroupsManager';
|
|
19
|
+
import useSCSubscribedEventsManager from '../../../hooks/useSCSubscribedEventsManager';
|
|
19
20
|
/**
|
|
20
21
|
* SCUserContext (Authentication Context)
|
|
21
22
|
*
|
|
@@ -68,6 +69,7 @@ export default function SCUserProvider({ children }) {
|
|
|
68
69
|
const categoriesManager = useSCFollowedCategoriesManager(state.user, updateUser);
|
|
69
70
|
const blockedUsersManager = useSCBlockedUsersManager(state.user);
|
|
70
71
|
const subscribedGroupsManager = useSCSubscribedGroupsManager(state.user);
|
|
72
|
+
const subscribedEventsManager = useSCSubscribedEventsManager(state.user);
|
|
71
73
|
/**
|
|
72
74
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
73
75
|
*/
|
|
@@ -119,6 +121,7 @@ export default function SCUserProvider({ children }) {
|
|
|
119
121
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
120
122
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
121
123
|
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
124
|
+
subscribedEventsManager.refresh && subscribedEventsManager.refresh();
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
/**
|
|
@@ -215,6 +218,7 @@ export default function SCUserProvider({ children }) {
|
|
|
215
218
|
incubators: subscribedIncubatorsManager,
|
|
216
219
|
blockedUsers: blockedUsersManager,
|
|
217
220
|
groups: subscribedGroupsManager,
|
|
221
|
+
events: subscribedEventsManager,
|
|
218
222
|
},
|
|
219
223
|
}), [
|
|
220
224
|
state,
|
|
@@ -233,6 +237,8 @@ export default function SCUserProvider({ children }) {
|
|
|
233
237
|
subscribedIncubatorsManager.incubators,
|
|
234
238
|
subscribedGroupsManager.loading,
|
|
235
239
|
subscribedGroupsManager.groups,
|
|
240
|
+
subscribedEventsManager.loading,
|
|
241
|
+
subscribedEventsManager.events,
|
|
236
242
|
]);
|
|
237
243
|
/**
|
|
238
244
|
* We only want to render the underlying app after we
|
|
@@ -61,6 +61,7 @@ export declare const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_cSug
|
|
|
61
61
|
export declare const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = "_cPopWidget_";
|
|
62
62
|
export declare const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFolWidget_";
|
|
63
63
|
export declare const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFoldWidget_";
|
|
64
|
+
export declare const USER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uEvents_";
|
|
64
65
|
export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
|
|
65
66
|
export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
|
|
66
67
|
export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
|
|
@@ -65,6 +65,7 @@ export const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_cSugWidget_'
|
|
|
65
65
|
export const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = '_cPopWidget_';
|
|
66
66
|
export const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFolWidget_';
|
|
67
67
|
export const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFoldWidget_';
|
|
68
|
+
export const USER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uEvents_';
|
|
68
69
|
export const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
|
|
69
70
|
export const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
|
|
70
71
|
export const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
|