@selfcommunity/react-core 0.4.9-alpha.0 → 0.4.9-alpha.1
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/SCUserProvider/index.js +6 -0
- package/lib/cjs/constants/Cache.d.ts +5 -0
- package/lib/cjs/constants/Cache.js +8 -1
- package/lib/cjs/constants/Routes.d.ts +1 -0
- package/lib/cjs/constants/Routes.js +3 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/cjs/hooks/useSCFetchGroup.js +73 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +36 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +176 -0
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/themes/theme.js +8 -0
- package/lib/cjs/types/context.d.ts +33 -2
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/types/theme.d.ts +13 -0
- package/lib/esm/components/provider/SCUserProvider/index.js +6 -0
- package/lib/esm/constants/Cache.d.ts +5 -0
- package/lib/esm/constants/Cache.js +5 -0
- package/lib/esm/constants/Routes.d.ts +1 -0
- package/lib/esm/constants/Routes.js +2 -0
- package/lib/esm/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchGroup.js +70 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +36 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +172 -0
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +2 -1
- package/lib/esm/themes/theme.js +8 -0
- package/lib/esm/types/context.d.ts +33 -2
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/types/theme.d.ts +13 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +5 -5
|
@@ -19,6 +19,7 @@ const types_1 = require("@selfcommunity/types");
|
|
|
19
19
|
const useSCSubscribedIncubatorsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedIncubatorsManager"));
|
|
20
20
|
const useSCBlockedUsersManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCBlockedUsersManager"));
|
|
21
21
|
const Session = tslib_1.__importStar(require("../../../constants/Session"));
|
|
22
|
+
const useSCSubscribedGroupsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedGroupsManager"));
|
|
22
23
|
/**
|
|
23
24
|
* SCUserContext (Authentication Context)
|
|
24
25
|
*
|
|
@@ -70,6 +71,7 @@ function SCUserProvider({ children }) {
|
|
|
70
71
|
const connectionsManager = (0, useSCConnectionsManager_1.default)(state.user);
|
|
71
72
|
const categoriesManager = (0, useSCFollowedCategoriesManager_1.default)(state.user, updateUser);
|
|
72
73
|
const blockedUsersManager = (0, useSCBlockedUsersManager_1.default)(state.user);
|
|
74
|
+
const subscribedGroupsManager = (0, useSCSubscribedGroupsManager_1.default)(state.user);
|
|
73
75
|
/**
|
|
74
76
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
75
77
|
*/
|
|
@@ -120,6 +122,7 @@ function SCUserProvider({ children }) {
|
|
|
120
122
|
connectionsManager.refresh && connectionsManager.refresh();
|
|
121
123
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
122
124
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
125
|
+
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
@@ -215,6 +218,7 @@ function SCUserProvider({ children }) {
|
|
|
215
218
|
connections: connectionsManager,
|
|
216
219
|
incubators: subscribedIncubatorsManager,
|
|
217
220
|
blockedUsers: blockedUsersManager,
|
|
221
|
+
groups: subscribedGroupsManager,
|
|
218
222
|
},
|
|
219
223
|
}), [
|
|
220
224
|
state,
|
|
@@ -231,6 +235,8 @@ function SCUserProvider({ children }) {
|
|
|
231
235
|
blockedUsersManager.blocked,
|
|
232
236
|
subscribedIncubatorsManager.loading,
|
|
233
237
|
subscribedIncubatorsManager.incubators,
|
|
238
|
+
subscribedGroupsManager.loading,
|
|
239
|
+
subscribedGroupsManager.groups,
|
|
234
240
|
]);
|
|
235
241
|
/**
|
|
236
242
|
* We only want to render the underlying app after we
|
|
@@ -17,6 +17,9 @@ export declare const getCategoriesObjectCacheKey: () => string;
|
|
|
17
17
|
/** CATEGORY OBJECT **/
|
|
18
18
|
export declare const CATEGORY_OBJECT_CACHE_PREFIX_KEY = "_ca_";
|
|
19
19
|
export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
20
|
+
/** GROUP OBJECT **/
|
|
21
|
+
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
22
|
+
export declare const getGroupObjectCacheKey: (id: any) => string;
|
|
20
23
|
/** INCUBATOR OBJECT **/
|
|
21
24
|
export declare const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = "_inc_";
|
|
22
25
|
export declare const getIncubatorObjectCacheKey: (id: any) => string;
|
|
@@ -62,4 +65,6 @@ export declare const PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidg
|
|
|
62
65
|
export declare const INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_iListWidget_";
|
|
63
66
|
export declare const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_iSugWidget_";
|
|
64
67
|
export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget_";
|
|
68
|
+
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
69
|
+
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
65
70
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Cache prefixes
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
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 = 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_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.getGroupObjectCacheKey = exports.GROUP_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.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
7
8
|
/** FEED OBJECT **/
|
|
8
9
|
exports.FEED_OBJECT_CACHE_PREFIX_KEY = '_fo_';
|
|
9
10
|
const getFeedObjectCacheKey = (id, type) => `${exports.FEED_OBJECT_CACHE_PREFIX_KEY}${type}_${id}`;
|
|
@@ -26,6 +27,10 @@ exports.getCategoriesObjectCacheKey = getCategoriesObjectCacheKey;
|
|
|
26
27
|
exports.CATEGORY_OBJECT_CACHE_PREFIX_KEY = '_ca_';
|
|
27
28
|
const getCategoryObjectCacheKey = (id) => `${exports.CATEGORY_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
28
29
|
exports.getCategoryObjectCacheKey = getCategoryObjectCacheKey;
|
|
30
|
+
/** GROUP OBJECT **/
|
|
31
|
+
exports.GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
32
|
+
const getGroupObjectCacheKey = (id) => `${exports.GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
33
|
+
exports.getGroupObjectCacheKey = getGroupObjectCacheKey;
|
|
29
34
|
/** INCUBATOR OBJECT **/
|
|
30
35
|
exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = '_inc_';
|
|
31
36
|
const getIncubatorObjectCacheKey = (id) => `${exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -86,5 +91,7 @@ exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
|
86
91
|
exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_iListWidget_';
|
|
87
92
|
exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_iSugWidget_';
|
|
88
93
|
exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
94
|
+
exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
95
|
+
exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
89
96
|
const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
90
97
|
exports.getWidgetStateCacheKey = getWidgetStateCacheKey;
|
|
@@ -31,6 +31,7 @@ export declare const SIGNUP_ROUTE_NAME = "signup";
|
|
|
31
31
|
export declare const RECOVER_ROUTE_NAME = "recover";
|
|
32
32
|
export declare const CUSTOM_PAGES_ROUTE_NAME = "custom_pages";
|
|
33
33
|
export declare const LEGAL_PAGES_ROUTE_NAME = "legal_pages";
|
|
34
|
+
export declare const GROUP_ROUTE_NAME = "group";
|
|
34
35
|
/**
|
|
35
36
|
* Default Routes
|
|
36
37
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultRoutes = exports.LEGAL_PAGES_ROUTE_NAME = exports.CUSTOM_PAGES_ROUTE_NAME = exports.RECOVER_ROUTE_NAME = exports.SIGNUP_ROUTE_NAME = exports.SIGNIN_ROUTE_NAME = exports.INCUBATOR_ROUTE_NAME = exports.LOYALTY_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = exports.USER_PROFILE_CATEGORIES_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWERS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWINGS_ROUTE_NAME = exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = exports.USER_NOTIFICATIONS_ROUTE_NAME = exports.USER_PROFILE_SETTINGS_ROUTE_NAME = exports.USER_PROFILE_ROUTE_NAME = exports.CATEGORIES_LIST_ROUTE_NAME = exports.CATEGORY_TRENDING_FEED_ROUTE_NAME = exports.CATEGORY_ROUTE_NAME = exports.COMMENT_ROUTE_NAME = exports.STATUS_ROUTE_NAME = exports.DISCUSSION_ROUTE_NAME = exports.POST_ROUTE_NAME = exports.EXPLORE_ROUTE_NAME = exports.HOME_ROUTE_NAME = exports.ROUTER_OPTION = exports.PORTAL_OPTION = void 0;
|
|
3
|
+
exports.defaultRoutes = exports.GROUP_ROUTE_NAME = exports.LEGAL_PAGES_ROUTE_NAME = exports.CUSTOM_PAGES_ROUTE_NAME = exports.RECOVER_ROUTE_NAME = exports.SIGNUP_ROUTE_NAME = exports.SIGNIN_ROUTE_NAME = exports.INCUBATOR_ROUTE_NAME = exports.LOYALTY_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = exports.USER_PROFILE_CATEGORIES_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWERS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWINGS_ROUTE_NAME = exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = exports.USER_NOTIFICATIONS_ROUTE_NAME = exports.USER_PROFILE_SETTINGS_ROUTE_NAME = exports.USER_PROFILE_ROUTE_NAME = exports.CATEGORIES_LIST_ROUTE_NAME = exports.CATEGORY_TRENDING_FEED_ROUTE_NAME = exports.CATEGORY_ROUTE_NAME = exports.COMMENT_ROUTE_NAME = exports.STATUS_ROUTE_NAME = exports.DISCUSSION_ROUTE_NAME = exports.POST_ROUTE_NAME = exports.EXPLORE_ROUTE_NAME = exports.HOME_ROUTE_NAME = exports.ROUTER_OPTION = exports.PORTAL_OPTION = void 0;
|
|
4
4
|
exports.PORTAL_OPTION = 'portal';
|
|
5
5
|
exports.ROUTER_OPTION = 'router';
|
|
6
6
|
/**
|
|
@@ -34,6 +34,7 @@ exports.SIGNUP_ROUTE_NAME = 'signup';
|
|
|
34
34
|
exports.RECOVER_ROUTE_NAME = 'recover';
|
|
35
35
|
exports.CUSTOM_PAGES_ROUTE_NAME = 'custom_pages';
|
|
36
36
|
exports.LEGAL_PAGES_ROUTE_NAME = 'legal_pages';
|
|
37
|
+
exports.GROUP_ROUTE_NAME = 'group';
|
|
37
38
|
/**
|
|
38
39
|
* Default Routes
|
|
39
40
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -67,4 +68,5 @@ exports.defaultRoutes = {
|
|
|
67
68
|
[exports.RECOVER_ROUTE_NAME]: '/recover/',
|
|
68
69
|
[exports.CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
69
70
|
[exports.LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
71
|
+
[exports.GROUP_ROUTE_NAME]: '/group/:id/',
|
|
70
72
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
3
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
|
+
/**
|
|
5
|
+
:::info
|
|
6
|
+
This custom hook is used to fetch a group object.
|
|
7
|
+
:::
|
|
8
|
+
* @param object
|
|
9
|
+
* @param object.id
|
|
10
|
+
* @param object.group
|
|
11
|
+
* @param object.cacheStrategy
|
|
12
|
+
*/
|
|
13
|
+
export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
|
|
14
|
+
id?: number | string;
|
|
15
|
+
group?: SCGroupType;
|
|
16
|
+
cacheStrategy?: CacheStrategies;
|
|
17
|
+
}): {
|
|
18
|
+
scGroup: SCGroupType;
|
|
19
|
+
setSCGroup: import("react").Dispatch<import("react").SetStateAction<SCGroupType>>;
|
|
20
|
+
error: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const Errors_1 = require("../constants/Errors");
|
|
5
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
7
|
+
const Cache_1 = require("../constants/Cache");
|
|
8
|
+
const use_deep_compare_effect_1 = require("use-deep-compare-effect");
|
|
9
|
+
const SCUserProvider_1 = require("../components/provider/SCUserProvider");
|
|
10
|
+
/**
|
|
11
|
+
:::info
|
|
12
|
+
This custom hook is used to fetch a group object.
|
|
13
|
+
:::
|
|
14
|
+
* @param object
|
|
15
|
+
* @param object.id
|
|
16
|
+
* @param object.group
|
|
17
|
+
* @param object.cacheStrategy
|
|
18
|
+
*/
|
|
19
|
+
function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
20
|
+
const __groupId = group ? group.id : id;
|
|
21
|
+
// CONTEXT
|
|
22
|
+
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
23
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
24
|
+
// CACHE
|
|
25
|
+
const __groupCacheKey = (0, Cache_1.getGroupObjectCacheKey)(__groupId);
|
|
26
|
+
const __group = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscribed']);
|
|
27
|
+
const [scGroup, setSCGroup] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__groupCacheKey, __group) : null);
|
|
28
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
29
|
+
/**
|
|
30
|
+
* Memoized fetchTag
|
|
31
|
+
*/
|
|
32
|
+
const fetchGroup = (0, react_1.useMemo)(() => () => {
|
|
33
|
+
return api_services_1.http
|
|
34
|
+
.request({
|
|
35
|
+
url: api_services_1.Endpoints.GetGroupInfo.url({ id: __groupId }),
|
|
36
|
+
method: api_services_1.Endpoints.GetGroupInfo.method,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => {
|
|
39
|
+
if (res.status >= 300) {
|
|
40
|
+
return Promise.reject(res);
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve(res.data);
|
|
43
|
+
});
|
|
44
|
+
}, [__groupId]);
|
|
45
|
+
/**
|
|
46
|
+
* If id attempt to get the group by id
|
|
47
|
+
*/
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
50
|
+
fetchGroup()
|
|
51
|
+
.then((obj) => {
|
|
52
|
+
const _c = authUserId ? obj : (0, utils_1.objectWithoutProperties)(obj, ['subscribed']);
|
|
53
|
+
setSCGroup(_c);
|
|
54
|
+
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
utils_1.LRUCache.delete(__groupCacheKey);
|
|
58
|
+
setError(`Group with id ${id} not found`);
|
|
59
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `Group with id ${id} not found`);
|
|
60
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}, [__groupId]);
|
|
64
|
+
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
65
|
+
if (group) {
|
|
66
|
+
const _c = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscribed']);
|
|
67
|
+
setSCGroup(_c);
|
|
68
|
+
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
69
|
+
}
|
|
70
|
+
}, [group]);
|
|
71
|
+
return { scGroup, setSCGroup, error };
|
|
72
|
+
}
|
|
73
|
+
exports.default = useSCFetchGroup;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SCGroupType, SCUserType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to manage the groups followed.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
:::tip How to use it:
|
|
8
|
+
Follow these steps:
|
|
9
|
+
```jsx
|
|
10
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
11
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
12
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
*/
|
|
16
|
+
export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
17
|
+
groups: any[];
|
|
18
|
+
loading: any[];
|
|
19
|
+
isLoading: (v: number | {
|
|
20
|
+
id: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
subscribe?: undefined;
|
|
23
|
+
subscriptionStatus?: undefined;
|
|
24
|
+
refresh?: undefined;
|
|
25
|
+
emptyCache?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
groups: any[];
|
|
28
|
+
loading: any[];
|
|
29
|
+
isLoading: (v: number | {
|
|
30
|
+
id: number;
|
|
31
|
+
}) => boolean;
|
|
32
|
+
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscriptionStatus: (group: SCGroupType) => string;
|
|
34
|
+
refresh: () => void;
|
|
35
|
+
emptyCache: () => void;
|
|
36
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
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 useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
7
|
+
const Errors_1 = require("../constants/Errors");
|
|
8
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
9
|
+
/**
|
|
10
|
+
:::info
|
|
11
|
+
This custom hook is used to manage the groups followed.
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
:::tip How to use it:
|
|
15
|
+
Follow these steps:
|
|
16
|
+
```jsx
|
|
17
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
18
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
19
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
20
|
+
```
|
|
21
|
+
:::
|
|
22
|
+
*/
|
|
23
|
+
function useSCSubscribedGroupsManager(user) {
|
|
24
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = (0, useSCCachingManager_1.default)();
|
|
25
|
+
const authUserId = user ? user.id : null;
|
|
26
|
+
/**
|
|
27
|
+
* Memoized refresh all groups
|
|
28
|
+
* It makes a single request to the server and retrieves
|
|
29
|
+
* all the groups followed by the user in a single solution
|
|
30
|
+
* It might be useful for multi-tab sync
|
|
31
|
+
*/
|
|
32
|
+
const refresh = (0, react_1.useMemo)(() => () => {
|
|
33
|
+
emptyCache();
|
|
34
|
+
if (user) {
|
|
35
|
+
// Only if user is authenticated
|
|
36
|
+
api_services_1.http
|
|
37
|
+
.request({
|
|
38
|
+
url: api_services_1.Endpoints.GetUserGroups.url(),
|
|
39
|
+
method: api_services_1.Endpoints.GetUserGroups.method,
|
|
40
|
+
})
|
|
41
|
+
.then((res) => {
|
|
42
|
+
if (res.status >= 300) {
|
|
43
|
+
return Promise.reject(res);
|
|
44
|
+
}
|
|
45
|
+
const groupsIds = res.data.map((g) => g.id);
|
|
46
|
+
updateCache(groupsIds);
|
|
47
|
+
setData(groupsIds);
|
|
48
|
+
return Promise.resolve(res.data);
|
|
49
|
+
})
|
|
50
|
+
.catch((e) => {
|
|
51
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to refresh the authenticated user groups.');
|
|
52
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, e);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}, [data, user, cache]);
|
|
56
|
+
/**
|
|
57
|
+
* Memoized subscribe Group
|
|
58
|
+
* Toggle action
|
|
59
|
+
*/
|
|
60
|
+
const subscribe = (0, react_1.useMemo)(() => (group) => {
|
|
61
|
+
setLoading(group.id);
|
|
62
|
+
return api_services_1.http
|
|
63
|
+
.request({
|
|
64
|
+
url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
65
|
+
method: api_services_1.Endpoints.SubscribeToGroup.method,
|
|
66
|
+
})
|
|
67
|
+
.then((res) => {
|
|
68
|
+
if (res.status >= 300) {
|
|
69
|
+
return Promise.reject(res);
|
|
70
|
+
}
|
|
71
|
+
updateCache([group.id]);
|
|
72
|
+
const isSubscribed = data.includes(group.id);
|
|
73
|
+
setData((prev) => (isSubscribed ? prev.filter((id) => id !== group.id) : [...[group.id], ...prev]));
|
|
74
|
+
setUnLoading(group.id);
|
|
75
|
+
return Promise.resolve(res.data);
|
|
76
|
+
});
|
|
77
|
+
}, [data, loading, cache]);
|
|
78
|
+
/**
|
|
79
|
+
* Check the authenticated user subscription status to the group
|
|
80
|
+
* Update the groups cached
|
|
81
|
+
* Update groups subscription statuses
|
|
82
|
+
* @param group
|
|
83
|
+
*/
|
|
84
|
+
const checkGroupSubscriptionStatus = (group) => {
|
|
85
|
+
setLoading(group.id);
|
|
86
|
+
return api_services_1.http
|
|
87
|
+
.request({
|
|
88
|
+
url: api_services_1.Endpoints.GetGroupSubscriptionStatus.url({ id: group.id }),
|
|
89
|
+
method: api_services_1.Endpoints.GetGroupSubscriptionStatus.method,
|
|
90
|
+
})
|
|
91
|
+
.then((res) => {
|
|
92
|
+
if (res.status >= 300) {
|
|
93
|
+
return Promise.reject(res);
|
|
94
|
+
}
|
|
95
|
+
setData((prev) => getDataUpdated(prev, group.id, res.data.status));
|
|
96
|
+
updateCache([group.id]);
|
|
97
|
+
setUnLoading(group.id);
|
|
98
|
+
return Promise.resolve(res.data);
|
|
99
|
+
})
|
|
100
|
+
.catch((e) => {
|
|
101
|
+
setUnLoading(group.id);
|
|
102
|
+
return Promise.reject(e);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Get updated data
|
|
107
|
+
* @param data
|
|
108
|
+
* @param groupId
|
|
109
|
+
* @param subscriptionStatus
|
|
110
|
+
*/
|
|
111
|
+
const getDataUpdated = (data, groupId, subscriptionStatus) => {
|
|
112
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === groupId);
|
|
113
|
+
let _data;
|
|
114
|
+
if (_index < 0) {
|
|
115
|
+
_data = [...data, ...[{ [groupId]: subscriptionStatus }]];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
_data = data.map((k, i) => {
|
|
119
|
+
if (parseInt(Object.keys(k)[0]) === groupId) {
|
|
120
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
121
|
+
}
|
|
122
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return _data;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Return current group subscription status if exists,
|
|
129
|
+
* otherwise return null
|
|
130
|
+
*/
|
|
131
|
+
const getCurrentGroupCacheStatus = (0, react_1.useMemo)(() => (group) => {
|
|
132
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === group.id);
|
|
133
|
+
return d.length ? d[0][group.id] : null;
|
|
134
|
+
}, [data]);
|
|
135
|
+
/**
|
|
136
|
+
* Bypass remote check if the group is subscribed
|
|
137
|
+
*/
|
|
138
|
+
const getSubscriptionStatus = (0, react_1.useMemo)(() => (group) => {
|
|
139
|
+
updateCache([group.id]);
|
|
140
|
+
setData((prev) => getDataUpdated(prev, group.id, group.subscription_status));
|
|
141
|
+
return group.subscription_status;
|
|
142
|
+
}, [data, cache]);
|
|
143
|
+
/**
|
|
144
|
+
* Memoized subscriptionStatus
|
|
145
|
+
* If group is already in cache -> check if the group is in groups,
|
|
146
|
+
* otherwise, check if user subscribe the group
|
|
147
|
+
*/
|
|
148
|
+
const subscriptionStatus = (0, react_1.useMemo)(() => (group) => {
|
|
149
|
+
// Cache is valid also for anonymous user
|
|
150
|
+
if (cache.includes(group.id)) {
|
|
151
|
+
return getCurrentGroupCacheStatus(group);
|
|
152
|
+
}
|
|
153
|
+
if (authUserId) {
|
|
154
|
+
if ('subscription_status' in group) {
|
|
155
|
+
return getSubscriptionStatus(group);
|
|
156
|
+
}
|
|
157
|
+
if (!isLoading(group)) {
|
|
158
|
+
checkGroupSubscriptionStatus(group);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}, [data, loading, cache, authUserId]);
|
|
163
|
+
/**
|
|
164
|
+
* Empty cache on logout
|
|
165
|
+
*/
|
|
166
|
+
(0, react_1.useEffect)(() => {
|
|
167
|
+
if (!authUserId) {
|
|
168
|
+
emptyCache();
|
|
169
|
+
}
|
|
170
|
+
}, [authUserId]);
|
|
171
|
+
if (!user) {
|
|
172
|
+
return { groups: data, loading, isLoading };
|
|
173
|
+
}
|
|
174
|
+
return { groups: data, loading, isLoading, subscribe, subscriptionStatus, refresh, emptyCache };
|
|
175
|
+
}
|
|
176
|
+
exports.default = useSCSubscribedGroupsManager;
|
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 } 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 } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -60,6 +60,7 @@ import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSn
|
|
|
60
60
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
61
61
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
62
62
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
63
|
+
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
63
64
|
/**
|
|
64
65
|
* Routing component
|
|
65
66
|
*/
|
|
@@ -79,4 +80,4 @@ import * as Locale from './constants/Locale';
|
|
|
79
80
|
/**
|
|
80
81
|
* List all exports
|
|
81
82
|
*/
|
|
82
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, 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, };
|
|
83
|
+
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, };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useIsComponentMountedRef = exports.useSCFetchFeed = exports.useSCFetchContributors = exports.useSCMediaClick = exports.useSCFetchIncubator = exports.useSCFetchCategories = exports.useSCFetchCategory = exports.useSCFetchAddressingTagList = exports.useSCFetchTag = exports.useSCFetchCustomAdv = exports.useSCFetchCommentObjects = exports.useSCFetchCommentObject = exports.useSCFetchFeedObject = exports.useSCFetchVote = exports.useSCFetchUserProviders = exports.useSCFetchUser = exports.Locale = exports.UserUtils = exports.SCCache = exports.SCRoutes = exports.Link = exports.useSCAlertMessages = exports.SCAlertMessagesContext = exports.SCAlertMessagesProvider = exports.useSCNotification = exports.SCNotificationContext = exports.SCNotificationProvider = exports.SCNotification = exports.SCFeatures = exports.SCPreferences = exports.SCPreferencesProvider = exports.withSCLocale = exports.useSCLocale = exports.SCLocaleProvider = exports.useSCRouting = exports.SCRoutingProvider = exports.withSCTheme = exports.useSCTheme = exports.SCThemeProvider = exports.useSCPreferences = exports.useSCUser = exports.SCUserProvider = exports.SCContextProvider = exports.useSCContext = exports.SCPreferencesContext = exports.SCLocaleContext = exports.SCRoutingContext = exports.SCThemeContext = exports.SCUserContext = exports.SCContext = void 0;
|
|
4
|
-
exports.useSCUserIsBlocked = exports.useSCFetchUserBlockedBy = exports.useSCFetchBroadcastMessages = exports.useSCFetchPrivateMessageSnippets = exports.useNoInitialEffect = exports.useEffectOnce = exports.useIsomorphicLayoutEffect = exports.usePreviousValue = void 0;
|
|
4
|
+
exports.useSCFetchGroup = exports.useSCUserIsBlocked = exports.useSCFetchUserBlockedBy = exports.useSCFetchBroadcastMessages = exports.useSCFetchPrivateMessageSnippets = exports.useNoInitialEffect = exports.useEffectOnce = exports.useIsomorphicLayoutEffect = exports.usePreviousValue = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
/**
|
|
7
7
|
* ContextProvider component
|
|
@@ -110,6 +110,8 @@ const useSCFetchUserBlockedBy_1 = tslib_1.__importDefault(require("./hooks/useSC
|
|
|
110
110
|
exports.useSCFetchUserBlockedBy = useSCFetchUserBlockedBy_1.default;
|
|
111
111
|
const useSCUserIsBlocked_1 = tslib_1.__importDefault(require("./hooks/useSCUserIsBlocked"));
|
|
112
112
|
exports.useSCUserIsBlocked = useSCUserIsBlocked_1.default;
|
|
113
|
+
const useSCFetchGroup_1 = tslib_1.__importDefault(require("./hooks/useSCFetchGroup"));
|
|
114
|
+
exports.useSCFetchGroup = useSCFetchGroup_1.default;
|
|
113
115
|
/**
|
|
114
116
|
* Routing component
|
|
115
117
|
*/
|
package/lib/cjs/themes/theme.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType } from
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -132,7 +132,7 @@ export interface SCUserContextType {
|
|
|
132
132
|
*/
|
|
133
133
|
refreshCounters: () => Promise<any>;
|
|
134
134
|
/**
|
|
135
|
-
* Managers: followed, connections, categories, incubators, etc...
|
|
135
|
+
* Managers: followed, connections, categories, incubators, groups, etc...
|
|
136
136
|
*/
|
|
137
137
|
managers: {
|
|
138
138
|
settings?: SCSettingsManagerType;
|
|
@@ -142,6 +142,7 @@ export interface SCUserContextType {
|
|
|
142
142
|
categories: SCFollowedCategoriesManagerType;
|
|
143
143
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
144
144
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
145
|
+
groups?: SCSubscribedGroupsManagerType;
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
148
|
export interface SCSettingsManagerType {
|
|
@@ -248,6 +249,36 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
248
249
|
*/
|
|
249
250
|
emptyCache?: () => void;
|
|
250
251
|
}
|
|
252
|
+
export interface SCSubscribedGroupsManagerType {
|
|
253
|
+
/**
|
|
254
|
+
* List of all groups ids followed by the authenticated user
|
|
255
|
+
*/
|
|
256
|
+
groups: number[];
|
|
257
|
+
/**
|
|
258
|
+
* List of all groups in loading state
|
|
259
|
+
*/
|
|
260
|
+
loading: number[];
|
|
261
|
+
/**
|
|
262
|
+
* List of current groups in loading state
|
|
263
|
+
*/
|
|
264
|
+
isLoading: (group: SCGroupType) => boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Handle user subscription to a group
|
|
267
|
+
*/
|
|
268
|
+
subscribe?: (group: SCGroupType) => Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Handles a user subscription status to a group, caching data
|
|
271
|
+
*/
|
|
272
|
+
subscriptionStatus?: (group: SCGroupType) => string;
|
|
273
|
+
/**
|
|
274
|
+
* Refresh groups
|
|
275
|
+
*/
|
|
276
|
+
refresh?: () => void;
|
|
277
|
+
/**
|
|
278
|
+
* Empty cache to revalidate all groups
|
|
279
|
+
*/
|
|
280
|
+
emptyCache?: () => void;
|
|
281
|
+
}
|
|
251
282
|
export interface SCConnectionsManagerType {
|
|
252
283
|
/**
|
|
253
284
|
* List of all users in relations(social graph) with 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 } 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 } 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, };
|
|
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, };
|
package/lib/cjs/types/theme.d.ts
CHANGED
|
@@ -29,6 +29,15 @@ export interface SCThemeUserVariableType {
|
|
|
29
29
|
*/
|
|
30
30
|
avatar: SCThemeAvatarVariableType;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface SCThemeGroupVariableType
|
|
34
|
+
*/
|
|
35
|
+
export interface SCThemeGroupVariableType {
|
|
36
|
+
/**
|
|
37
|
+
* Avatar variables
|
|
38
|
+
*/
|
|
39
|
+
avatar: SCThemeAvatarVariableType;
|
|
40
|
+
}
|
|
32
41
|
/**
|
|
33
42
|
* Interface SCThemeCategoryVariableType
|
|
34
43
|
*/
|
|
@@ -67,6 +76,10 @@ export interface SCThemeVariablesType {
|
|
|
67
76
|
* Category
|
|
68
77
|
*/
|
|
69
78
|
category: SCThemeCategoryVariableType;
|
|
79
|
+
/**
|
|
80
|
+
* Group
|
|
81
|
+
*/
|
|
82
|
+
group: SCThemeGroupVariableType;
|
|
70
83
|
}
|
|
71
84
|
export interface SCThemeType extends MuiTheme {
|
|
72
85
|
/**
|
|
@@ -15,6 +15,7 @@ import { SCNotificationTopicType, SCNotificationTypologyType, SCUserStatus } fro
|
|
|
15
15
|
import useSCSubscribedIncubatorsManager from '../../../hooks/useSCSubscribedIncubatorsManager';
|
|
16
16
|
import useSCBlockedUsersManager from '../../../hooks/useSCBlockedUsersManager';
|
|
17
17
|
import * as Session from '../../../constants/Session';
|
|
18
|
+
import useSCSubscribedGroupsManager from '../../../hooks/useSCSubscribedGroupsManager';
|
|
18
19
|
/**
|
|
19
20
|
* SCUserContext (Authentication Context)
|
|
20
21
|
*
|
|
@@ -66,6 +67,7 @@ export default function SCUserProvider({ children }) {
|
|
|
66
67
|
const connectionsManager = useSCConnectionsManager(state.user);
|
|
67
68
|
const categoriesManager = useSCFollowedCategoriesManager(state.user, updateUser);
|
|
68
69
|
const blockedUsersManager = useSCBlockedUsersManager(state.user);
|
|
70
|
+
const subscribedGroupsManager = useSCSubscribedGroupsManager(state.user);
|
|
69
71
|
/**
|
|
70
72
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
71
73
|
*/
|
|
@@ -116,6 +118,7 @@ export default function SCUserProvider({ children }) {
|
|
|
116
118
|
connectionsManager.refresh && connectionsManager.refresh();
|
|
117
119
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
118
120
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
121
|
+
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
@@ -211,6 +214,7 @@ export default function SCUserProvider({ children }) {
|
|
|
211
214
|
connections: connectionsManager,
|
|
212
215
|
incubators: subscribedIncubatorsManager,
|
|
213
216
|
blockedUsers: blockedUsersManager,
|
|
217
|
+
groups: subscribedGroupsManager,
|
|
214
218
|
},
|
|
215
219
|
}), [
|
|
216
220
|
state,
|
|
@@ -227,6 +231,8 @@ export default function SCUserProvider({ children }) {
|
|
|
227
231
|
blockedUsersManager.blocked,
|
|
228
232
|
subscribedIncubatorsManager.loading,
|
|
229
233
|
subscribedIncubatorsManager.incubators,
|
|
234
|
+
subscribedGroupsManager.loading,
|
|
235
|
+
subscribedGroupsManager.groups,
|
|
230
236
|
]);
|
|
231
237
|
/**
|
|
232
238
|
* We only want to render the underlying app after we
|