@selfcommunity/react-core 0.4.9-alpha.25 → 0.4.9-alpha.27
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/hooks/useSCFetchGroup.d.ts +1 -2
- package/lib/cjs/hooks/useSCFetchGroup.js +8 -7
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +4 -1
- package/lib/esm/hooks/useSCFetchGroup.d.ts +1 -2
- package/lib/esm/hooks/useSCFetchGroup.js +8 -7
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +5 -2
- package/lib/umd/react-core.js +1 -1
- package/package.json +3 -3
|
@@ -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);
|
|
@@ -63,9 +66,7 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
|
|
|
63
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
71
|
}, [group, authUserId]);
|
|
71
72
|
return { scGroup, setSCGroup, error };
|
|
@@ -7,6 +7,7 @@ const types_1 = require("@selfcommunity/types");
|
|
|
7
7
|
const useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
8
8
|
const Errors_1 = require("../constants/Errors");
|
|
9
9
|
const utils_1 = require("@selfcommunity/utils");
|
|
10
|
+
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
10
11
|
/**
|
|
11
12
|
:::info
|
|
12
13
|
This custom hook is used to manage the groups followed.
|
|
@@ -23,7 +24,9 @@ const utils_1 = require("@selfcommunity/utils");
|
|
|
23
24
|
*/
|
|
24
25
|
function useSCSubscribedGroupsManager(user) {
|
|
25
26
|
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = (0, useSCCachingManager_1.default)();
|
|
27
|
+
const scPreferencesContext = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
26
28
|
const authUserId = user ? user.id : null;
|
|
29
|
+
const groupsDisabled = scPreferencesContext.features && !scPreferencesContext.features.includes(types_1.SCFeatureName.GROUPING);
|
|
27
30
|
/**
|
|
28
31
|
* Memoized refresh all groups
|
|
29
32
|
* It makes a single request to the server and retrieves
|
|
@@ -212,7 +215,7 @@ function useSCSubscribedGroupsManager(user) {
|
|
|
212
215
|
emptyCache();
|
|
213
216
|
}
|
|
214
217
|
}, [authUserId]);
|
|
215
|
-
if (!user) {
|
|
218
|
+
if (groupsDisabled || !user) {
|
|
216
219
|
return { groups: data, loading, isLoading };
|
|
217
220
|
}
|
|
218
221
|
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|
|
@@ -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);
|
|
@@ -61,9 +64,7 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
|
|
|
61
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
69
|
}, [group, authUserId]);
|
|
69
70
|
return { scGroup, setSCGroup, error };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react';
|
|
2
2
|
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
3
|
-
import { SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
3
|
+
import { SCFeatureName, SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
4
4
|
import useSCCachingManager from './useSCCachingManager';
|
|
5
5
|
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
6
6
|
import { Logger } from '@selfcommunity/utils';
|
|
7
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
7
8
|
/**
|
|
8
9
|
:::info
|
|
9
10
|
This custom hook is used to manage the groups followed.
|
|
@@ -20,7 +21,9 @@ import { Logger } from '@selfcommunity/utils';
|
|
|
20
21
|
*/
|
|
21
22
|
export default function useSCSubscribedGroupsManager(user) {
|
|
22
23
|
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
24
|
+
const scPreferencesContext = useSCPreferences();
|
|
23
25
|
const authUserId = user ? user.id : null;
|
|
26
|
+
const groupsDisabled = scPreferencesContext.features && !scPreferencesContext.features.includes(SCFeatureName.GROUPING);
|
|
24
27
|
/**
|
|
25
28
|
* Memoized refresh all groups
|
|
26
29
|
* It makes a single request to the server and retrieves
|
|
@@ -209,7 +212,7 @@ export default function useSCSubscribedGroupsManager(user) {
|
|
|
209
212
|
emptyCache();
|
|
210
213
|
}
|
|
211
214
|
}, [authUserId]);
|
|
212
|
-
if (!user) {
|
|
215
|
+
if (groupsDisabled || !user) {
|
|
213
216
|
return { groups: data, loading, isLoading };
|
|
214
217
|
}
|
|
215
218
|
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|