@selfcommunity/react-core 0.4.9-alpha.1 → 0.4.9-alpha.11
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/constants/Cache.d.ts +4 -0
- package/lib/cjs/constants/Cache.js +7 -2
- package/lib/cjs/constants/Routes.d.ts +3 -0
- package/lib/cjs/constants/Routes.js +8 -2
- package/lib/cjs/hooks/useSCFetchGroup.js +5 -5
- package/lib/cjs/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchGroups.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +3 -1
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +59 -17
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/types/context.d.ts +5 -1
- package/lib/esm/constants/Cache.d.ts +4 -0
- package/lib/esm/constants/Cache.js +4 -0
- package/lib/esm/constants/Routes.d.ts +3 -0
- package/lib/esm/constants/Routes.js +7 -1
- package/lib/esm/hooks/useSCFetchGroup.js +5 -5
- package/lib/esm/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchGroups.js +81 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +3 -1
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +60 -18
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/types/context.d.ts +5 -1
- package/lib/umd/react-core.js +1 -1
- package/package.json +5 -5
|
@@ -20,6 +20,9 @@ export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
|
20
20
|
/** GROUP OBJECT **/
|
|
21
21
|
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
22
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;
|
|
23
26
|
/** INCUBATOR OBJECT **/
|
|
24
27
|
export declare const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = "_inc_";
|
|
25
28
|
export declare const getIncubatorObjectCacheKey: (id: any) => string;
|
|
@@ -67,4 +70,5 @@ export declare const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_iSugW
|
|
|
67
70
|
export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget_";
|
|
68
71
|
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
69
72
|
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
73
|
+
export declare const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_glIST_";
|
|
70
74
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Cache prefixes
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.getWidgetStateCacheKey = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
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;
|
|
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}`;
|
|
@@ -31,6 +31,10 @@ exports.getCategoryObjectCacheKey = getCategoryObjectCacheKey;
|
|
|
31
31
|
exports.GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
32
32
|
const getGroupObjectCacheKey = (id) => `${exports.GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
33
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;
|
|
34
38
|
/** INCUBATOR OBJECT **/
|
|
35
39
|
exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = '_inc_';
|
|
36
40
|
const getIncubatorObjectCacheKey = (id) => `${exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -93,5 +97,6 @@ exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_iSugWidget_';
|
|
|
93
97
|
exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
94
98
|
exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
95
99
|
exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
100
|
+
exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_glIST_';
|
|
96
101
|
const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
97
102
|
exports.getWidgetStateCacheKey = getWidgetStateCacheKey;
|
|
@@ -32,6 +32,9 @@ 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
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";
|
|
35
38
|
/**
|
|
36
39
|
* Default Routes
|
|
37
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.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;
|
|
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
|
/**
|
|
@@ -35,6 +35,9 @@ exports.RECOVER_ROUTE_NAME = 'recover';
|
|
|
35
35
|
exports.CUSTOM_PAGES_ROUTE_NAME = 'custom_pages';
|
|
36
36
|
exports.LEGAL_PAGES_ROUTE_NAME = 'legal_pages';
|
|
37
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';
|
|
38
41
|
/**
|
|
39
42
|
* Default Routes
|
|
40
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}}
|
|
@@ -68,5 +71,8 @@ exports.defaultRoutes = {
|
|
|
68
71
|
[exports.RECOVER_ROUTE_NAME]: '/recover/',
|
|
69
72
|
[exports.CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
70
73
|
[exports.LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
71
|
-
[exports.GROUP_ROUTE_NAME]: '/group/:id/',
|
|
74
|
+
[exports.GROUP_ROUTE_NAME]: '/group/:id/:name/',
|
|
75
|
+
[exports.GROUP_MEMBERS_ROUTE_NAME]: '/group/:id/:name/members/',
|
|
76
|
+
[exports.GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:name/messages/',
|
|
77
|
+
[exports.GROUPS_ROUTE_NAME]: '/groups/',
|
|
72
78
|
};
|
|
@@ -23,7 +23,7 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
23
23
|
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
24
24
|
// CACHE
|
|
25
25
|
const __groupCacheKey = (0, Cache_1.getGroupObjectCacheKey)(__groupId);
|
|
26
|
-
const __group = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['
|
|
26
|
+
const __group = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscription_status']);
|
|
27
27
|
const [scGroup, setSCGroup] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__groupCacheKey, __group) : null);
|
|
28
28
|
const [error, setError] = (0, react_1.useState)(null);
|
|
29
29
|
/**
|
|
@@ -49,7 +49,7 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
49
49
|
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
50
50
|
fetchGroup()
|
|
51
51
|
.then((obj) => {
|
|
52
|
-
const _c = authUserId ? obj : (0, utils_1.objectWithoutProperties)(obj, ['
|
|
52
|
+
const _c = authUserId ? obj : (0, utils_1.objectWithoutProperties)(obj, ['subscription_status']);
|
|
53
53
|
setSCGroup(_c);
|
|
54
54
|
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
55
55
|
})
|
|
@@ -60,14 +60,14 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
60
60
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
}, [__groupId]);
|
|
63
|
+
}, [__groupId, authUserId]);
|
|
64
64
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
65
65
|
if (group) {
|
|
66
|
-
const _c = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['
|
|
66
|
+
const _c = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscription_status']);
|
|
67
67
|
setSCGroup(_c);
|
|
68
68
|
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
69
69
|
}
|
|
70
|
-
}, [group]);
|
|
70
|
+
}, [group, authUserId]);
|
|
71
71
|
return { scGroup, setSCGroup, error };
|
|
72
72
|
}
|
|
73
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;
|
|
@@ -20,6 +20,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
20
20
|
id: number;
|
|
21
21
|
}) => boolean;
|
|
22
22
|
subscribe?: undefined;
|
|
23
|
+
unsubscribe?: undefined;
|
|
23
24
|
subscriptionStatus?: undefined;
|
|
24
25
|
refresh?: undefined;
|
|
25
26
|
emptyCache?: undefined;
|
|
@@ -29,7 +30,8 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
29
30
|
isLoading: (v: number | {
|
|
30
31
|
id: number;
|
|
31
32
|
}) => boolean;
|
|
32
|
-
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
34
|
+
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
33
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
34
36
|
refresh: () => void;
|
|
35
37
|
emptyCache: () => void;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
|
+
const types_1 = require("@selfcommunity/types");
|
|
6
7
|
const useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
7
8
|
const Errors_1 = require("../constants/Errors");
|
|
8
9
|
const utils_1 = require("@selfcommunity/utils");
|
|
@@ -57,23 +58,64 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
57
58
|
* Memoized subscribe Group
|
|
58
59
|
* Toggle action
|
|
59
60
|
*/
|
|
60
|
-
const subscribe = (0, react_1.useMemo)(() => (group) => {
|
|
61
|
+
const subscribe = (0, react_1.useMemo)(() => (group, userId) => {
|
|
61
62
|
setLoading(group.id);
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
}
|
|
77
119
|
}, [data, loading, cache]);
|
|
78
120
|
/**
|
|
79
121
|
* Check the authenticated user subscription status to the group
|
|
@@ -171,6 +213,6 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
171
213
|
if (!user) {
|
|
172
214
|
return { groups: data, loading, isLoading };
|
|
173
215
|
}
|
|
174
|
-
return { groups: data, loading, isLoading, subscribe, subscriptionStatus, refresh, emptyCache };
|
|
216
|
+
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|
|
175
217
|
}
|
|
176
218
|
exports.default = useSCSubscribedGroupsManager;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
|
61
61
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
62
62
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
63
63
|
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
64
|
+
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
64
65
|
/**
|
|
65
66
|
* Routing component
|
|
66
67
|
*/
|
|
@@ -80,4 +81,4 @@ import * as Locale from './constants/Locale';
|
|
|
80
81
|
/**
|
|
81
82
|
* List all exports
|
|
82
83
|
*/
|
|
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, };
|
|
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.useSCFetchGroup = 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
|
|
@@ -112,6 +112,8 @@ const useSCUserIsBlocked_1 = tslib_1.__importDefault(require("./hooks/useSCUserI
|
|
|
112
112
|
exports.useSCUserIsBlocked = useSCUserIsBlocked_1.default;
|
|
113
113
|
const useSCFetchGroup_1 = tslib_1.__importDefault(require("./hooks/useSCFetchGroup"));
|
|
114
114
|
exports.useSCFetchGroup = useSCFetchGroup_1.default;
|
|
115
|
+
const useSCFetchGroups_1 = tslib_1.__importDefault(require("./hooks/useSCFetchGroups"));
|
|
116
|
+
exports.useSCFetchGroups = useSCFetchGroups_1.default;
|
|
115
117
|
/**
|
|
116
118
|
* Routing component
|
|
117
119
|
*/
|
|
@@ -265,7 +265,11 @@ export interface SCSubscribedGroupsManagerType {
|
|
|
265
265
|
/**
|
|
266
266
|
* Handle user subscription to a group
|
|
267
267
|
*/
|
|
268
|
-
subscribe?: (group: SCGroupType) => Promise<any>;
|
|
268
|
+
subscribe?: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Handle user unsubscription from a group
|
|
271
|
+
*/
|
|
272
|
+
unsubscribe?: (group: SCGroupType) => Promise<any>;
|
|
269
273
|
/**
|
|
270
274
|
* Handles a user subscription status to a group, caching data
|
|
271
275
|
*/
|
|
@@ -20,6 +20,9 @@ export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
|
20
20
|
/** GROUP OBJECT **/
|
|
21
21
|
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
22
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;
|
|
23
26
|
/** INCUBATOR OBJECT **/
|
|
24
27
|
export declare const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = "_inc_";
|
|
25
28
|
export declare const getIncubatorObjectCacheKey: (id: any) => string;
|
|
@@ -67,4 +70,5 @@ export declare const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_iSugW
|
|
|
67
70
|
export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget_";
|
|
68
71
|
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
69
72
|
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
73
|
+
export declare const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_glIST_";
|
|
70
74
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -20,6 +20,9 @@ export const getCategoryObjectCacheKey = (id) => `${CATEGORY_OBJECT_CACHE_PREFIX
|
|
|
20
20
|
/** GROUP OBJECT **/
|
|
21
21
|
export const GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
22
22
|
export const getGroupObjectCacheKey = (id) => `${GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
23
|
+
/** GROUPS OBJECT **/
|
|
24
|
+
export const GROUPS_OBJECT_CACHE_PREFIX_KEY = '_grps_';
|
|
25
|
+
export const getGroupsObjectCacheKey = () => `${GROUPS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
23
26
|
/** INCUBATOR OBJECT **/
|
|
24
27
|
export const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = '_inc_';
|
|
25
28
|
export const getIncubatorObjectCacheKey = (id) => `${INCUBATOR_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -71,4 +74,5 @@ export const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_iSugWidget_';
|
|
|
71
74
|
export const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
72
75
|
export const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
73
76
|
export const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
77
|
+
export const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_glIST_';
|
|
74
78
|
export const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
@@ -32,6 +32,9 @@ 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
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";
|
|
35
38
|
/**
|
|
36
39
|
* Default Routes
|
|
37
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}}
|
|
@@ -32,6 +32,9 @@ export const RECOVER_ROUTE_NAME = 'recover';
|
|
|
32
32
|
export const CUSTOM_PAGES_ROUTE_NAME = 'custom_pages';
|
|
33
33
|
export const LEGAL_PAGES_ROUTE_NAME = 'legal_pages';
|
|
34
34
|
export const GROUP_ROUTE_NAME = 'group';
|
|
35
|
+
export const GROUP_MEMBERS_ROUTE_NAME = 'group_members';
|
|
36
|
+
export const GROUP_MESSAGES_ROUTE_NAME = 'group_messages';
|
|
37
|
+
export const GROUPS_ROUTE_NAME = 'groups';
|
|
35
38
|
/**
|
|
36
39
|
* Default Routes
|
|
37
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}}
|
|
@@ -65,5 +68,8 @@ export const defaultRoutes = {
|
|
|
65
68
|
[RECOVER_ROUTE_NAME]: '/recover/',
|
|
66
69
|
[CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
67
70
|
[LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
68
|
-
[GROUP_ROUTE_NAME]: '/group/:id/',
|
|
71
|
+
[GROUP_ROUTE_NAME]: '/group/:id/:name/',
|
|
72
|
+
[GROUP_MEMBERS_ROUTE_NAME]: '/group/:id/:name/members/',
|
|
73
|
+
[GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:name/messages/',
|
|
74
|
+
[GROUPS_ROUTE_NAME]: '/groups/',
|
|
69
75
|
};
|
|
@@ -21,7 +21,7 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
21
21
|
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
22
22
|
// CACHE
|
|
23
23
|
const __groupCacheKey = getGroupObjectCacheKey(__groupId);
|
|
24
|
-
const __group = authUserId ? group : objectWithoutProperties(group, ['
|
|
24
|
+
const __group = authUserId ? group : objectWithoutProperties(group, ['subscription_status']);
|
|
25
25
|
const [scGroup, setSCGroup] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__groupCacheKey, __group) : null);
|
|
26
26
|
const [error, setError] = useState(null);
|
|
27
27
|
/**
|
|
@@ -47,7 +47,7 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
47
47
|
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
48
48
|
fetchGroup()
|
|
49
49
|
.then((obj) => {
|
|
50
|
-
const _c = authUserId ? obj : objectWithoutProperties(obj, ['
|
|
50
|
+
const _c = authUserId ? obj : objectWithoutProperties(obj, ['subscription_status']);
|
|
51
51
|
setSCGroup(_c);
|
|
52
52
|
LRUCache.set(__groupCacheKey, _c);
|
|
53
53
|
})
|
|
@@ -58,13 +58,13 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
58
58
|
Logger.error(SCOPE_SC_CORE, err.message);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
}, [__groupId]);
|
|
61
|
+
}, [__groupId, authUserId]);
|
|
62
62
|
useDeepCompareEffectNoCheck(() => {
|
|
63
63
|
if (group) {
|
|
64
|
-
const _c = authUserId ? group : objectWithoutProperties(group, ['
|
|
64
|
+
const _c = authUserId ? group : objectWithoutProperties(group, ['subscription_status']);
|
|
65
65
|
setSCGroup(_c);
|
|
66
66
|
LRUCache.set(__groupCacheKey, _c);
|
|
67
67
|
}
|
|
68
|
-
}, [group]);
|
|
68
|
+
}, [group, authUserId]);
|
|
69
69
|
return { scGroup, setSCGroup, error };
|
|
70
70
|
}
|
|
@@ -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,81 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
4
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
5
|
+
import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
6
|
+
import { getGroupObjectCacheKey, getGroupsObjectCacheKey } from '../constants/Cache';
|
|
7
|
+
const init = { groups: [], isLoading: true };
|
|
8
|
+
// HYDRATE the cache
|
|
9
|
+
const hydrate = (ids) => {
|
|
10
|
+
if (!ids) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const groups = ids.map((id) => {
|
|
14
|
+
const __groupCacheKey = getGroupObjectCacheKey(id);
|
|
15
|
+
return LRUCache.get(__groupCacheKey);
|
|
16
|
+
});
|
|
17
|
+
if (groups.filter((c) => !c).length > 0) {
|
|
18
|
+
// REVALIDATE CACHE
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return groups;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
:::info
|
|
25
|
+
This custom hook is used to fetch groups.
|
|
26
|
+
@param object.cacheStrategy
|
|
27
|
+
|
|
28
|
+
:::tip Context can be consumed in this way:
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
const {groups, isLoading} = useSCFetchGroups();
|
|
32
|
+
```
|
|
33
|
+
:::
|
|
34
|
+
* @param props
|
|
35
|
+
*/
|
|
36
|
+
const useSCFetchGroups = (props) => {
|
|
37
|
+
// PROPS
|
|
38
|
+
const { cacheStrategy = CacheStrategies.CACHE_FIRST } = props || {};
|
|
39
|
+
// CACHE
|
|
40
|
+
const __groupsCacheKey = getGroupsObjectCacheKey();
|
|
41
|
+
// STATE
|
|
42
|
+
const groups = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__groupsCacheKey, null)) : null;
|
|
43
|
+
const [data, setData] = useState(groups !== null ? { groups, isLoading: false } : init);
|
|
44
|
+
/**
|
|
45
|
+
* Fetch groups
|
|
46
|
+
*/
|
|
47
|
+
const fetchGroups = (next = Endpoints.GetUserGroups.url()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const response = yield http.request({
|
|
49
|
+
url: next,
|
|
50
|
+
method: Endpoints.GetUserGroups.method,
|
|
51
|
+
});
|
|
52
|
+
const data = response.data;
|
|
53
|
+
if (data.next) {
|
|
54
|
+
return data.results.concat(yield fetchGroups(data.next));
|
|
55
|
+
}
|
|
56
|
+
return data.results;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Get groups
|
|
60
|
+
*/
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (cacheStrategy === CacheStrategies.CACHE_FIRST && groups) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
fetchGroups()
|
|
66
|
+
.then((data) => {
|
|
67
|
+
setData({ groups: data, isLoading: false });
|
|
68
|
+
LRUCache.set(__groupsCacheKey, data.map((group) => {
|
|
69
|
+
const __groupCacheKey = getGroupObjectCacheKey(group.id);
|
|
70
|
+
LRUCache.set(__groupCacheKey, group);
|
|
71
|
+
return group.id;
|
|
72
|
+
}));
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
console.log(error);
|
|
76
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to retrieve groups');
|
|
77
|
+
});
|
|
78
|
+
}, []);
|
|
79
|
+
return data;
|
|
80
|
+
};
|
|
81
|
+
export default useSCFetchGroups;
|
|
@@ -20,6 +20,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
20
20
|
id: number;
|
|
21
21
|
}) => boolean;
|
|
22
22
|
subscribe?: undefined;
|
|
23
|
+
unsubscribe?: undefined;
|
|
23
24
|
subscriptionStatus?: undefined;
|
|
24
25
|
refresh?: undefined;
|
|
25
26
|
emptyCache?: undefined;
|
|
@@ -29,7 +30,8 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
29
30
|
isLoading: (v: number | {
|
|
30
31
|
id: number;
|
|
31
32
|
}) => boolean;
|
|
32
|
-
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
34
|
+
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
33
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
34
36
|
refresh: () => void;
|
|
35
37
|
emptyCache: () => void;
|