@selfcommunity/react-core 0.4.0-alpha.113 → 0.4.0-alpha.115
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/SCVoteProvider/index.d.ts +1 -1
- package/lib/cjs/components/provider/SCVoteProvider/index.js +14 -31
- package/lib/cjs/constants/Cache.d.ts +0 -5
- package/lib/cjs/constants/Cache.js +1 -11
- package/lib/cjs/hooks/useSCFetchVote.js +5 -3
- package/lib/cjs/index.d.ts +1 -2
- package/lib/cjs/index.js +1 -3
- package/lib/cjs/types/context.d.ts +4 -0
- package/lib/esm/components/provider/SCVoteProvider/index.d.ts +1 -1
- package/lib/esm/components/provider/SCVoteProvider/index.js +16 -33
- package/lib/esm/constants/Cache.d.ts +0 -5
- package/lib/esm/constants/Cache.js +0 -7
- package/lib/esm/hooks/useSCFetchVote.js +5 -2
- package/lib/esm/index.d.ts +1 -2
- package/lib/esm/index.js +1 -2
- package/lib/esm/types/context.d.ts +4 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +3 -3
- package/lib/cjs/hooks/useSCFetchReactions.d.ts +0 -23
- package/lib/cjs/hooks/useSCFetchReactions.js +0 -75
- package/lib/esm/hooks/useSCFetchReactions.d.ts +0 -23
- package/lib/esm/hooks/useSCFetchReactions.js +0 -73
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfcommunity/react-core",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.115",
|
|
4
4
|
"description": "React Core Components useful for integrating UI Community components (react-ui).",
|
|
5
5
|
"author": "SelfCommunity <https://www.selfcommunity.com>",
|
|
6
6
|
"homepage": "https://www.selfcommunity.com",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@selfcommunity/api-services": "^0.4.0-alpha.39",
|
|
72
|
-
"@selfcommunity/react-i18n": "^0.5.0-alpha.
|
|
72
|
+
"@selfcommunity/react-i18n": "^0.5.0-alpha.59",
|
|
73
73
|
"@selfcommunity/types": "^0.5.0-alpha.16",
|
|
74
74
|
"@selfcommunity/utils": "^0.2.0-alpha.12",
|
|
75
75
|
"js-cookie": "^3.0.5",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"bugs": {
|
|
126
126
|
"url": "https://github.com/selfcommunity/community-js/issues"
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "2298f733030a4f3e96253985b0676f2c666ff520"
|
|
129
129
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SCReactionType } from '@selfcommunity/types';
|
|
2
|
-
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
-
/**
|
|
4
|
-
:::info
|
|
5
|
-
This custom hook is used to fetch reactions.
|
|
6
|
-
@param object.cacheStrategy
|
|
7
|
-
|
|
8
|
-
:::tipContext can be consumed in this way:
|
|
9
|
-
|
|
10
|
-
```jsx
|
|
11
|
-
const {reactions, isLoading} = useSCFetchReactions();
|
|
12
|
-
```
|
|
13
|
-
:::
|
|
14
|
-
* @param props
|
|
15
|
-
*/
|
|
16
|
-
declare const useSCFetchReactions: (props?: {
|
|
17
|
-
cacheStrategy?: CacheStrategies;
|
|
18
|
-
}) => {
|
|
19
|
-
default: SCReactionType;
|
|
20
|
-
reactions: SCReactionType[];
|
|
21
|
-
isLoading: boolean;
|
|
22
|
-
};
|
|
23
|
-
export default useSCFetchReactions;
|
|
@@ -1,75 +0,0 @@
|
|
|
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 types_1 = require("@selfcommunity/types");
|
|
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 SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
10
|
-
const init = { default: null, reactions: [], isLoading: true };
|
|
11
|
-
// HYDRATE the cache
|
|
12
|
-
const hydrate = (ids) => {
|
|
13
|
-
if (!ids) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
const reactions = ids.map((id) => {
|
|
17
|
-
const __categoryCacheKey = (0, Cache_1.getReactionObjectCacheKey)(id);
|
|
18
|
-
return utils_1.LRUCache.get(__categoryCacheKey);
|
|
19
|
-
});
|
|
20
|
-
if (reactions.filter((c) => !c).length > 0) {
|
|
21
|
-
// REVALIDATE CACHE
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return reactions;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
:::info
|
|
28
|
-
This custom hook is used to fetch reactions.
|
|
29
|
-
@param object.cacheStrategy
|
|
30
|
-
|
|
31
|
-
:::tipContext can be consumed in this way:
|
|
32
|
-
|
|
33
|
-
```jsx
|
|
34
|
-
const {reactions, isLoading} = useSCFetchReactions();
|
|
35
|
-
```
|
|
36
|
-
:::
|
|
37
|
-
* @param props
|
|
38
|
-
*/
|
|
39
|
-
const useSCFetchReactions = (props) => {
|
|
40
|
-
// HOOKS
|
|
41
|
-
const scPreferences = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
42
|
-
// PROPS
|
|
43
|
-
const { cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST } = props || {};
|
|
44
|
-
// CACHE
|
|
45
|
-
const __reactionsCacheKey = (0, Cache_1.getReactionsObjectCacheKey)();
|
|
46
|
-
// STATE
|
|
47
|
-
const reactions = cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? hydrate(utils_1.LRUCache.get(__reactionsCacheKey, null)) : null;
|
|
48
|
-
const [data, setData] = (0, react_1.useState)(reactions !== null ? { default: reactions.find((reaction) => reaction.id === 1), reactions, isLoading: false } : init);
|
|
49
|
-
/**
|
|
50
|
-
* Get reactions
|
|
51
|
-
*/
|
|
52
|
-
(0, react_1.useEffect)(() => {
|
|
53
|
-
if (cacheStrategy === utils_1.CacheStrategies.CACHE_FIRST && reactions) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (!scPreferences.features || !scPreferences.features.includes(types_1.SCFeatureName.REACTION)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
api_services_1.ReactionService.getAllReactionsList()
|
|
60
|
-
.then((data) => {
|
|
61
|
-
setData({ reactions: data, isLoading: false, default: data.find((reaction) => reaction.id === 1) });
|
|
62
|
-
utils_1.LRUCache.set(__reactionsCacheKey, data.map((r) => {
|
|
63
|
-
const __categoryCacheKey = (0, Cache_1.getReactionObjectCacheKey)(r.id);
|
|
64
|
-
utils_1.LRUCache.set(__categoryCacheKey, r);
|
|
65
|
-
return r.id;
|
|
66
|
-
}));
|
|
67
|
-
})
|
|
68
|
-
.catch((error) => {
|
|
69
|
-
console.log(error);
|
|
70
|
-
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to retrieve reactions');
|
|
71
|
-
});
|
|
72
|
-
}, []);
|
|
73
|
-
return data;
|
|
74
|
-
};
|
|
75
|
-
exports.default = useSCFetchReactions;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SCReactionType } from '@selfcommunity/types';
|
|
2
|
-
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
-
/**
|
|
4
|
-
:::info
|
|
5
|
-
This custom hook is used to fetch reactions.
|
|
6
|
-
@param object.cacheStrategy
|
|
7
|
-
|
|
8
|
-
:::tipContext can be consumed in this way:
|
|
9
|
-
|
|
10
|
-
```jsx
|
|
11
|
-
const {reactions, isLoading} = useSCFetchReactions();
|
|
12
|
-
```
|
|
13
|
-
:::
|
|
14
|
-
* @param props
|
|
15
|
-
*/
|
|
16
|
-
declare const useSCFetchReactions: (props?: {
|
|
17
|
-
cacheStrategy?: CacheStrategies;
|
|
18
|
-
}) => {
|
|
19
|
-
default: SCReactionType;
|
|
20
|
-
reactions: SCReactionType[];
|
|
21
|
-
isLoading: boolean;
|
|
22
|
-
};
|
|
23
|
-
export default useSCFetchReactions;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
3
|
-
import { SCFeatureName } from '@selfcommunity/types';
|
|
4
|
-
import { ReactionService } from '@selfcommunity/api-services';
|
|
5
|
-
import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
6
|
-
import { getReactionObjectCacheKey, getReactionsObjectCacheKey } from '../constants/Cache';
|
|
7
|
-
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
8
|
-
const init = { default: null, reactions: [], isLoading: true };
|
|
9
|
-
// HYDRATE the cache
|
|
10
|
-
const hydrate = (ids) => {
|
|
11
|
-
if (!ids) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const reactions = ids.map((id) => {
|
|
15
|
-
const __categoryCacheKey = getReactionObjectCacheKey(id);
|
|
16
|
-
return LRUCache.get(__categoryCacheKey);
|
|
17
|
-
});
|
|
18
|
-
if (reactions.filter((c) => !c).length > 0) {
|
|
19
|
-
// REVALIDATE CACHE
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
return reactions;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
:::info
|
|
26
|
-
This custom hook is used to fetch reactions.
|
|
27
|
-
@param object.cacheStrategy
|
|
28
|
-
|
|
29
|
-
:::tipContext can be consumed in this way:
|
|
30
|
-
|
|
31
|
-
```jsx
|
|
32
|
-
const {reactions, isLoading} = useSCFetchReactions();
|
|
33
|
-
```
|
|
34
|
-
:::
|
|
35
|
-
* @param props
|
|
36
|
-
*/
|
|
37
|
-
const useSCFetchReactions = (props) => {
|
|
38
|
-
// HOOKS
|
|
39
|
-
const scPreferences = useSCPreferences();
|
|
40
|
-
// PROPS
|
|
41
|
-
const { cacheStrategy = CacheStrategies.CACHE_FIRST } = props || {};
|
|
42
|
-
// CACHE
|
|
43
|
-
const __reactionsCacheKey = getReactionsObjectCacheKey();
|
|
44
|
-
// STATE
|
|
45
|
-
const reactions = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__reactionsCacheKey, null)) : null;
|
|
46
|
-
const [data, setData] = useState(reactions !== null ? { default: reactions.find((reaction) => reaction.id === 1), reactions, isLoading: false } : init);
|
|
47
|
-
/**
|
|
48
|
-
* Get reactions
|
|
49
|
-
*/
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (cacheStrategy === CacheStrategies.CACHE_FIRST && reactions) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (!scPreferences.features || !scPreferences.features.includes(SCFeatureName.REACTION)) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
ReactionService.getAllReactionsList()
|
|
58
|
-
.then((data) => {
|
|
59
|
-
setData({ reactions: data, isLoading: false, default: data.find((reaction) => reaction.id === 1) });
|
|
60
|
-
LRUCache.set(__reactionsCacheKey, data.map((r) => {
|
|
61
|
-
const __categoryCacheKey = getReactionObjectCacheKey(r.id);
|
|
62
|
-
LRUCache.set(__categoryCacheKey, r);
|
|
63
|
-
return r.id;
|
|
64
|
-
}));
|
|
65
|
-
})
|
|
66
|
-
.catch((error) => {
|
|
67
|
-
console.log(error);
|
|
68
|
-
Logger.error(SCOPE_SC_CORE, 'Unable to retrieve reactions');
|
|
69
|
-
});
|
|
70
|
-
}, []);
|
|
71
|
-
return data;
|
|
72
|
-
};
|
|
73
|
-
export default useSCFetchReactions;
|