@selfcommunity/react-core 0.4.9-alpha.0 → 0.4.9-alpha.10
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 +9 -0
- package/lib/cjs/constants/Cache.js +13 -1
- package/lib/cjs/constants/Routes.d.ts +4 -0
- package/lib/cjs/constants/Routes.js +9 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/cjs/hooks/useSCFetchGroup.js +73 -0
- package/lib/cjs/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchGroups.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +218 -0
- package/lib/cjs/index.d.ts +4 -2
- package/lib/cjs/index.js +5 -1
- package/lib/cjs/themes/theme.js +8 -0
- package/lib/cjs/types/context.d.ts +37 -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 +9 -0
- package/lib/esm/constants/Cache.js +9 -0
- package/lib/esm/constants/Routes.d.ts +4 -0
- package/lib/esm/constants/Routes.js +8 -0
- package/lib/esm/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchGroup.js +70 -0
- package/lib/esm/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchGroups.js +81 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +214 -0
- package/lib/esm/index.d.ts +4 -2
- package/lib/esm/index.js +3 -1
- package/lib/esm/themes/theme.js +8 -0
- package/lib/esm/types/context.d.ts +37 -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,12 @@ 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;
|
|
23
|
+
/** GROUPS OBJECT **/
|
|
24
|
+
export declare const GROUPS_OBJECT_CACHE_PREFIX_KEY = "_grps_";
|
|
25
|
+
export declare const getGroupsObjectCacheKey: () => string;
|
|
20
26
|
/** INCUBATOR OBJECT **/
|
|
21
27
|
export declare const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = "_inc_";
|
|
22
28
|
export declare const getIncubatorObjectCacheKey: (id: any) => string;
|
|
@@ -62,4 +68,7 @@ export declare const PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidg
|
|
|
62
68
|
export declare const INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_iListWidget_";
|
|
63
69
|
export declare const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_iSugWidget_";
|
|
64
70
|
export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget_";
|
|
71
|
+
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
72
|
+
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
73
|
+
export declare const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_glIST_";
|
|
65
74
|
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.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.getGroupsObjectCacheKey = exports.GROUPS_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.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 = 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,14 @@ 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;
|
|
34
|
+
/** GROUPS OBJECT **/
|
|
35
|
+
exports.GROUPS_OBJECT_CACHE_PREFIX_KEY = '_grps_';
|
|
36
|
+
const getGroupsObjectCacheKey = () => `${exports.GROUPS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
37
|
+
exports.getGroupsObjectCacheKey = getGroupsObjectCacheKey;
|
|
29
38
|
/** INCUBATOR OBJECT **/
|
|
30
39
|
exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = '_inc_';
|
|
31
40
|
const getIncubatorObjectCacheKey = (id) => `${exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -86,5 +95,8 @@ exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
|
86
95
|
exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_iListWidget_';
|
|
87
96
|
exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_iSugWidget_';
|
|
88
97
|
exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
98
|
+
exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
99
|
+
exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
100
|
+
exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_glIST_';
|
|
89
101
|
const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
90
102
|
exports.getWidgetStateCacheKey = getWidgetStateCacheKey;
|
|
@@ -31,6 +31,10 @@ 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";
|
|
35
|
+
export declare const GROUP_MEMBERS_ROUTE_NAME = "group_members";
|
|
36
|
+
export declare const GROUP_MESSAGES_ROUTE_NAME = "group_messages";
|
|
37
|
+
export declare const GROUPS_ROUTE_NAME = "groups";
|
|
34
38
|
/**
|
|
35
39
|
* Default Routes
|
|
36
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}}
|
|
@@ -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.GROUPS_ROUTE_NAME = exports.GROUP_MESSAGES_ROUTE_NAME = exports.GROUP_MEMBERS_ROUTE_NAME = 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,10 @@ 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';
|
|
38
|
+
exports.GROUP_MEMBERS_ROUTE_NAME = 'group_members';
|
|
39
|
+
exports.GROUP_MESSAGES_ROUTE_NAME = 'group_messages';
|
|
40
|
+
exports.GROUPS_ROUTE_NAME = 'groups';
|
|
37
41
|
/**
|
|
38
42
|
* Default Routes
|
|
39
43
|
* @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 +71,8 @@ exports.defaultRoutes = {
|
|
|
67
71
|
[exports.RECOVER_ROUTE_NAME]: '/recover/',
|
|
68
72
|
[exports.CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
69
73
|
[exports.LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
74
|
+
[exports.GROUP_ROUTE_NAME]: '/group/:id/:slug/',
|
|
75
|
+
[exports.GROUP_MEMBERS_ROUTE_NAME]: '/group/:id/:slug/members/',
|
|
76
|
+
[exports.GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:slug/messages/',
|
|
77
|
+
[exports.GROUPS_ROUTE_NAME]: '/groups/',
|
|
70
78
|
};
|
|
@@ -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, ['subscription_status']);
|
|
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, ['subscription_status']);
|
|
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, authUserId]);
|
|
64
|
+
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
65
|
+
if (group) {
|
|
66
|
+
const _c = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscription_status']);
|
|
67
|
+
setSCGroup(_c);
|
|
68
|
+
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
69
|
+
}
|
|
70
|
+
}, [group, authUserId]);
|
|
71
|
+
return { scGroup, setSCGroup, error };
|
|
72
|
+
}
|
|
73
|
+
exports.default = useSCFetchGroup;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch groups.
|
|
6
|
+
@param object.cacheStrategy
|
|
7
|
+
|
|
8
|
+
:::tip Context can be consumed in this way:
|
|
9
|
+
|
|
10
|
+
```jsx
|
|
11
|
+
const {groups, isLoading} = useSCFetchGroups();
|
|
12
|
+
```
|
|
13
|
+
:::
|
|
14
|
+
* @param props
|
|
15
|
+
*/
|
|
16
|
+
declare const useSCFetchGroups: (props?: {
|
|
17
|
+
cacheStrategy?: CacheStrategies;
|
|
18
|
+
}) => {
|
|
19
|
+
groups: SCGroupType[];
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
};
|
|
22
|
+
export default useSCFetchGroups;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const Errors_1 = require("../constants/Errors");
|
|
6
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
8
|
+
const Cache_1 = require("../constants/Cache");
|
|
9
|
+
const init = { groups: [], isLoading: true };
|
|
10
|
+
// HYDRATE the cache
|
|
11
|
+
const hydrate = (ids) => {
|
|
12
|
+
if (!ids) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const groups = ids.map((id) => {
|
|
16
|
+
const __groupCacheKey = (0, Cache_1.getGroupObjectCacheKey)(id);
|
|
17
|
+
return utils_1.LRUCache.get(__groupCacheKey);
|
|
18
|
+
});
|
|
19
|
+
if (groups.filter((c) => !c).length > 0) {
|
|
20
|
+
// REVALIDATE CACHE
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return groups;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
:::info
|
|
27
|
+
This custom hook is used to fetch groups.
|
|
28
|
+
@param object.cacheStrategy
|
|
29
|
+
|
|
30
|
+
:::tip Context can be consumed in this way:
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
const {groups, isLoading} = useSCFetchGroups();
|
|
34
|
+
```
|
|
35
|
+
:::
|
|
36
|
+
* @param props
|
|
37
|
+
*/
|
|
38
|
+
const useSCFetchGroups = (props) => {
|
|
39
|
+
// PROPS
|
|
40
|
+
const { cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST } = props || {};
|
|
41
|
+
// CACHE
|
|
42
|
+
const __groupsCacheKey = (0, Cache_1.getGroupsObjectCacheKey)();
|
|
43
|
+
// STATE
|
|
44
|
+
const groups = cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? hydrate(utils_1.LRUCache.get(__groupsCacheKey, null)) : null;
|
|
45
|
+
const [data, setData] = (0, react_1.useState)(groups !== null ? { groups, isLoading: false } : init);
|
|
46
|
+
/**
|
|
47
|
+
* Fetch groups
|
|
48
|
+
*/
|
|
49
|
+
const fetchGroups = (next = api_services_1.Endpoints.GetUserGroups.url()) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const response = yield api_services_1.http.request({
|
|
51
|
+
url: next,
|
|
52
|
+
method: api_services_1.Endpoints.GetUserGroups.method,
|
|
53
|
+
});
|
|
54
|
+
const data = response.data;
|
|
55
|
+
if (data.next) {
|
|
56
|
+
return data.results.concat(yield fetchGroups(data.next));
|
|
57
|
+
}
|
|
58
|
+
return data.results;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Get groups
|
|
62
|
+
*/
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (cacheStrategy === utils_1.CacheStrategies.CACHE_FIRST && groups) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
fetchGroups()
|
|
68
|
+
.then((data) => {
|
|
69
|
+
setData({ groups: data, isLoading: false });
|
|
70
|
+
utils_1.LRUCache.set(__groupsCacheKey, data.map((group) => {
|
|
71
|
+
const __groupCacheKey = (0, Cache_1.getGroupObjectCacheKey)(group.id);
|
|
72
|
+
utils_1.LRUCache.set(__groupCacheKey, group);
|
|
73
|
+
return group.id;
|
|
74
|
+
}));
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
console.log(error);
|
|
78
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to retrieve groups');
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
return data;
|
|
82
|
+
};
|
|
83
|
+
exports.default = useSCFetchGroups;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
unsubscribe?: undefined;
|
|
24
|
+
subscriptionStatus?: undefined;
|
|
25
|
+
refresh?: undefined;
|
|
26
|
+
emptyCache?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
groups: any[];
|
|
29
|
+
loading: any[];
|
|
30
|
+
isLoading: (v: number | {
|
|
31
|
+
id: number;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
34
|
+
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
|
+
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
|
+
refresh: () => void;
|
|
37
|
+
emptyCache: () => void;
|
|
38
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
/**
|
|
11
|
+
:::info
|
|
12
|
+
This custom hook is used to manage the groups followed.
|
|
13
|
+
:::
|
|
14
|
+
|
|
15
|
+
:::tip How to use it:
|
|
16
|
+
Follow these steps:
|
|
17
|
+
```jsx
|
|
18
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
19
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
20
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
21
|
+
```
|
|
22
|
+
:::
|
|
23
|
+
*/
|
|
24
|
+
function useSCSubscribedGroupsManager(user) {
|
|
25
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = (0, useSCCachingManager_1.default)();
|
|
26
|
+
const authUserId = user ? user.id : null;
|
|
27
|
+
/**
|
|
28
|
+
* Memoized refresh all groups
|
|
29
|
+
* It makes a single request to the server and retrieves
|
|
30
|
+
* all the groups followed by the user in a single solution
|
|
31
|
+
* It might be useful for multi-tab sync
|
|
32
|
+
*/
|
|
33
|
+
const refresh = (0, react_1.useMemo)(() => () => {
|
|
34
|
+
emptyCache();
|
|
35
|
+
if (user) {
|
|
36
|
+
// Only if user is authenticated
|
|
37
|
+
api_services_1.http
|
|
38
|
+
.request({
|
|
39
|
+
url: api_services_1.Endpoints.GetUserGroups.url(),
|
|
40
|
+
method: api_services_1.Endpoints.GetUserGroups.method,
|
|
41
|
+
})
|
|
42
|
+
.then((res) => {
|
|
43
|
+
if (res.status >= 300) {
|
|
44
|
+
return Promise.reject(res);
|
|
45
|
+
}
|
|
46
|
+
const groupsIds = res.data.map((g) => g.id);
|
|
47
|
+
updateCache(groupsIds);
|
|
48
|
+
setData(groupsIds);
|
|
49
|
+
return Promise.resolve(res.data);
|
|
50
|
+
})
|
|
51
|
+
.catch((e) => {
|
|
52
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to refresh the authenticated user groups.');
|
|
53
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, e);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}, [data, user, cache]);
|
|
57
|
+
/**
|
|
58
|
+
* Memoized subscribe Group
|
|
59
|
+
* Toggle action
|
|
60
|
+
*/
|
|
61
|
+
const subscribe = (0, react_1.useMemo)(() => (group, userId) => {
|
|
62
|
+
setLoading(group.id);
|
|
63
|
+
if (userId) {
|
|
64
|
+
return api_services_1.http
|
|
65
|
+
.request({
|
|
66
|
+
url: api_services_1.Endpoints.InviteOrAcceptGroupRequest.url({ id: group.id }),
|
|
67
|
+
method: api_services_1.Endpoints.InviteOrAcceptGroupRequest.method,
|
|
68
|
+
data: { users: [userId] },
|
|
69
|
+
})
|
|
70
|
+
.then((res) => {
|
|
71
|
+
if (res.status >= 300) {
|
|
72
|
+
return Promise.reject(res);
|
|
73
|
+
}
|
|
74
|
+
updateCache([group.id]);
|
|
75
|
+
setData((prev) => getDataUpdated(prev, group.id, types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
76
|
+
setUnLoading(group.id);
|
|
77
|
+
return Promise.resolve(res.data);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return api_services_1.http
|
|
82
|
+
.request({
|
|
83
|
+
url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
84
|
+
method: api_services_1.Endpoints.SubscribeToGroup.method,
|
|
85
|
+
})
|
|
86
|
+
.then((res) => {
|
|
87
|
+
if (res.status >= 300) {
|
|
88
|
+
return Promise.reject(res);
|
|
89
|
+
}
|
|
90
|
+
updateCache([group.id]);
|
|
91
|
+
setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE ? types_1.SCGroupSubscriptionStatusType.REQUESTED : types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
92
|
+
setUnLoading(group.id);
|
|
93
|
+
return Promise.resolve(res.data);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}, [data, loading, cache]);
|
|
97
|
+
/**
|
|
98
|
+
* Memoized subscribe Group
|
|
99
|
+
* Toggle action
|
|
100
|
+
*/
|
|
101
|
+
const unsubscribe = (0, react_1.useMemo)(() => (group) => {
|
|
102
|
+
if (group.subscription_status !== types_1.SCGroupSubscriptionStatusType.REQUESTED) {
|
|
103
|
+
setLoading(group.id);
|
|
104
|
+
return api_services_1.http
|
|
105
|
+
.request({
|
|
106
|
+
url: api_services_1.Endpoints.UnsubscribeFromGroup.url({ id: group.id }),
|
|
107
|
+
method: api_services_1.Endpoints.UnsubscribeFromGroup.method,
|
|
108
|
+
})
|
|
109
|
+
.then((res) => {
|
|
110
|
+
if (res.status >= 300) {
|
|
111
|
+
return Promise.reject(res);
|
|
112
|
+
}
|
|
113
|
+
updateCache([group.id]);
|
|
114
|
+
setData((prev) => getDataUpdated(prev, group.id, null));
|
|
115
|
+
setUnLoading(group.id);
|
|
116
|
+
return Promise.resolve(res.data);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, [data, loading, cache]);
|
|
120
|
+
/**
|
|
121
|
+
* Check the authenticated user subscription status to the group
|
|
122
|
+
* Update the groups cached
|
|
123
|
+
* Update groups subscription statuses
|
|
124
|
+
* @param group
|
|
125
|
+
*/
|
|
126
|
+
const checkGroupSubscriptionStatus = (group) => {
|
|
127
|
+
setLoading(group.id);
|
|
128
|
+
return api_services_1.http
|
|
129
|
+
.request({
|
|
130
|
+
url: api_services_1.Endpoints.GetGroupSubscriptionStatus.url({ id: group.id }),
|
|
131
|
+
method: api_services_1.Endpoints.GetGroupSubscriptionStatus.method,
|
|
132
|
+
})
|
|
133
|
+
.then((res) => {
|
|
134
|
+
if (res.status >= 300) {
|
|
135
|
+
return Promise.reject(res);
|
|
136
|
+
}
|
|
137
|
+
setData((prev) => getDataUpdated(prev, group.id, res.data.status));
|
|
138
|
+
updateCache([group.id]);
|
|
139
|
+
setUnLoading(group.id);
|
|
140
|
+
return Promise.resolve(res.data);
|
|
141
|
+
})
|
|
142
|
+
.catch((e) => {
|
|
143
|
+
setUnLoading(group.id);
|
|
144
|
+
return Promise.reject(e);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Get updated data
|
|
149
|
+
* @param data
|
|
150
|
+
* @param groupId
|
|
151
|
+
* @param subscriptionStatus
|
|
152
|
+
*/
|
|
153
|
+
const getDataUpdated = (data, groupId, subscriptionStatus) => {
|
|
154
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === groupId);
|
|
155
|
+
let _data;
|
|
156
|
+
if (_index < 0) {
|
|
157
|
+
_data = [...data, ...[{ [groupId]: subscriptionStatus }]];
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
_data = data.map((k, i) => {
|
|
161
|
+
if (parseInt(Object.keys(k)[0]) === groupId) {
|
|
162
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
163
|
+
}
|
|
164
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return _data;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Return current group subscription status if exists,
|
|
171
|
+
* otherwise return null
|
|
172
|
+
*/
|
|
173
|
+
const getCurrentGroupCacheStatus = (0, react_1.useMemo)(() => (group) => {
|
|
174
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === group.id);
|
|
175
|
+
return d.length ? d[0][group.id] : null;
|
|
176
|
+
}, [data]);
|
|
177
|
+
/**
|
|
178
|
+
* Bypass remote check if the group is subscribed
|
|
179
|
+
*/
|
|
180
|
+
const getSubscriptionStatus = (0, react_1.useMemo)(() => (group) => {
|
|
181
|
+
updateCache([group.id]);
|
|
182
|
+
setData((prev) => getDataUpdated(prev, group.id, group.subscription_status));
|
|
183
|
+
return group.subscription_status;
|
|
184
|
+
}, [data, cache]);
|
|
185
|
+
/**
|
|
186
|
+
* Memoized subscriptionStatus
|
|
187
|
+
* If group is already in cache -> check if the group is in groups,
|
|
188
|
+
* otherwise, check if user subscribe the group
|
|
189
|
+
*/
|
|
190
|
+
const subscriptionStatus = (0, react_1.useMemo)(() => (group) => {
|
|
191
|
+
// Cache is valid also for anonymous user
|
|
192
|
+
if (cache.includes(group.id)) {
|
|
193
|
+
return getCurrentGroupCacheStatus(group);
|
|
194
|
+
}
|
|
195
|
+
if (authUserId) {
|
|
196
|
+
if ('subscription_status' in group) {
|
|
197
|
+
return getSubscriptionStatus(group);
|
|
198
|
+
}
|
|
199
|
+
if (!isLoading(group)) {
|
|
200
|
+
checkGroupSubscriptionStatus(group);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}, [data, loading, cache, authUserId]);
|
|
205
|
+
/**
|
|
206
|
+
* Empty cache on logout
|
|
207
|
+
*/
|
|
208
|
+
(0, react_1.useEffect)(() => {
|
|
209
|
+
if (!authUserId) {
|
|
210
|
+
emptyCache();
|
|
211
|
+
}
|
|
212
|
+
}, [authUserId]);
|
|
213
|
+
if (!user) {
|
|
214
|
+
return { groups: data, loading, isLoading };
|
|
215
|
+
}
|
|
216
|
+
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|
|
217
|
+
}
|
|
218
|
+
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,8 @@ 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';
|
|
64
|
+
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
63
65
|
/**
|
|
64
66
|
* Routing component
|
|
65
67
|
*/
|
|
@@ -79,4 +81,4 @@ import * as Locale from './constants/Locale';
|
|
|
79
81
|
/**
|
|
80
82
|
* List all exports
|
|
81
83
|
*/
|
|
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, };
|
|
84
|
+
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, };
|
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.useSCFetchGroups = 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,10 @@ 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;
|
|
115
|
+
const useSCFetchGroups_1 = tslib_1.__importDefault(require("./hooks/useSCFetchGroups"));
|
|
116
|
+
exports.useSCFetchGroups = useSCFetchGroups_1.default;
|
|
113
117
|
/**
|
|
114
118
|
* Routing component
|
|
115
119
|
*/
|