@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
|
@@ -24,7 +24,7 @@ export declare const SCVoteContext: React.Context<SCVoteContextType>;
|
|
|
24
24
|
* @param children
|
|
25
25
|
* @return
|
|
26
26
|
* ```jsx
|
|
27
|
-
* <SCVoteContext.Provider value={{reactions}}>{!
|
|
27
|
+
* <SCVoteContext.Provider value={{reactions}}>{!isLoading && children}</SCVoteContext.Provider>
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export default function SCVoteProvider({ children }: {
|
|
@@ -8,7 +8,6 @@ const utils_1 = require("@selfcommunity/utils");
|
|
|
8
8
|
const Errors_1 = require("../../../constants/Errors");
|
|
9
9
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
10
10
|
const types_1 = require("@selfcommunity/types");
|
|
11
|
-
const Cache_1 = require("../../../constants/Cache");
|
|
12
11
|
const SCPreferencesProvider_1 = require("../SCPreferencesProvider");
|
|
13
12
|
/**
|
|
14
13
|
* Creates Vote Context
|
|
@@ -34,72 +33,56 @@ exports.SCVoteContext = (0, react_1.createContext)({});
|
|
|
34
33
|
* @param children
|
|
35
34
|
* @return
|
|
36
35
|
* ```jsx
|
|
37
|
-
* <SCVoteContext.Provider value={{reactions}}>{!
|
|
36
|
+
* <SCVoteContext.Provider value={{reactions}}>{!isLoading && children}</SCVoteContext.Provider>
|
|
38
37
|
* ```
|
|
39
38
|
*/
|
|
40
39
|
function SCVoteProvider({ children = null }) {
|
|
41
40
|
const scContext = (0, SCContextProvider_1.useSCContext)();
|
|
42
41
|
const scPreferencesContext = (0, react_1.useContext)(SCPreferencesProvider_1.SCPreferencesContext);
|
|
43
|
-
const [reactions] = (0, react_1.useState)(scContext.settings.vote.reactions);
|
|
42
|
+
const [reactions, setReactions] = (0, react_1.useState)(scContext.settings.vote.reactions);
|
|
44
43
|
const [, setError] = (0, react_1.useState)();
|
|
45
|
-
const [initialized, setInitialized] = (0, react_1.useState)(scContext.settings.vote.reactions !== null);
|
|
46
|
-
const [
|
|
47
|
-
/**
|
|
48
|
-
* Hydrate reactions cache
|
|
49
|
-
* @param data
|
|
50
|
-
*/
|
|
51
|
-
const hydrateCache = (data) => {
|
|
52
|
-
if (data && Array.isArray(data) && data.length) {
|
|
53
|
-
utils_1.LRUCache.set((0, Cache_1.getReactionsObjectCacheKey)(), data.map((r) => {
|
|
54
|
-
const __reactionCacheKey = (0, Cache_1.getReactionObjectCacheKey)(r.id);
|
|
55
|
-
utils_1.LRUCache.set(__reactionCacheKey, r, { noSsr: false });
|
|
56
|
-
return r.id;
|
|
57
|
-
}), { noSsr: false });
|
|
58
|
-
}
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
44
|
+
const [initialized, setInitialized] = (0, react_1.useState)((scPreferencesContext.features && !scPreferencesContext.features.includes(types_1.SCFeatureName.REACTION)) || scContext.settings.vote.reactions !== null);
|
|
45
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(scPreferencesContext.features && scPreferencesContext.features.includes(types_1.SCFeatureName.REACTION) && scContext.settings.vote.reactions === null);
|
|
61
46
|
/**
|
|
62
47
|
* Helper to refresh reactions list
|
|
63
48
|
*/
|
|
64
|
-
const refreshReactions = (0, react_1.
|
|
65
|
-
|
|
49
|
+
const refreshReactions = (0, react_1.useCallback)(() => api_services_1.ReactionService.getAllReactionsList().then((data) => {
|
|
50
|
+
setReactions(data);
|
|
51
|
+
return data;
|
|
66
52
|
}), []);
|
|
67
53
|
/**
|
|
68
54
|
* Initialize component
|
|
69
55
|
* Load all reactions if the feature 'reaction' is enabled
|
|
70
56
|
*/
|
|
71
|
-
const _initComponent = (0, react_1.
|
|
57
|
+
const _initComponent = (0, react_1.useCallback)(() => {
|
|
72
58
|
if (!initialized) {
|
|
73
59
|
setInitialized(true);
|
|
74
|
-
|
|
60
|
+
setIsLoading(true);
|
|
75
61
|
refreshReactions()
|
|
76
62
|
.then(() => {
|
|
77
|
-
|
|
63
|
+
setIsLoading(false);
|
|
78
64
|
})
|
|
79
65
|
.catch((_error) => {
|
|
80
66
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, _error);
|
|
81
67
|
setError(_error);
|
|
82
68
|
});
|
|
83
69
|
}
|
|
84
|
-
|
|
85
|
-
hydrateCache(reactions);
|
|
86
|
-
}
|
|
87
|
-
}, [loading, reactions, initialized]);
|
|
70
|
+
}, [isLoading, initialized]);
|
|
88
71
|
// EFFECTS
|
|
89
72
|
(0, react_1.useEffect)(() => {
|
|
90
73
|
let _t;
|
|
91
|
-
if (scPreferencesContext.features && scPreferencesContext.features.includes(types_1.SCFeatureName.REACTION)) {
|
|
74
|
+
if (scPreferencesContext.features && scPreferencesContext.features.includes(types_1.SCFeatureName.REACTION) && !reactions) {
|
|
92
75
|
_t = setTimeout(_initComponent);
|
|
93
76
|
return () => {
|
|
94
77
|
_t && clearTimeout(_t);
|
|
95
78
|
};
|
|
96
79
|
}
|
|
97
|
-
}, [scPreferencesContext.features]);
|
|
80
|
+
}, [scPreferencesContext.features, reactions]);
|
|
98
81
|
/**
|
|
99
82
|
* Nesting all necessary providers
|
|
100
83
|
* All child components will use help contexts to works
|
|
101
84
|
*/
|
|
102
|
-
return react_1.default.createElement(exports.SCVoteContext.Provider, { value: { reactions, refreshReactions } }, initialized && children);
|
|
85
|
+
return react_1.default.createElement(exports.SCVoteContext.Provider, { value: { reactions, isLoading, refreshReactions } }, initialized && children);
|
|
103
86
|
}
|
|
104
87
|
exports.default = SCVoteProvider;
|
|
105
88
|
/**
|
|
@@ -36,11 +36,6 @@ export declare const VIRTUALIZED_SCROLL_STATE_CACHE_PREFIX_KEY = "_virtualized_s
|
|
|
36
36
|
export declare const getVirtualizedScrollStateCacheKey: (id: any) => string;
|
|
37
37
|
export declare const FEED_CACHE_SP_KEY = "_feed_spos_";
|
|
38
38
|
export declare const getFeedSPCacheKey: (id: any) => string;
|
|
39
|
-
/** REACTIONS **/
|
|
40
|
-
export declare const REACTIONS_OBJECT_CACHE_PREFIX_KEY = "_res_";
|
|
41
|
-
export declare const getReactionsObjectCacheKey: () => string;
|
|
42
|
-
export declare const REACTION_OBJECT_CACHE_PREFIX_KEY = "_re_";
|
|
43
|
-
export declare const getReactionObjectCacheKey: (id: any) => string;
|
|
44
39
|
/** CUSTOM ADVERTISING **/
|
|
45
40
|
export declare const ADV_OBJECT_CACHE_PREFIX_KEY = "_adv_";
|
|
46
41
|
export declare const getAdvObjectCacheKey: (id: any) => string;
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Cache prefixes
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
7
|
-
exports.getWidgetStateCacheKey = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
6
|
+
exports.getWidgetStateCacheKey = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = 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.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;
|
|
8
7
|
/** FEED OBJECT **/
|
|
9
8
|
exports.FEED_OBJECT_CACHE_PREFIX_KEY = '_fo_';
|
|
10
9
|
const getFeedObjectCacheKey = (id, type) => `${exports.FEED_OBJECT_CACHE_PREFIX_KEY}${type}_${id}`;
|
|
@@ -58,15 +57,6 @@ exports.getVirtualizedScrollStateCacheKey = getVirtualizedScrollStateCacheKey;
|
|
|
58
57
|
exports.FEED_CACHE_SP_KEY = '_feed_spos_';
|
|
59
58
|
const getFeedSPCacheKey = (id) => `${exports.FEED_CACHE_SP_KEY}${id}`;
|
|
60
59
|
exports.getFeedSPCacheKey = getFeedSPCacheKey;
|
|
61
|
-
/** REACTIONS **/
|
|
62
|
-
// Reactions Object
|
|
63
|
-
exports.REACTIONS_OBJECT_CACHE_PREFIX_KEY = '_res_';
|
|
64
|
-
const getReactionsObjectCacheKey = () => `${exports.REACTIONS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
65
|
-
exports.getReactionsObjectCacheKey = getReactionsObjectCacheKey;
|
|
66
|
-
// Reaction Object
|
|
67
|
-
exports.REACTION_OBJECT_CACHE_PREFIX_KEY = '_re_';
|
|
68
|
-
const getReactionObjectCacheKey = (id) => `${exports.REACTION_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
69
|
-
exports.getReactionObjectCacheKey = getReactionObjectCacheKey;
|
|
70
60
|
/** CUSTOM ADVERTISING **/
|
|
71
61
|
exports.ADV_OBJECT_CACHE_PREFIX_KEY = '_adv_';
|
|
72
62
|
const getAdvObjectCacheKey = (id) => `${exports.ADV_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
3
|
const react_1 = require("react");
|
|
5
4
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
5
|
const utils_1 = require("@selfcommunity/utils");
|
|
7
6
|
const Errors_1 = require("../constants/Errors");
|
|
8
7
|
const types_1 = require("@selfcommunity/types");
|
|
9
8
|
const Cache_1 = require("../constants/Cache");
|
|
10
|
-
const useSCFetchReactions_1 = tslib_1.__importDefault(require("./useSCFetchReactions"));
|
|
11
9
|
const SCContextProvider_1 = require("../components/provider/SCContextProvider");
|
|
12
10
|
const SCUserProvider_1 = require("../components/provider/SCUserProvider");
|
|
11
|
+
const SCVoteProvider_1 = require("../components/provider/SCVoteProvider");
|
|
13
12
|
/**
|
|
14
13
|
:::info
|
|
15
14
|
This custom hook is used to fetch a contribution vote.
|
|
@@ -30,7 +29,10 @@ function useSCFetchVote({ id, contribution = null, contributionType, onVote = nu
|
|
|
30
29
|
// HOOKS
|
|
31
30
|
const scContext = (0, SCContextProvider_1.useSCContext)();
|
|
32
31
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
33
|
-
const
|
|
32
|
+
const scVoteContext = (0, SCVoteProvider_1.useSCVote)();
|
|
33
|
+
const reactions = (0, react_1.useMemo)(() => {
|
|
34
|
+
return { default: scVoteContext.reactions.find((reaction) => reaction.id === 1), reactions: scVoteContext.reactions, isLoading: scVoteContext.isLoading };
|
|
35
|
+
}, [scVoteContext.reactions, scVoteContext.isLoading]);
|
|
34
36
|
const fetchObject = (0, react_1.useMemo)(() => () => {
|
|
35
37
|
setIsLoading(true);
|
|
36
38
|
return api_services_1.http
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -56,7 +56,6 @@ import useSCFetchIncubator from './hooks/useSCFetchIncubator';
|
|
|
56
56
|
import useSCMediaClick from './hooks/useSCMediaClick';
|
|
57
57
|
import useSCFetchContributors from './hooks/useSCFetchContributors';
|
|
58
58
|
import useSCFetchFeed from './hooks/useSCFetchFeed';
|
|
59
|
-
import useSCFetchReactions from './hooks/useSCFetchReactions';
|
|
60
59
|
import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSnippets';
|
|
61
60
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
62
61
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
@@ -80,4 +79,4 @@ import * as Locale from './constants/Locale';
|
|
|
80
79
|
/**
|
|
81
80
|
* List all exports
|
|
82
81
|
*/
|
|
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, 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,
|
|
82
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useIsComponentMountedRef = exports.useSCFetchFeed = exports.useSCFetchContributors = exports.useSCMediaClick = exports.useSCFetchIncubator = exports.useSCFetchCategories = exports.useSCFetchCategory = exports.useSCFetchAddressingTagList = exports.useSCFetchTag = exports.useSCFetchCustomAdv = exports.useSCFetchCommentObjects = exports.useSCFetchCommentObject = exports.useSCFetchFeedObject = exports.useSCFetchVote = exports.useSCFetchUserProviders = exports.useSCFetchUser = exports.Locale = exports.UserUtils = exports.SCCache = exports.SCRoutes = exports.Link = exports.useSCAlertMessages = exports.SCAlertMessagesContext = exports.SCAlertMessagesProvider = exports.useSCNotification = exports.SCNotificationContext = exports.SCNotificationProvider = exports.SCNotification = exports.SCFeatures = exports.SCPreferences = exports.SCPreferencesProvider = exports.withSCLocale = exports.useSCLocale = exports.SCLocaleProvider = exports.useSCRouting = exports.SCRoutingProvider = exports.withSCTheme = exports.useSCTheme = exports.SCThemeProvider = exports.useSCPreferences = exports.useSCUser = exports.SCUserProvider = exports.SCContextProvider = exports.useSCContext = exports.SCPreferencesContext = exports.SCLocaleContext = exports.SCRoutingContext = exports.SCThemeContext = exports.SCUserContext = exports.SCContext = void 0;
|
|
4
|
-
exports.useSCUserIsBlocked = exports.useSCFetchUserBlockedBy = exports.useSCFetchBroadcastMessages = exports.useSCFetchPrivateMessageSnippets = exports.
|
|
4
|
+
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
|
|
@@ -102,8 +102,6 @@ const useSCFetchContributors_1 = tslib_1.__importDefault(require("./hooks/useSCF
|
|
|
102
102
|
exports.useSCFetchContributors = useSCFetchContributors_1.default;
|
|
103
103
|
const useSCFetchFeed_1 = tslib_1.__importDefault(require("./hooks/useSCFetchFeed"));
|
|
104
104
|
exports.useSCFetchFeed = useSCFetchFeed_1.default;
|
|
105
|
-
const useSCFetchReactions_1 = tslib_1.__importDefault(require("./hooks/useSCFetchReactions"));
|
|
106
|
-
exports.useSCFetchReactions = useSCFetchReactions_1.default;
|
|
107
105
|
const useSCFetchPrivateMessageSnippets_1 = tslib_1.__importDefault(require("./hooks/useSCFetchPrivateMessageSnippets"));
|
|
108
106
|
exports.useSCFetchPrivateMessageSnippets = useSCFetchPrivateMessageSnippets_1.default;
|
|
109
107
|
const useSCFetchBroadcastMessages_1 = tslib_1.__importDefault(require("./hooks/useSCFetchBroadcastMessages"));
|
|
@@ -24,7 +24,7 @@ export declare const SCVoteContext: React.Context<SCVoteContextType>;
|
|
|
24
24
|
* @param children
|
|
25
25
|
* @return
|
|
26
26
|
* ```jsx
|
|
27
|
-
* <SCVoteContext.Provider value={{reactions}}>{!
|
|
27
|
+
* <SCVoteContext.Provider value={{reactions}}>{!isLoading && children}</SCVoteContext.Provider>
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export default function SCVoteProvider({ children }: {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect,
|
|
1
|
+
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
2
2
|
import { ReactionService } from '@selfcommunity/api-services';
|
|
3
|
-
import { Logger
|
|
3
|
+
import { Logger } from '@selfcommunity/utils';
|
|
4
4
|
import { SCOPE_SC_CORE } from '../../../constants/Errors';
|
|
5
5
|
import { useSCContext } from '../SCContextProvider';
|
|
6
6
|
import { SCFeatureName } from '@selfcommunity/types';
|
|
7
|
-
import { getReactionObjectCacheKey, getReactionsObjectCacheKey } from '../../../constants/Cache';
|
|
8
7
|
import { SCPreferencesContext } from '../SCPreferencesProvider';
|
|
9
8
|
/**
|
|
10
9
|
* Creates Vote Context
|
|
@@ -30,72 +29,56 @@ export const SCVoteContext = createContext({});
|
|
|
30
29
|
* @param children
|
|
31
30
|
* @return
|
|
32
31
|
* ```jsx
|
|
33
|
-
* <SCVoteContext.Provider value={{reactions}}>{!
|
|
32
|
+
* <SCVoteContext.Provider value={{reactions}}>{!isLoading && children}</SCVoteContext.Provider>
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
35
|
export default function SCVoteProvider({ children = null }) {
|
|
37
36
|
const scContext = useSCContext();
|
|
38
37
|
const scPreferencesContext = useContext(SCPreferencesContext);
|
|
39
|
-
const [reactions] = useState(scContext.settings.vote.reactions);
|
|
38
|
+
const [reactions, setReactions] = useState(scContext.settings.vote.reactions);
|
|
40
39
|
const [, setError] = useState();
|
|
41
|
-
const [initialized, setInitialized] = useState(scContext.settings.vote.reactions !== null);
|
|
42
|
-
const [
|
|
43
|
-
/**
|
|
44
|
-
* Hydrate reactions cache
|
|
45
|
-
* @param data
|
|
46
|
-
*/
|
|
47
|
-
const hydrateCache = (data) => {
|
|
48
|
-
if (data && Array.isArray(data) && data.length) {
|
|
49
|
-
LRUCache.set(getReactionsObjectCacheKey(), data.map((r) => {
|
|
50
|
-
const __reactionCacheKey = getReactionObjectCacheKey(r.id);
|
|
51
|
-
LRUCache.set(__reactionCacheKey, r, { noSsr: false });
|
|
52
|
-
return r.id;
|
|
53
|
-
}), { noSsr: false });
|
|
54
|
-
}
|
|
55
|
-
return data;
|
|
56
|
-
};
|
|
40
|
+
const [initialized, setInitialized] = useState((scPreferencesContext.features && !scPreferencesContext.features.includes(SCFeatureName.REACTION)) || scContext.settings.vote.reactions !== null);
|
|
41
|
+
const [isLoading, setIsLoading] = useState(scPreferencesContext.features && scPreferencesContext.features.includes(SCFeatureName.REACTION) && scContext.settings.vote.reactions === null);
|
|
57
42
|
/**
|
|
58
43
|
* Helper to refresh reactions list
|
|
59
44
|
*/
|
|
60
|
-
const refreshReactions =
|
|
61
|
-
|
|
45
|
+
const refreshReactions = useCallback(() => ReactionService.getAllReactionsList().then((data) => {
|
|
46
|
+
setReactions(data);
|
|
47
|
+
return data;
|
|
62
48
|
}), []);
|
|
63
49
|
/**
|
|
64
50
|
* Initialize component
|
|
65
51
|
* Load all reactions if the feature 'reaction' is enabled
|
|
66
52
|
*/
|
|
67
|
-
const _initComponent =
|
|
53
|
+
const _initComponent = useCallback(() => {
|
|
68
54
|
if (!initialized) {
|
|
69
55
|
setInitialized(true);
|
|
70
|
-
|
|
56
|
+
setIsLoading(true);
|
|
71
57
|
refreshReactions()
|
|
72
58
|
.then(() => {
|
|
73
|
-
|
|
59
|
+
setIsLoading(false);
|
|
74
60
|
})
|
|
75
61
|
.catch((_error) => {
|
|
76
62
|
Logger.error(SCOPE_SC_CORE, _error);
|
|
77
63
|
setError(_error);
|
|
78
64
|
});
|
|
79
65
|
}
|
|
80
|
-
|
|
81
|
-
hydrateCache(reactions);
|
|
82
|
-
}
|
|
83
|
-
}, [loading, reactions, initialized]);
|
|
66
|
+
}, [isLoading, initialized]);
|
|
84
67
|
// EFFECTS
|
|
85
68
|
useEffect(() => {
|
|
86
69
|
let _t;
|
|
87
|
-
if (scPreferencesContext.features && scPreferencesContext.features.includes(SCFeatureName.REACTION)) {
|
|
70
|
+
if (scPreferencesContext.features && scPreferencesContext.features.includes(SCFeatureName.REACTION) && !reactions) {
|
|
88
71
|
_t = setTimeout(_initComponent);
|
|
89
72
|
return () => {
|
|
90
73
|
_t && clearTimeout(_t);
|
|
91
74
|
};
|
|
92
75
|
}
|
|
93
|
-
}, [scPreferencesContext.features]);
|
|
76
|
+
}, [scPreferencesContext.features, reactions]);
|
|
94
77
|
/**
|
|
95
78
|
* Nesting all necessary providers
|
|
96
79
|
* All child components will use help contexts to works
|
|
97
80
|
*/
|
|
98
|
-
return React.createElement(SCVoteContext.Provider, { value: { reactions, refreshReactions } }, initialized && children);
|
|
81
|
+
return React.createElement(SCVoteContext.Provider, { value: { reactions, isLoading, refreshReactions } }, initialized && children);
|
|
99
82
|
}
|
|
100
83
|
/**
|
|
101
84
|
* Let's only export the `useSCPreferences` hook instead of the context.
|
|
@@ -36,11 +36,6 @@ export declare const VIRTUALIZED_SCROLL_STATE_CACHE_PREFIX_KEY = "_virtualized_s
|
|
|
36
36
|
export declare const getVirtualizedScrollStateCacheKey: (id: any) => string;
|
|
37
37
|
export declare const FEED_CACHE_SP_KEY = "_feed_spos_";
|
|
38
38
|
export declare const getFeedSPCacheKey: (id: any) => string;
|
|
39
|
-
/** REACTIONS **/
|
|
40
|
-
export declare const REACTIONS_OBJECT_CACHE_PREFIX_KEY = "_res_";
|
|
41
|
-
export declare const getReactionsObjectCacheKey: () => string;
|
|
42
|
-
export declare const REACTION_OBJECT_CACHE_PREFIX_KEY = "_re_";
|
|
43
|
-
export declare const getReactionObjectCacheKey: (id: any) => string;
|
|
44
39
|
/** CUSTOM ADVERTISING **/
|
|
45
40
|
export declare const ADV_OBJECT_CACHE_PREFIX_KEY = "_adv_";
|
|
46
41
|
export declare const getAdvObjectCacheKey: (id: any) => string;
|
|
@@ -40,13 +40,6 @@ export const getVirtualizedScrollStateCacheKey = (id) => `${VIRTUALIZED_SCROLL_S
|
|
|
40
40
|
// Cache feed position
|
|
41
41
|
export const FEED_CACHE_SP_KEY = '_feed_spos_';
|
|
42
42
|
export const getFeedSPCacheKey = (id) => `${FEED_CACHE_SP_KEY}${id}`;
|
|
43
|
-
/** REACTIONS **/
|
|
44
|
-
// Reactions Object
|
|
45
|
-
export const REACTIONS_OBJECT_CACHE_PREFIX_KEY = '_res_';
|
|
46
|
-
export const getReactionsObjectCacheKey = () => `${REACTIONS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
47
|
-
// Reaction Object
|
|
48
|
-
export const REACTION_OBJECT_CACHE_PREFIX_KEY = '_re_';
|
|
49
|
-
export const getReactionObjectCacheKey = (id) => `${REACTION_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
50
43
|
/** CUSTOM ADVERTISING **/
|
|
51
44
|
export const ADV_OBJECT_CACHE_PREFIX_KEY = '_adv_';
|
|
52
45
|
export const getAdvObjectCacheKey = (id) => `${ADV_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -4,9 +4,9 @@ import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
|
|
|
4
4
|
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
5
5
|
import { SCContributionType, } from '@selfcommunity/types';
|
|
6
6
|
import { getCommentObjectCacheKey, getFeedObjectCacheKey } from '../constants/Cache';
|
|
7
|
-
import useSCFetchReactions from './useSCFetchReactions';
|
|
8
7
|
import { useSCContext } from '../components/provider/SCContextProvider';
|
|
9
8
|
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
9
|
+
import { useSCVote } from '../components/provider/SCVoteProvider';
|
|
10
10
|
/**
|
|
11
11
|
:::info
|
|
12
12
|
This custom hook is used to fetch a contribution vote.
|
|
@@ -27,7 +27,10 @@ export default function useSCFetchVote({ id, contribution = null, contributionTy
|
|
|
27
27
|
// HOOKS
|
|
28
28
|
const scContext = useSCContext();
|
|
29
29
|
const scUserContext = useSCUser();
|
|
30
|
-
const
|
|
30
|
+
const scVoteContext = useSCVote();
|
|
31
|
+
const reactions = useMemo(() => {
|
|
32
|
+
return { default: scVoteContext.reactions.find((reaction) => reaction.id === 1), reactions: scVoteContext.reactions, isLoading: scVoteContext.isLoading };
|
|
33
|
+
}, [scVoteContext.reactions, scVoteContext.isLoading]);
|
|
31
34
|
const fetchObject = useMemo(() => () => {
|
|
32
35
|
setIsLoading(true);
|
|
33
36
|
return http
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -56,7 +56,6 @@ import useSCFetchIncubator from './hooks/useSCFetchIncubator';
|
|
|
56
56
|
import useSCMediaClick from './hooks/useSCMediaClick';
|
|
57
57
|
import useSCFetchContributors from './hooks/useSCFetchContributors';
|
|
58
58
|
import useSCFetchFeed from './hooks/useSCFetchFeed';
|
|
59
|
-
import useSCFetchReactions from './hooks/useSCFetchReactions';
|
|
60
59
|
import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSnippets';
|
|
61
60
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
62
61
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
@@ -80,4 +79,4 @@ import * as Locale from './constants/Locale';
|
|
|
80
79
|
/**
|
|
81
80
|
* List all exports
|
|
82
81
|
*/
|
|
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, 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,
|
|
82
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, };
|
package/lib/esm/index.js
CHANGED
|
@@ -52,7 +52,6 @@ import useSCFetchIncubator from './hooks/useSCFetchIncubator';
|
|
|
52
52
|
import useSCMediaClick from './hooks/useSCMediaClick';
|
|
53
53
|
import useSCFetchContributors from './hooks/useSCFetchContributors';
|
|
54
54
|
import useSCFetchFeed from './hooks/useSCFetchFeed';
|
|
55
|
-
import useSCFetchReactions from './hooks/useSCFetchReactions';
|
|
56
55
|
import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSnippets';
|
|
57
56
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
58
57
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
@@ -76,4 +75,4 @@ import * as Locale from './constants/Locale';
|
|
|
76
75
|
/**
|
|
77
76
|
* List all exports
|
|
78
77
|
*/
|
|
79
|
-
export { 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,
|
|
78
|
+
export { 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, };
|