@selfcommunity/react-core 0.4.9-alpha.4 → 0.4.9-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +1 -1
- package/lib/cjs/constants/Cache.d.ts +1 -0
- package/lib/cjs/constants/Cache.js +2 -1
- package/lib/cjs/constants/Notification.d.ts +4 -0
- package/lib/cjs/constants/Notification.js +4 -0
- package/lib/cjs/constants/Routes.d.ts +3 -0
- package/lib/cjs/constants/Routes.js +7 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +1 -2
- package/lib/cjs/hooks/useSCFetchGroup.js +10 -9
- package/lib/cjs/hooks/useSCFetchGroups.js +2 -2
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +61 -36
- package/lib/cjs/types/context.d.ts +1 -1
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +1 -1
- package/lib/esm/constants/Cache.d.ts +1 -0
- package/lib/esm/constants/Cache.js +1 -0
- package/lib/esm/constants/Notification.d.ts +4 -0
- package/lib/esm/constants/Notification.js +4 -0
- package/lib/esm/constants/Routes.d.ts +3 -0
- package/lib/esm/constants/Routes.js +6 -0
- package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -2
- package/lib/esm/hooks/useSCFetchGroup.js +10 -9
- package/lib/esm/hooks/useSCFetchGroups.js +2 -2
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +1 -1
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +62 -37
- package/lib/esm/types/context.d.ts +1 -1
- package/lib/umd/react-core.js +1 -1
- package/package.json +5 -5
|
@@ -48,7 +48,7 @@ function SCPreferencesProvider({ children = null }) {
|
|
|
48
48
|
Promise.all([api_services_1.PreferenceService.getAllPreferences(), api_services_1.FeatureService.getAllFeatures()])
|
|
49
49
|
.then(function ([preferences, features]) {
|
|
50
50
|
setPreferences(preferences['results'].reduce((obj, p) => (Object.assign(Object.assign({}, obj), { [`${p.section}.${p.name}`]: p })), {}));
|
|
51
|
-
setFeatures(features['results'].map((f) => f.name));
|
|
51
|
+
setFeatures(features['results'].filter((f) => f.enabled).map((f) => f.name));
|
|
52
52
|
setLoading(false);
|
|
53
53
|
})
|
|
54
54
|
.catch((_error) => {
|
|
@@ -71,4 +71,5 @@ export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget
|
|
|
71
71
|
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
72
72
|
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
73
73
|
export declare const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_glIST_";
|
|
74
|
+
export declare const GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = "_gSubWidget_";
|
|
74
75
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
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
|
+
exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = 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}`;
|
|
@@ -98,5 +98,6 @@ exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
|
98
98
|
exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
99
99
|
exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
100
100
|
exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_glIST_';
|
|
101
|
+
exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = '_gSubWidget_';
|
|
101
102
|
const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
102
103
|
exports.getWidgetStateCacheKey = getWidgetStateCacheKey;
|
|
@@ -44,6 +44,10 @@ export declare const SCNotificationMapping: {
|
|
|
44
44
|
83: SCNotificationTypologyType;
|
|
45
45
|
96: SCNotificationTypologyType;
|
|
46
46
|
99: SCNotificationTypologyType;
|
|
47
|
+
31: SCNotificationTypologyType;
|
|
48
|
+
32: SCNotificationTypologyType;
|
|
49
|
+
33: SCNotificationTypologyType;
|
|
50
|
+
34: SCNotificationTypologyType;
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
53
|
* Silent Snippet Notifications
|
|
@@ -47,6 +47,10 @@ exports.SCNotificationMapping = {
|
|
|
47
47
|
83: types_1.SCNotificationTypologyType.UNBLOCKED_USER,
|
|
48
48
|
96: types_1.SCNotificationTypologyType.INCUBATOR_APPROVED,
|
|
49
49
|
99: types_1.SCNotificationTypologyType.CUSTOM_NOTIFICATION,
|
|
50
|
+
31: types_1.SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP,
|
|
51
|
+
32: types_1.SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP,
|
|
52
|
+
33: types_1.SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP,
|
|
53
|
+
34: types_1.SCNotificationTypologyType.USER_ADDED_TO_GROUP
|
|
50
54
|
};
|
|
51
55
|
/**
|
|
52
56
|
* Silent Snippet Notifications
|
|
@@ -32,7 +32,10 @@ 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";
|
|
35
37
|
export declare const GROUPS_ROUTE_NAME = "groups";
|
|
38
|
+
export declare const GROUPS_SUBSCRIBED_ROUTE_NAME = "groups_subscribed";
|
|
36
39
|
/**
|
|
37
40
|
* Default Routes
|
|
38
41
|
* @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.GROUPS_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;
|
|
3
|
+
exports.defaultRoutes = exports.GROUPS_SUBSCRIBED_ROUTE_NAME = 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,7 +35,10 @@ 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';
|
|
38
40
|
exports.GROUPS_ROUTE_NAME = 'groups';
|
|
41
|
+
exports.GROUPS_SUBSCRIBED_ROUTE_NAME = 'groups_subscribed';
|
|
39
42
|
/**
|
|
40
43
|
* Default Routes
|
|
41
44
|
* @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}}
|
|
@@ -70,5 +73,8 @@ exports.defaultRoutes = {
|
|
|
70
73
|
[exports.CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
71
74
|
[exports.LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
72
75
|
[exports.GROUP_ROUTE_NAME]: '/group/:id/:slug/',
|
|
76
|
+
[exports.GROUP_MEMBERS_ROUTE_NAME]: '/group/:id/:slug/members/',
|
|
77
|
+
[exports.GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:slug/messages/',
|
|
73
78
|
[exports.GROUPS_ROUTE_NAME]: '/groups/',
|
|
79
|
+
[exports.GROUPS_SUBSCRIBED_ROUTE_NAME]: '/groups/subscribed/',
|
|
74
80
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { SCGroupType } from '@selfcommunity/types';
|
|
3
2
|
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
3
|
/**
|
|
@@ -16,6 +15,6 @@ export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
|
|
|
16
15
|
cacheStrategy?: CacheStrategies;
|
|
17
16
|
}): {
|
|
18
17
|
scGroup: SCGroupType;
|
|
19
|
-
setSCGroup:
|
|
18
|
+
setSCGroup: (group: SCGroupType) => void;
|
|
20
19
|
error: string;
|
|
21
20
|
};
|
|
@@ -24,8 +24,13 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
24
24
|
// CACHE
|
|
25
25
|
const __groupCacheKey = (0, Cache_1.getGroupObjectCacheKey)(__groupId);
|
|
26
26
|
const __group = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscription_status']);
|
|
27
|
-
const [scGroup,
|
|
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
|
+
const setSCGroup = (group) => {
|
|
30
|
+
const _c = authUserId ? group : (0, utils_1.objectWithoutProperties)(group, ['subscription_status']);
|
|
31
|
+
setScGroup(_c);
|
|
32
|
+
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
33
|
+
};
|
|
29
34
|
/**
|
|
30
35
|
* Memoized fetchTag
|
|
31
36
|
*/
|
|
@@ -49,9 +54,7 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
49
54
|
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
50
55
|
fetchGroup()
|
|
51
56
|
.then((obj) => {
|
|
52
|
-
|
|
53
|
-
setSCGroup(_c);
|
|
54
|
-
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
57
|
+
setSCGroup(obj);
|
|
55
58
|
})
|
|
56
59
|
.catch((err) => {
|
|
57
60
|
utils_1.LRUCache.delete(__groupCacheKey);
|
|
@@ -60,14 +63,12 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
60
63
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
61
64
|
});
|
|
62
65
|
}
|
|
63
|
-
}, [__groupId]);
|
|
66
|
+
}, [__groupId, authUserId]);
|
|
64
67
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
65
68
|
if (group) {
|
|
66
|
-
|
|
67
|
-
setSCGroup(_c);
|
|
68
|
-
utils_1.LRUCache.set(__groupCacheKey, _c);
|
|
69
|
+
setSCGroup(group);
|
|
69
70
|
}
|
|
70
|
-
}, [group]);
|
|
71
|
+
}, [group, authUserId]);
|
|
71
72
|
return { scGroup, setSCGroup, error };
|
|
72
73
|
}
|
|
73
74
|
exports.default = useSCFetchGroup;
|
|
@@ -46,10 +46,10 @@ const useSCFetchGroups = (props) => {
|
|
|
46
46
|
/**
|
|
47
47
|
* Fetch groups
|
|
48
48
|
*/
|
|
49
|
-
const fetchGroups = (next = api_services_1.Endpoints.
|
|
49
|
+
const fetchGroups = (next = api_services_1.Endpoints.GetUserGroups.url()) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
50
|
const response = yield api_services_1.http.request({
|
|
51
51
|
url: next,
|
|
52
|
-
method: api_services_1.Endpoints.
|
|
52
|
+
method: api_services_1.Endpoints.GetUserGroups.method,
|
|
53
53
|
});
|
|
54
54
|
const data = response.data;
|
|
55
55
|
if (data.next) {
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
34
34
|
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -3,9 +3,11 @@ 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");
|
|
10
|
+
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
9
11
|
/**
|
|
10
12
|
:::info
|
|
11
13
|
This custom hook is used to manage the groups followed.
|
|
@@ -22,7 +24,9 @@ const utils_1 = require("@selfcommunity/utils");
|
|
|
22
24
|
*/
|
|
23
25
|
function useSCSubscribedGroupsManager(user) {
|
|
24
26
|
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = (0, useSCCachingManager_1.default)();
|
|
27
|
+
const scPreferencesContext = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
25
28
|
const authUserId = user ? user.id : null;
|
|
29
|
+
const groupsDisabled = scPreferencesContext.features && !scPreferencesContext.features.includes(types_1.SCFeatureName.GROUPING);
|
|
26
30
|
/**
|
|
27
31
|
* Memoized refresh all groups
|
|
28
32
|
* It makes a single request to the server and retrieves
|
|
@@ -42,9 +46,9 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
42
46
|
if (res.status >= 300) {
|
|
43
47
|
return Promise.reject(res);
|
|
44
48
|
}
|
|
45
|
-
const groupsIds = res.data.map((g) => g.id);
|
|
49
|
+
const groupsIds = res.data.results.map((g) => g.id);
|
|
46
50
|
updateCache(groupsIds);
|
|
47
|
-
setData(
|
|
51
|
+
setData(res.data.results.map((g) => ({ [g.id]: g.subscription_status })));
|
|
48
52
|
return Promise.resolve(res.data);
|
|
49
53
|
})
|
|
50
54
|
.catch((e) => {
|
|
@@ -57,45 +61,66 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
57
61
|
* Memoized subscribe Group
|
|
58
62
|
* Toggle action
|
|
59
63
|
*/
|
|
60
|
-
const subscribe = (0, react_1.useMemo)(() => (group) => {
|
|
64
|
+
const subscribe = (0, react_1.useMemo)(() => (group, userId) => {
|
|
61
65
|
setLoading(group.id);
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
if (userId) {
|
|
67
|
+
return api_services_1.http
|
|
68
|
+
.request({
|
|
69
|
+
url: api_services_1.Endpoints.InviteOrAcceptGroupRequest.url({ id: group.id }),
|
|
70
|
+
method: api_services_1.Endpoints.InviteOrAcceptGroupRequest.method,
|
|
71
|
+
data: { users: [userId] },
|
|
72
|
+
})
|
|
73
|
+
.then((res) => {
|
|
74
|
+
if (res.status >= 300) {
|
|
75
|
+
return Promise.reject(res);
|
|
76
|
+
}
|
|
77
|
+
updateCache([group.id]);
|
|
78
|
+
setData((prev) => getDataUpdated(prev, group.id, types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
79
|
+
setUnLoading(group.id);
|
|
80
|
+
return Promise.resolve(res.data);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return api_services_1.http
|
|
85
|
+
.request({
|
|
86
|
+
url: api_services_1.Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
87
|
+
method: api_services_1.Endpoints.SubscribeToGroup.method,
|
|
88
|
+
})
|
|
89
|
+
.then((res) => {
|
|
90
|
+
if (res.status >= 300) {
|
|
91
|
+
return Promise.reject(res);
|
|
92
|
+
}
|
|
93
|
+
updateCache([group.id]);
|
|
94
|
+
setData((prev) => getDataUpdated(prev, group.id, group.privacy === types_1.SCGroupPrivacyType.PRIVATE && group.subscription_status !== types_1.SCGroupSubscriptionStatusType.INVITED
|
|
95
|
+
? types_1.SCGroupSubscriptionStatusType.REQUESTED
|
|
96
|
+
: types_1.SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
97
|
+
setUnLoading(group.id);
|
|
98
|
+
return Promise.resolve(res.data);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
77
101
|
}, [data, loading, cache]);
|
|
78
102
|
/**
|
|
79
103
|
* Memoized subscribe Group
|
|
80
104
|
* Toggle action
|
|
81
105
|
*/
|
|
82
106
|
const unsubscribe = (0, react_1.useMemo)(() => (group) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
if (group.subscription_status !== types_1.SCGroupSubscriptionStatusType.REQUESTED) {
|
|
108
|
+
setLoading(group.id);
|
|
109
|
+
return api_services_1.http
|
|
110
|
+
.request({
|
|
111
|
+
url: api_services_1.Endpoints.UnsubscribeFromGroup.url({ id: group.id }),
|
|
112
|
+
method: api_services_1.Endpoints.UnsubscribeFromGroup.method,
|
|
113
|
+
})
|
|
114
|
+
.then((res) => {
|
|
115
|
+
if (res.status >= 300) {
|
|
116
|
+
return Promise.reject(res);
|
|
117
|
+
}
|
|
118
|
+
updateCache([group.id]);
|
|
119
|
+
setData((prev) => getDataUpdated(prev, group.id, null));
|
|
120
|
+
setUnLoading(group.id);
|
|
121
|
+
return Promise.resolve(res.data);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
99
124
|
}, [data, loading, cache]);
|
|
100
125
|
/**
|
|
101
126
|
* Check the authenticated user subscription status to the group
|
|
@@ -181,7 +206,7 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
181
206
|
}
|
|
182
207
|
}
|
|
183
208
|
return null;
|
|
184
|
-
}, [
|
|
209
|
+
}, [loading, cache, authUserId]);
|
|
185
210
|
/**
|
|
186
211
|
* Empty cache on logout
|
|
187
212
|
*/
|
|
@@ -190,7 +215,7 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
190
215
|
emptyCache();
|
|
191
216
|
}
|
|
192
217
|
}, [authUserId]);
|
|
193
|
-
if (!user) {
|
|
218
|
+
if (groupsDisabled || !user) {
|
|
194
219
|
return { groups: data, loading, isLoading };
|
|
195
220
|
}
|
|
196
221
|
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|
|
@@ -265,7 +265,7 @@ 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
269
|
/**
|
|
270
270
|
* Handle user unsubscription from a group
|
|
271
271
|
*/
|
|
@@ -44,7 +44,7 @@ export default function SCPreferencesProvider({ children = null }) {
|
|
|
44
44
|
Promise.all([PreferenceService.getAllPreferences(), FeatureService.getAllFeatures()])
|
|
45
45
|
.then(function ([preferences, features]) {
|
|
46
46
|
setPreferences(preferences['results'].reduce((obj, p) => (Object.assign(Object.assign({}, obj), { [`${p.section}.${p.name}`]: p })), {}));
|
|
47
|
-
setFeatures(features['results'].map((f) => f.name));
|
|
47
|
+
setFeatures(features['results'].filter((f) => f.enabled).map((f) => f.name));
|
|
48
48
|
setLoading(false);
|
|
49
49
|
})
|
|
50
50
|
.catch((_error) => {
|
|
@@ -71,4 +71,5 @@ export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget
|
|
|
71
71
|
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
72
72
|
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
73
73
|
export declare const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_glIST_";
|
|
74
|
+
export declare const GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = "_gSubWidget_";
|
|
74
75
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -75,4 +75,5 @@ export const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
|
75
75
|
export const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
76
76
|
export const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
77
77
|
export const GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_glIST_';
|
|
78
|
+
export const GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = '_gSubWidget_';
|
|
78
79
|
export const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
@@ -44,6 +44,10 @@ export declare const SCNotificationMapping: {
|
|
|
44
44
|
83: SCNotificationTypologyType;
|
|
45
45
|
96: SCNotificationTypologyType;
|
|
46
46
|
99: SCNotificationTypologyType;
|
|
47
|
+
31: SCNotificationTypologyType;
|
|
48
|
+
32: SCNotificationTypologyType;
|
|
49
|
+
33: SCNotificationTypologyType;
|
|
50
|
+
34: SCNotificationTypologyType;
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
53
|
* Silent Snippet Notifications
|
|
@@ -44,6 +44,10 @@ export const SCNotificationMapping = {
|
|
|
44
44
|
83: SCNotificationTypologyType.UNBLOCKED_USER,
|
|
45
45
|
96: SCNotificationTypologyType.INCUBATOR_APPROVED,
|
|
46
46
|
99: SCNotificationTypologyType.CUSTOM_NOTIFICATION,
|
|
47
|
+
31: SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP,
|
|
48
|
+
32: SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP,
|
|
49
|
+
33: SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP,
|
|
50
|
+
34: SCNotificationTypologyType.USER_ADDED_TO_GROUP
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
53
|
* Silent Snippet Notifications
|
|
@@ -32,7 +32,10 @@ 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";
|
|
35
37
|
export declare const GROUPS_ROUTE_NAME = "groups";
|
|
38
|
+
export declare const GROUPS_SUBSCRIBED_ROUTE_NAME = "groups_subscribed";
|
|
36
39
|
/**
|
|
37
40
|
* Default Routes
|
|
38
41
|
* @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,7 +32,10 @@ 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';
|
|
35
37
|
export const GROUPS_ROUTE_NAME = 'groups';
|
|
38
|
+
export const GROUPS_SUBSCRIBED_ROUTE_NAME = 'groups_subscribed';
|
|
36
39
|
/**
|
|
37
40
|
* Default Routes
|
|
38
41
|
* @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,5 +70,8 @@ export const defaultRoutes = {
|
|
|
67
70
|
[CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
68
71
|
[LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
69
72
|
[GROUP_ROUTE_NAME]: '/group/:id/:slug/',
|
|
73
|
+
[GROUP_MEMBERS_ROUTE_NAME]: '/group/:id/:slug/members/',
|
|
74
|
+
[GROUP_MESSAGES_ROUTE_NAME]: '/group/:id/:slug/messages/',
|
|
70
75
|
[GROUPS_ROUTE_NAME]: '/groups/',
|
|
76
|
+
[GROUPS_SUBSCRIBED_ROUTE_NAME]: '/groups/subscribed/',
|
|
71
77
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { SCGroupType } from '@selfcommunity/types';
|
|
3
2
|
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
3
|
/**
|
|
@@ -16,6 +15,6 @@ export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
|
|
|
16
15
|
cacheStrategy?: CacheStrategies;
|
|
17
16
|
}): {
|
|
18
17
|
scGroup: SCGroupType;
|
|
19
|
-
setSCGroup:
|
|
18
|
+
setSCGroup: (group: SCGroupType) => void;
|
|
20
19
|
error: string;
|
|
21
20
|
};
|
|
@@ -22,8 +22,13 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
22
22
|
// CACHE
|
|
23
23
|
const __groupCacheKey = getGroupObjectCacheKey(__groupId);
|
|
24
24
|
const __group = authUserId ? group : objectWithoutProperties(group, ['subscription_status']);
|
|
25
|
-
const [scGroup,
|
|
25
|
+
const [scGroup, setScGroup] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__groupCacheKey, __group) : null);
|
|
26
26
|
const [error, setError] = useState(null);
|
|
27
|
+
const setSCGroup = (group) => {
|
|
28
|
+
const _c = authUserId ? group : objectWithoutProperties(group, ['subscription_status']);
|
|
29
|
+
setScGroup(_c);
|
|
30
|
+
LRUCache.set(__groupCacheKey, _c);
|
|
31
|
+
};
|
|
27
32
|
/**
|
|
28
33
|
* Memoized fetchTag
|
|
29
34
|
*/
|
|
@@ -47,9 +52,7 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
47
52
|
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
48
53
|
fetchGroup()
|
|
49
54
|
.then((obj) => {
|
|
50
|
-
|
|
51
|
-
setSCGroup(_c);
|
|
52
|
-
LRUCache.set(__groupCacheKey, _c);
|
|
55
|
+
setSCGroup(obj);
|
|
53
56
|
})
|
|
54
57
|
.catch((err) => {
|
|
55
58
|
LRUCache.delete(__groupCacheKey);
|
|
@@ -58,13 +61,11 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
58
61
|
Logger.error(SCOPE_SC_CORE, err.message);
|
|
59
62
|
});
|
|
60
63
|
}
|
|
61
|
-
}, [__groupId]);
|
|
64
|
+
}, [__groupId, authUserId]);
|
|
62
65
|
useDeepCompareEffectNoCheck(() => {
|
|
63
66
|
if (group) {
|
|
64
|
-
|
|
65
|
-
setSCGroup(_c);
|
|
66
|
-
LRUCache.set(__groupCacheKey, _c);
|
|
67
|
+
setSCGroup(group);
|
|
67
68
|
}
|
|
68
|
-
}, [group]);
|
|
69
|
+
}, [group, authUserId]);
|
|
69
70
|
return { scGroup, setSCGroup, error };
|
|
70
71
|
}
|
|
@@ -44,10 +44,10 @@ const useSCFetchGroups = (props) => {
|
|
|
44
44
|
/**
|
|
45
45
|
* Fetch groups
|
|
46
46
|
*/
|
|
47
|
-
const fetchGroups = (next = Endpoints.
|
|
47
|
+
const fetchGroups = (next = Endpoints.GetUserGroups.url()) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
48
|
const response = yield http.request({
|
|
49
49
|
url: next,
|
|
50
|
-
method: Endpoints.
|
|
50
|
+
method: Endpoints.GetUserGroups.method,
|
|
51
51
|
});
|
|
52
52
|
const data = response.data;
|
|
53
53
|
if (data.next) {
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscribe: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
34
34
|
unsubscribe: (group: SCGroupType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (group: SCGroupType) => string;
|
|
36
36
|
refresh: () => void;
|