@selfcommunity/react-core 0.1.2-alpha.0
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/LICENSE.md +21 -0
- package/README.md +13 -0
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js +67 -0
- package/lib/cjs/components/provider/SCContextProvider/index.js +117 -0
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +158 -0
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +73 -0
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +93 -0
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +146 -0
- package/lib/cjs/components/provider/SCThemeProvider/index.js +123 -0
- package/lib/cjs/components/provider/SCUserProvider/index.js +310 -0
- package/lib/cjs/components/router/index.js +91 -0
- package/lib/cjs/constants/Actions.js +6 -0
- package/lib/cjs/constants/ContextProviders.js +29 -0
- package/lib/cjs/constants/Device.js +11 -0
- package/lib/cjs/constants/Errors.js +10 -0
- package/lib/cjs/constants/Features.js +84 -0
- package/lib/cjs/constants/Locale.js +19 -0
- package/lib/cjs/constants/Notification.js +67 -0
- package/lib/cjs/constants/Notifications.js +27 -0
- package/lib/cjs/constants/Preferences.js +344 -0
- package/lib/cjs/constants/Routes.js +68 -0
- package/lib/cjs/constants/Session.js +22 -0
- package/lib/cjs/constants/Theme.js +6 -0
- package/lib/cjs/constants/WebSocket.js +10 -0
- package/lib/cjs/hooks/useSCAuth.js +340 -0
- package/lib/cjs/hooks/useSCCachingManager.js +58 -0
- package/lib/cjs/hooks/useSCConnectionsManager.js +285 -0
- package/lib/cjs/hooks/useSCFetchCategories.js +71 -0
- package/lib/cjs/hooks/useSCFetchCategory.js +68 -0
- package/lib/cjs/hooks/useSCFetchCommentObject.js +68 -0
- package/lib/cjs/hooks/useSCFetchCommentObjects.js +296 -0
- package/lib/cjs/hooks/useSCFetchCustomAdv.js +84 -0
- package/lib/cjs/hooks/useSCFetchFeedObject.js +79 -0
- package/lib/cjs/hooks/useSCFetchIncubator.js +68 -0
- package/lib/cjs/hooks/useSCFetchTag.js +68 -0
- package/lib/cjs/hooks/useSCFetchUser.js +68 -0
- package/lib/cjs/hooks/useSCFollowedCategoriesManager.js +162 -0
- package/lib/cjs/hooks/useSCFollowersManager.js +232 -0
- package/lib/cjs/hooks/useSCMediaClick.js +27 -0
- package/lib/cjs/hooks/useSCSubscribedIncubatorsManager.js +165 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +286 -0
- package/lib/cjs/hooks/useSCWebSocket.js +120 -0
- package/lib/cjs/index.js +169 -0
- package/lib/cjs/scss/styles.scss +1 -0
- package/lib/cjs/themes/theme.js +165 -0
- package/lib/cjs/types/context.js +3 -0
- package/lib/cjs/types/index.js +22 -0
- package/lib/cjs/utils/errors.js +196 -0
- package/lib/cjs/utils/locale.js +56 -0
- package/lib/cjs/utils/logger.js +32 -0
- package/lib/cjs/utils/object.js +44 -0
- package/lib/cjs/utils/session.js +17 -0
- package/lib/cjs/utils/string.js +57 -0
- package/lib/cjs/utils/url.js +70 -0
- package/lib/cjs/utils/user.js +83 -0
- package/lib/cjs/utils/validator.js +771 -0
- package/lib/cjs/utils/webPushMessaging.js +110 -0
- package/lib/cjs/utils/websocket.js +307 -0
- package/lib/esm/api-services/src/client/index.d.ts +115 -0
- package/lib/esm/api-services/src/client/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts +10 -0
- package/lib/esm/api-services/src/constants/Endpoints.d.ts.map +1 -0
- package/lib/esm/api-services/src/index.d.ts +24 -0
- package/lib/esm/api-services/src/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/category/index.d.ts +13 -0
- package/lib/esm/api-services/src/services/category/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts +10 -0
- package/lib/esm/api-services/src/services/feature/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/preference/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/services/user/index.d.ts +16 -0
- package/lib/esm/api-services/src/services/user/index.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/http.d.ts +6 -0
- package/lib/esm/api-services/src/utils/http.d.ts.map +1 -0
- package/lib/esm/api-services/src/utils/token.d.ts +16 -0
- package/lib/esm/api-services/src/utils/token.d.ts.map +1 -0
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +67 -0
- package/lib/esm/components/provider/SCContextProvider/index.js +117 -0
- package/lib/esm/components/provider/SCLocaleProvider/index.js +158 -0
- package/lib/esm/components/provider/SCNotificationProvider/index.js +73 -0
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +93 -0
- package/lib/esm/components/provider/SCRoutingProvider/index.js +146 -0
- package/lib/esm/components/provider/SCThemeProvider/index.js +123 -0
- package/lib/esm/components/provider/SCUserProvider/index.js +310 -0
- package/lib/esm/components/router/index.js +91 -0
- package/lib/esm/constants/Actions.js +6 -0
- package/lib/esm/constants/ContextProviders.js +29 -0
- package/lib/esm/constants/Device.js +11 -0
- package/lib/esm/constants/Errors.js +10 -0
- package/lib/esm/constants/Features.js +84 -0
- package/lib/esm/constants/Locale.js +19 -0
- package/lib/esm/constants/Notification.js +67 -0
- package/lib/esm/constants/Notifications.js +27 -0
- package/lib/esm/constants/Preferences.js +344 -0
- package/lib/esm/constants/Routes.js +68 -0
- package/lib/esm/constants/Session.js +22 -0
- package/lib/esm/constants/Theme.js +6 -0
- package/lib/esm/constants/WebSocket.js +10 -0
- package/lib/esm/hooks/useSCAuth.js +340 -0
- package/lib/esm/hooks/useSCCachingManager.js +58 -0
- package/lib/esm/hooks/useSCConnectionsManager.js +285 -0
- package/lib/esm/hooks/useSCFetchCategories.js +71 -0
- package/lib/esm/hooks/useSCFetchCategory.js +68 -0
- package/lib/esm/hooks/useSCFetchCommentObject.js +68 -0
- package/lib/esm/hooks/useSCFetchCommentObjects.js +296 -0
- package/lib/esm/hooks/useSCFetchCustomAdv.js +84 -0
- package/lib/esm/hooks/useSCFetchFeedObject.js +79 -0
- package/lib/esm/hooks/useSCFetchIncubator.js +68 -0
- package/lib/esm/hooks/useSCFetchTag.js +68 -0
- package/lib/esm/hooks/useSCFetchUser.js +68 -0
- package/lib/esm/hooks/useSCFollowedCategoriesManager.js +162 -0
- package/lib/esm/hooks/useSCFollowersManager.js +232 -0
- package/lib/esm/hooks/useSCMediaClick.js +27 -0
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.js +165 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +286 -0
- package/lib/esm/hooks/useSCWebSocket.js +120 -0
- package/lib/esm/index.js +169 -0
- package/lib/esm/react-core/src/components/provider/SCAlertMessagesProvider/index.d.ts +37 -0
- package/lib/esm/react-core/src/components/provider/SCAlertMessagesProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCContextProvider/index.d.ts +35 -0
- package/lib/esm/react-core/src/components/provider/SCContextProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCLocaleProvider/index.d.ts +42 -0
- package/lib/esm/react-core/src/components/provider/SCLocaleProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCNotificationProvider/index.d.ts +37 -0
- package/lib/esm/react-core/src/components/provider/SCNotificationProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCPreferencesProvider/index.d.ts +38 -0
- package/lib/esm/react-core/src/components/provider/SCPreferencesProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCRoutingProvider/index.d.ts +39 -0
- package/lib/esm/react-core/src/components/provider/SCRoutingProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCThemeProvider/index.d.ts +49 -0
- package/lib/esm/react-core/src/components/provider/SCThemeProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/provider/SCUserProvider/index.d.ts +38 -0
- package/lib/esm/react-core/src/components/provider/SCUserProvider/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/components/router/index.d.ts +34 -0
- package/lib/esm/react-core/src/components/router/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Actions.d.ts +2 -0
- package/lib/esm/react-core/src/constants/Actions.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/ContextProviders.d.ts +6 -0
- package/lib/esm/react-core/src/constants/ContextProviders.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Device.d.ts +6 -0
- package/lib/esm/react-core/src/constants/Device.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Errors.d.ts +5 -0
- package/lib/esm/react-core/src/constants/Errors.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Features.d.ts +41 -0
- package/lib/esm/react-core/src/constants/Features.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Locale.d.ts +8 -0
- package/lib/esm/react-core/src/constants/Locale.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Notification.d.ts +55 -0
- package/lib/esm/react-core/src/constants/Notification.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Notifications.d.ts +11 -0
- package/lib/esm/react-core/src/constants/Notifications.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Routes.d.ts +29 -0
- package/lib/esm/react-core/src/constants/Routes.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Session.d.ts +10 -0
- package/lib/esm/react-core/src/constants/Session.d.ts.map +1 -0
- package/lib/esm/react-core/src/constants/Theme.d.ts +2 -0
- package/lib/esm/react-core/src/constants/Theme.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCAuth.d.ts +56 -0
- package/lib/esm/react-core/src/hooks/useSCAuth.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCCachingManager.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCCachingManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCConnectionsManager.d.ts +40 -0
- package/lib/esm/react-core/src/hooks/useSCConnectionsManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategories.d.ts +17 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategories.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategory.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCategory.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObject.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObject.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts +54 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCommentObjects.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCustomAdv.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchCustomAdv.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchFeedObject.d.ts +21 -0
- package/lib/esm/react-core/src/hooks/useSCFetchFeedObject.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchIncubator.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchIncubator.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchTag.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchTag.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFetchUser.d.ts +19 -0
- package/lib/esm/react-core/src/hooks/useSCFetchUser.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFollowedCategoriesManager.d.ts +37 -0
- package/lib/esm/react-core/src/hooks/useSCFollowedCategoriesManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCFollowersManager.d.ts +37 -0
- package/lib/esm/react-core/src/hooks/useSCFollowersManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCMediaClick.d.ts +4 -0
- package/lib/esm/react-core/src/hooks/useSCMediaClick.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCSubscribedIncubatorsManager.d.ts +27 -0
- package/lib/esm/react-core/src/hooks/useSCSubscribedIncubatorsManager.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCWebPushMessaging.d.ts +9 -0
- package/lib/esm/react-core/src/hooks/useSCWebPushMessaging.d.ts.map +1 -0
- package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts +12 -0
- package/lib/esm/react-core/src/hooks/useSCWebSocket.d.ts.map +1 -0
- package/lib/esm/react-core/src/index.d.ts +77 -0
- package/lib/esm/react-core/src/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/types/context.d.ts +428 -0
- package/lib/esm/react-core/src/types/context.d.ts.map +1 -0
- package/lib/esm/react-core/src/types/index.d.ts +3 -0
- package/lib/esm/react-core/src/types/index.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/errors.d.ts +98 -0
- package/lib/esm/react-core/src/utils/errors.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/locale.d.ts +10 -0
- package/lib/esm/react-core/src/utils/locale.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/logger.d.ts +11 -0
- package/lib/esm/react-core/src/utils/logger.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/object.d.ts +13 -0
- package/lib/esm/react-core/src/utils/object.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/session.d.ts +6 -0
- package/lib/esm/react-core/src/utils/session.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/string.d.ts +21 -0
- package/lib/esm/react-core/src/utils/string.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/url.d.ts +22 -0
- package/lib/esm/react-core/src/utils/url.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/user.d.ts +41 -0
- package/lib/esm/react-core/src/utils/user.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/validator.d.ts +239 -0
- package/lib/esm/react-core/src/utils/validator.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/webPushMessaging.d.ts +14 -0
- package/lib/esm/react-core/src/utils/webPushMessaging.d.ts.map +1 -0
- package/lib/esm/react-core/src/utils/websocket.d.ts +177 -0
- package/lib/esm/react-core/src/utils/websocket.d.ts.map +1 -0
- package/lib/esm/react-i18n/src/index.d.ts +815 -0
- package/lib/esm/react-i18n/src/index.d.ts.map +1 -0
- package/lib/esm/scss/styles.scss +1 -0
- package/lib/esm/themes/theme.js +165 -0
- package/lib/esm/types/context.js +3 -0
- package/lib/esm/types/index.js +22 -0
- package/lib/esm/types/src/index.d.ts +9 -0
- package/lib/esm/types/src/index.d.ts.map +1 -0
- package/lib/esm/types/src/types/auth.d.ts +26 -0
- package/lib/esm/types/src/types/auth.d.ts.map +1 -0
- package/lib/esm/types/src/types/broadcastMessage.d.ts +73 -0
- package/lib/esm/types/src/types/broadcastMessage.d.ts.map +1 -0
- package/lib/esm/types/src/types/category.d.ts +100 -0
- package/lib/esm/types/src/types/category.d.ts.map +1 -0
- package/lib/esm/types/src/types/comment.d.ts +97 -0
- package/lib/esm/types/src/types/comment.d.ts.map +1 -0
- package/lib/esm/types/src/types/customAdv.d.ts +53 -0
- package/lib/esm/types/src/types/customAdv.d.ts.map +1 -0
- package/lib/esm/types/src/types/customNotification.d.ts +28 -0
- package/lib/esm/types/src/types/customNotification.d.ts.map +1 -0
- package/lib/esm/types/src/types/embed.d.ts +33 -0
- package/lib/esm/types/src/types/embed.d.ts.map +1 -0
- package/lib/esm/types/src/types/feed.d.ts +208 -0
- package/lib/esm/types/src/types/feed.d.ts.map +1 -0
- package/lib/esm/types/src/types/incubator.d.ts +53 -0
- package/lib/esm/types/src/types/incubator.d.ts.map +1 -0
- package/lib/esm/types/src/types/index.d.ts +22 -0
- package/lib/esm/types/src/types/index.d.ts.map +1 -0
- package/lib/esm/types/src/types/location.d.ts +61 -0
- package/lib/esm/types/src/types/location.d.ts.map +1 -0
- package/lib/esm/types/src/types/media.d.ts +52 -0
- package/lib/esm/types/src/types/media.d.ts.map +1 -0
- package/lib/esm/types/src/types/notification.d.ts +416 -0
- package/lib/esm/types/src/types/notification.d.ts.map +1 -0
- package/lib/esm/types/src/types/poll.d.ts +77 -0
- package/lib/esm/types/src/types/poll.d.ts.map +1 -0
- package/lib/esm/types/src/types/privateMessage.d.ts +109 -0
- package/lib/esm/types/src/types/privateMessage.d.ts.map +1 -0
- package/lib/esm/types/src/types/prize.d.ts +48 -0
- package/lib/esm/types/src/types/prize.d.ts.map +1 -0
- package/lib/esm/types/src/types/tag.d.ts +47 -0
- package/lib/esm/types/src/types/tag.d.ts.map +1 -0
- package/lib/esm/types/src/types/user.d.ts +227 -0
- package/lib/esm/types/src/types/user.d.ts.map +1 -0
- package/lib/esm/utils/errors.js +196 -0
- package/lib/esm/utils/locale.js +56 -0
- package/lib/esm/utils/logger.js +32 -0
- package/lib/esm/utils/object.js +44 -0
- package/lib/esm/utils/session.js +17 -0
- package/lib/esm/utils/src/index.d.ts +7 -0
- package/lib/esm/utils/src/index.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/string.d.ts +21 -0
- package/lib/esm/utils/src/utils/string.d.ts.map +1 -0
- package/lib/esm/utils/src/utils/url.d.ts +22 -0
- package/lib/esm/utils/src/utils/url.d.ts.map +1 -0
- package/lib/esm/utils/string.js +57 -0
- package/lib/esm/utils/url.js +70 -0
- package/lib/esm/utils/user.js +83 -0
- package/lib/esm/utils/validator.js +771 -0
- package/lib/esm/utils/webPushMessaging.js +110 -0
- package/lib/esm/utils/websocket.js +307 -0
- package/lib/umd/react-core.js +2 -0
- package/lib/umd/react-core.js.LICENSE.txt +1 -0
- package/package.json +128 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.defaultRoutes = exports.USER_PROFILE_SETTINGS_ROUTE_NAME = exports.USER_PROFILE_ROUTE_NAME = exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = exports.USER_NOTIFICATIONS_ROUTE_NAME = exports.STATUS_ROUTE_NAME = exports.SIGNUP_ROUTE_NAME = exports.SIGNIN_ROUTE_NAME = exports.ROUTER_OPTION = exports.RECOVER_ROUTE_NAME = exports.POST_ROUTE_NAME = exports.PORTAL_OPTION = exports.LOYALTY_ROUTE_NAME = exports.INCUBATOR_ROUTE_NAME = exports.DISCUSSION_ROUTE_NAME = exports.CUSTOM_PAGES_ROUTE_NAME = exports.COMMENT_ROUTE_NAME = exports.CATEGORY_ROUTE_NAME = exports.CATEGORIES_LIST_ROUTE_NAME = void 0;
|
|
5
|
+
const PORTAL_OPTION = 'portal';
|
|
6
|
+
exports.PORTAL_OPTION = PORTAL_OPTION;
|
|
7
|
+
const ROUTER_OPTION = 'router';
|
|
8
|
+
/**
|
|
9
|
+
* Routes name
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
exports.ROUTER_OPTION = ROUTER_OPTION;
|
|
13
|
+
const POST_ROUTE_NAME = 'post';
|
|
14
|
+
exports.POST_ROUTE_NAME = POST_ROUTE_NAME;
|
|
15
|
+
const DISCUSSION_ROUTE_NAME = 'discussion';
|
|
16
|
+
exports.DISCUSSION_ROUTE_NAME = DISCUSSION_ROUTE_NAME;
|
|
17
|
+
const STATUS_ROUTE_NAME = 'status';
|
|
18
|
+
exports.STATUS_ROUTE_NAME = STATUS_ROUTE_NAME;
|
|
19
|
+
const COMMENT_ROUTE_NAME = 'comment';
|
|
20
|
+
exports.COMMENT_ROUTE_NAME = COMMENT_ROUTE_NAME;
|
|
21
|
+
const CATEGORY_ROUTE_NAME = 'category';
|
|
22
|
+
exports.CATEGORY_ROUTE_NAME = CATEGORY_ROUTE_NAME;
|
|
23
|
+
const CATEGORIES_LIST_ROUTE_NAME = 'categories';
|
|
24
|
+
exports.CATEGORIES_LIST_ROUTE_NAME = CATEGORIES_LIST_ROUTE_NAME;
|
|
25
|
+
const USER_PROFILE_ROUTE_NAME = 'user_profile';
|
|
26
|
+
exports.USER_PROFILE_ROUTE_NAME = USER_PROFILE_ROUTE_NAME;
|
|
27
|
+
const USER_PROFILE_SETTINGS_ROUTE_NAME = 'user_profile_settings';
|
|
28
|
+
exports.USER_PROFILE_SETTINGS_ROUTE_NAME = USER_PROFILE_SETTINGS_ROUTE_NAME;
|
|
29
|
+
const USER_NOTIFICATIONS_ROUTE_NAME = 'user_notifications';
|
|
30
|
+
exports.USER_NOTIFICATIONS_ROUTE_NAME = USER_NOTIFICATIONS_ROUTE_NAME;
|
|
31
|
+
const USER_PRIVATE_MESSAGES_ROUTE_NAME = 'user_messages';
|
|
32
|
+
exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = USER_PRIVATE_MESSAGES_ROUTE_NAME;
|
|
33
|
+
const LOYALTY_ROUTE_NAME = 'loyalty';
|
|
34
|
+
exports.LOYALTY_ROUTE_NAME = LOYALTY_ROUTE_NAME;
|
|
35
|
+
const INCUBATOR_ROUTE_NAME = 'incubator';
|
|
36
|
+
exports.INCUBATOR_ROUTE_NAME = INCUBATOR_ROUTE_NAME;
|
|
37
|
+
const SIGNIN_ROUTE_NAME = 'signin';
|
|
38
|
+
exports.SIGNIN_ROUTE_NAME = SIGNIN_ROUTE_NAME;
|
|
39
|
+
const SIGNUP_ROUTE_NAME = 'signup';
|
|
40
|
+
exports.SIGNUP_ROUTE_NAME = SIGNUP_ROUTE_NAME;
|
|
41
|
+
const RECOVER_ROUTE_NAME = 'recover';
|
|
42
|
+
exports.RECOVER_ROUTE_NAME = RECOVER_ROUTE_NAME;
|
|
43
|
+
const CUSTOM_PAGES_ROUTE_NAME = 'custom_pages';
|
|
44
|
+
/**
|
|
45
|
+
* Default Routes
|
|
46
|
+
* @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}}
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
exports.CUSTOM_PAGES_ROUTE_NAME = CUSTOM_PAGES_ROUTE_NAME;
|
|
50
|
+
const defaultRoutes = {
|
|
51
|
+
[POST_ROUTE_NAME]: '/post/:id/',
|
|
52
|
+
[DISCUSSION_ROUTE_NAME]: '/discussion/:id/',
|
|
53
|
+
[STATUS_ROUTE_NAME]: '/status/:id/',
|
|
54
|
+
[COMMENT_ROUTE_NAME]: '/:contribution_type/:contribution_id/comment/:id/',
|
|
55
|
+
[CATEGORY_ROUTE_NAME]: '/category/:id/',
|
|
56
|
+
[CATEGORIES_LIST_ROUTE_NAME]: '/categories/',
|
|
57
|
+
[USER_PROFILE_ROUTE_NAME]: '/user/:id/',
|
|
58
|
+
[USER_PROFILE_SETTINGS_ROUTE_NAME]: '/user/:id/edit/',
|
|
59
|
+
[USER_NOTIFICATIONS_ROUTE_NAME]: '/notification/',
|
|
60
|
+
[USER_PRIVATE_MESSAGES_ROUTE_NAME]: '/messages/:id/',
|
|
61
|
+
[LOYALTY_ROUTE_NAME]: '/loyalty/',
|
|
62
|
+
[INCUBATOR_ROUTE_NAME]: '/incubator/:id/',
|
|
63
|
+
[SIGNIN_ROUTE_NAME]: '/signin/',
|
|
64
|
+
[SIGNUP_ROUTE_NAME]: '/signup/',
|
|
65
|
+
[RECOVER_ROUTE_NAME]: '/recover/',
|
|
66
|
+
[CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/'
|
|
67
|
+
};
|
|
68
|
+
exports.defaultRoutes = defaultRoutes;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.sessionTypes = exports.SESSION_TYPE_OPTION = exports.SESSION_OPTION = exports.SESSION_HANDLE_REFRESH_TOKEN_OPTION = exports.SESSION_CLIENT_ID_OPTION = exports.SESSION_AUTH_TOKEN_OPTION = exports.OAUTH_SESSION = exports.JWT_SESSION = exports.COOKIE_SESSION = void 0;
|
|
5
|
+
const SESSION_OPTION = 'session';
|
|
6
|
+
exports.SESSION_OPTION = SESSION_OPTION;
|
|
7
|
+
const SESSION_TYPE_OPTION = 'type';
|
|
8
|
+
exports.SESSION_TYPE_OPTION = SESSION_TYPE_OPTION;
|
|
9
|
+
const SESSION_CLIENT_ID_OPTION = 'clientId';
|
|
10
|
+
exports.SESSION_CLIENT_ID_OPTION = SESSION_CLIENT_ID_OPTION;
|
|
11
|
+
const SESSION_AUTH_TOKEN_OPTION = 'authToken';
|
|
12
|
+
exports.SESSION_AUTH_TOKEN_OPTION = SESSION_AUTH_TOKEN_OPTION;
|
|
13
|
+
const SESSION_HANDLE_REFRESH_TOKEN_OPTION = 'handleRefreshToken';
|
|
14
|
+
exports.SESSION_HANDLE_REFRESH_TOKEN_OPTION = SESSION_HANDLE_REFRESH_TOKEN_OPTION;
|
|
15
|
+
const COOKIE_SESSION = 'Cookie';
|
|
16
|
+
exports.COOKIE_SESSION = COOKIE_SESSION;
|
|
17
|
+
const JWT_SESSION = 'JWT';
|
|
18
|
+
exports.JWT_SESSION = JWT_SESSION;
|
|
19
|
+
const OAUTH_SESSION = 'OAuth';
|
|
20
|
+
exports.OAUTH_SESSION = OAUTH_SESSION;
|
|
21
|
+
const sessionTypes = [JWT_SESSION, OAUTH_SESSION, COOKIE_SESSION];
|
|
22
|
+
exports.sessionTypes = sessionTypes;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.WS_PROTOCOL_PREFIX = exports.WS_HEARTBEAT_MESSAGE = exports.WS_FACILITY_NOTIFY = void 0;
|
|
5
|
+
const WS_PROTOCOL_PREFIX = '__';
|
|
6
|
+
exports.WS_PROTOCOL_PREFIX = WS_PROTOCOL_PREFIX;
|
|
7
|
+
const WS_FACILITY_NOTIFY = 'notify';
|
|
8
|
+
exports.WS_FACILITY_NOTIFY = WS_FACILITY_NOTIFY;
|
|
9
|
+
const WS_HEARTBEAT_MESSAGE = '--1a61c1de89b75ddfbb684b8d224ee3ae--';
|
|
10
|
+
exports.WS_HEARTBEAT_MESSAGE = WS_HEARTBEAT_MESSAGE;
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useAuth;
|
|
5
|
+
exports.userActionTypes = void 0;
|
|
6
|
+
|
|
7
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
8
|
+
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
|
|
11
|
+
var Session = _interopRequireWildcard(require("../constants/Session"));
|
|
12
|
+
|
|
13
|
+
var _useDeepCompareEffect = _interopRequireDefault(require("use-deep-compare-effect"));
|
|
14
|
+
|
|
15
|
+
var _logger = require("../utils/logger");
|
|
16
|
+
|
|
17
|
+
var _Errors = require("../constants/Errors");
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
+
|
|
23
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @hidden
|
|
27
|
+
* We have complex state logic that involves multiple sub-values,
|
|
28
|
+
* so useReducer is preferable to useState.
|
|
29
|
+
* Define all possible auth action types label
|
|
30
|
+
* Use this to export actions and dispatch an action
|
|
31
|
+
*/
|
|
32
|
+
const userActionTypes = {
|
|
33
|
+
LOGIN_LOADING: '_login_loading',
|
|
34
|
+
LOGIN_SUCCESS: '_login_success',
|
|
35
|
+
LOGIN_FAILURE: '_login_failure',
|
|
36
|
+
LOGOUT: '_logout',
|
|
37
|
+
REFRESH_TOKEN_SUCCESS: '_refresh_token_success',
|
|
38
|
+
REFRESH_TOKEN_FAILURE: '_invalid_token_failure',
|
|
39
|
+
REFRESH_SESSION: '_refresh_token',
|
|
40
|
+
UPDATE_USER: '_change_user'
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* userReducer:
|
|
44
|
+
* - manage the state of authentication
|
|
45
|
+
* - update the state base on action type
|
|
46
|
+
* @param state
|
|
47
|
+
* @param action
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
exports.userActionTypes = userActionTypes;
|
|
51
|
+
|
|
52
|
+
function userReducer(state, action) {
|
|
53
|
+
switch (action.type) {
|
|
54
|
+
case userActionTypes.LOGIN_LOADING:
|
|
55
|
+
return {
|
|
56
|
+
user: null,
|
|
57
|
+
session: Object.assign({}, state.session),
|
|
58
|
+
error: null,
|
|
59
|
+
loading: true
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
case userActionTypes.LOGIN_SUCCESS:
|
|
63
|
+
return {
|
|
64
|
+
user: action.payload.user,
|
|
65
|
+
error: null,
|
|
66
|
+
session: Object.assign({}, state.session),
|
|
67
|
+
loading: false
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
case userActionTypes.LOGIN_FAILURE:
|
|
71
|
+
return {
|
|
72
|
+
user: null,
|
|
73
|
+
session: Object.assign({}, state.session),
|
|
74
|
+
error: action.payload.error,
|
|
75
|
+
loading: false
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
case userActionTypes.REFRESH_TOKEN_SUCCESS:
|
|
79
|
+
const newAuthToken = Object.assign({}, state.session.authToken, Object.assign({}, state.session.authToken, {
|
|
80
|
+
accessToken: action.payload.token.accessToken
|
|
81
|
+
}, action.payload.token.refreshToken ? {
|
|
82
|
+
refreshToken: action.payload.token.refreshToken
|
|
83
|
+
} : {}, action.payload.token.expiresIn ? {
|
|
84
|
+
expiresIn: action.payload.token.expiresIn
|
|
85
|
+
} : {}));
|
|
86
|
+
const newSession = Object.assign({}, state.session, {
|
|
87
|
+
authToken: newAuthToken
|
|
88
|
+
}); // Update current client config
|
|
89
|
+
|
|
90
|
+
_apiServices.http.setAuthorizeToken(newAuthToken.accessToken);
|
|
91
|
+
|
|
92
|
+
return Object.assign({}, state, {
|
|
93
|
+
session: newSession,
|
|
94
|
+
error: null,
|
|
95
|
+
loading: false
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
case userActionTypes.REFRESH_TOKEN_FAILURE:
|
|
99
|
+
return {
|
|
100
|
+
user: null,
|
|
101
|
+
session: Object.assign({}, state.session),
|
|
102
|
+
loading: null,
|
|
103
|
+
error: action.payload.error
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
case userActionTypes.LOGOUT:
|
|
107
|
+
return {
|
|
108
|
+
user: null,
|
|
109
|
+
session: null,
|
|
110
|
+
error: null,
|
|
111
|
+
loading: null
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
case userActionTypes.UPDATE_USER:
|
|
115
|
+
return Object.assign({}, state, {
|
|
116
|
+
user: Object.assign({}, state.user, action.payload)
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
case userActionTypes.REFRESH_SESSION:
|
|
120
|
+
return Object.assign({}, state, action.payload.conf);
|
|
121
|
+
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unhandled type: ${action.type}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Define initial context auth session
|
|
128
|
+
* @param session
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
function stateInitializer(session) {
|
|
133
|
+
let _session = Object.assign({}, session);
|
|
134
|
+
|
|
135
|
+
let _isLoading = false;
|
|
136
|
+
/**
|
|
137
|
+
* Set http authorization if session type is OAuth or JWT
|
|
138
|
+
* Configure http object (Authorization, etc...)
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
if ([Session.OAUTH_SESSION, Session.JWT_SESSION].includes(_session.type) && _session.authToken && _session.authToken.accessToken) {
|
|
142
|
+
_apiServices.http.setAuthorizeToken(_session.authToken.accessToken);
|
|
143
|
+
|
|
144
|
+
_isLoading = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_apiServices.http.setSupportWithCredentials(_session.type === Session.COOKIE_SESSION);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
user: null,
|
|
151
|
+
session: _session,
|
|
152
|
+
error: null,
|
|
153
|
+
loading: _isLoading,
|
|
154
|
+
isSessionRefreshing: false,
|
|
155
|
+
refreshSession: false
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
:::info
|
|
160
|
+
This component is used to navigate through the application.
|
|
161
|
+
:::
|
|
162
|
+
|
|
163
|
+
#### Usage
|
|
164
|
+
|
|
165
|
+
In order to use router you need to import this components first:
|
|
166
|
+
|
|
167
|
+
```jsx
|
|
168
|
+
import {SCRoutingContextType, useSCRouting, Link, SCRoutes} from '@selfcommunity/react-core';
|
|
169
|
+
````
|
|
170
|
+
|
|
171
|
+
:::tipUsage Example:
|
|
172
|
+
|
|
173
|
+
```jsx
|
|
174
|
+
const scRoutingContext: SCRoutingContextType = useSCRouting();
|
|
175
|
+
<Button component={Link} to={scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, {id: user.id})>Go to profile</Button>
|
|
176
|
+
````
|
|
177
|
+
or
|
|
178
|
+
|
|
179
|
+
```jsx
|
|
180
|
+
const scRoutingContext: SCRoutingContextType = useSCRouting();
|
|
181
|
+
<Link to={scRoutingContext.url('profile', {id: user.id})}>Go to profile</Link>
|
|
182
|
+
````
|
|
183
|
+
:::
|
|
184
|
+
* @param initialSession
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
function useAuth(initialSession) {
|
|
189
|
+
const [state, dispatch] = (0, _react.useReducer)(userReducer, {}, () => stateInitializer(initialSession));
|
|
190
|
+
let authInterceptor = (0, _react.useRef)(null);
|
|
191
|
+
let isSessionRefreshing = (0, _react.useRef)(false);
|
|
192
|
+
let failedQueue = (0, _react.useRef)([]); // CONST
|
|
193
|
+
|
|
194
|
+
const userId = state.user ? state.user.id : null;
|
|
195
|
+
const accessToken = state.session.authToken && state.session.authToken.accessToken ? state.session.authToken.accessToken : null;
|
|
196
|
+
/**
|
|
197
|
+
* Refresh session
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
const refreshSession = (0, _react.useMemo)(() => () => {
|
|
201
|
+
const session = state.session;
|
|
202
|
+
|
|
203
|
+
if (!isSessionRefreshing.current && session.handleRefreshToken) {
|
|
204
|
+
isSessionRefreshing.current = true;
|
|
205
|
+
return session.handleRefreshToken(state.session).then(res => {
|
|
206
|
+
isSessionRefreshing.current = false;
|
|
207
|
+
dispatch({
|
|
208
|
+
type: userActionTypes.REFRESH_TOKEN_SUCCESS,
|
|
209
|
+
payload: {
|
|
210
|
+
token: res
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return Promise.resolve(res);
|
|
214
|
+
}).catch(error => {
|
|
215
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh user session.');
|
|
216
|
+
|
|
217
|
+
if (error.response && error.response.data) {
|
|
218
|
+
dispatch({
|
|
219
|
+
type: userActionTypes.REFRESH_TOKEN_FAILURE,
|
|
220
|
+
payload: {
|
|
221
|
+
error: error.response.toString()
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return Promise.reject(error);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return Promise.reject(new Error('Unable to refresh session. Unauthenticated user.'));
|
|
231
|
+
}, [accessToken]);
|
|
232
|
+
/**
|
|
233
|
+
* Manages multiple request during refresh session
|
|
234
|
+
* Save concurrent requests and retry them again
|
|
235
|
+
* at the end of refreshing session
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
const processQueue = (0, _react.useMemo)(() => (error, token = null) => {
|
|
239
|
+
failedQueue.current.forEach(prom => {
|
|
240
|
+
if (error) {
|
|
241
|
+
prom.reject(error);
|
|
242
|
+
} else {
|
|
243
|
+
prom.resolve(token);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
failedQueue.current = [];
|
|
247
|
+
}, [failedQueue.current]);
|
|
248
|
+
/**
|
|
249
|
+
* Add/remove an http request interceptor.
|
|
250
|
+
* When the component unmounted the interceptor will be detached
|
|
251
|
+
* The interceptor check if the token is expiring
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
(0, _react.useEffect)(() => {
|
|
255
|
+
if (userId !== null) {
|
|
256
|
+
authInterceptor.current = _apiServices.http.getClientInstance().interceptors.response.use(response => {
|
|
257
|
+
return response;
|
|
258
|
+
}, async error => {
|
|
259
|
+
let originalConfig = error.config;
|
|
260
|
+
|
|
261
|
+
if (error.response) {
|
|
262
|
+
if (error.response.status === 401) {
|
|
263
|
+
/**
|
|
264
|
+
* if other requests arrive at the same time
|
|
265
|
+
* as the token refresh, we save them for later
|
|
266
|
+
*/
|
|
267
|
+
if (isSessionRefreshing.current) {
|
|
268
|
+
return new Promise(function (resolve, reject) {
|
|
269
|
+
failedQueue.current.push({
|
|
270
|
+
resolve,
|
|
271
|
+
reject
|
|
272
|
+
});
|
|
273
|
+
}).then(token => {
|
|
274
|
+
originalConfig.headers['Authorization'] = 'Bearer ' + token;
|
|
275
|
+
return _apiServices.http.request(originalConfig);
|
|
276
|
+
}).catch(err => {
|
|
277
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to resolve promises in failedQueue.');
|
|
278
|
+
|
|
279
|
+
return Promise.reject(err);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* we mark the request as retried,
|
|
284
|
+
* we avoid doing it again
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
const session = state.session;
|
|
289
|
+
const authToken = session && 'authToken' in session ? session.authToken : null;
|
|
290
|
+
|
|
291
|
+
if (session.type !== Session.COOKIE_SESSION && !isSessionRefreshing.current && state.user && session && session.handleRefreshToken && Boolean(authToken && authToken.refreshToken)) {
|
|
292
|
+
/**
|
|
293
|
+
* set refreshing mode,
|
|
294
|
+
* save all concurrent request in the meantime
|
|
295
|
+
*/
|
|
296
|
+
try {
|
|
297
|
+
const res = await refreshSession();
|
|
298
|
+
originalConfig.headers.Authorization = `Bearer ${res['accessToken']}`;
|
|
299
|
+
processQueue(null, res['accessToken']);
|
|
300
|
+
return Promise.resolve(_apiServices.http.request(originalConfig));
|
|
301
|
+
} catch (_error) {
|
|
302
|
+
if (_error.response && _error.response.data) {
|
|
303
|
+
processQueue(_error, null);
|
|
304
|
+
return Promise.reject(_error.response.data);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return Promise.reject(error);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return () => {
|
|
316
|
+
if (authInterceptor.current !== null) {
|
|
317
|
+
_apiServices.http.getClientInstance().interceptors.response.eject(authInterceptor.current);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}, [userId, accessToken]);
|
|
321
|
+
/**
|
|
322
|
+
* Reset session if initial conf changed
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
(0, _useDeepCompareEffect.default)(() => {
|
|
326
|
+
dispatch({
|
|
327
|
+
type: userActionTypes.REFRESH_SESSION,
|
|
328
|
+
payload: {
|
|
329
|
+
conf: stateInitializer(initialSession)
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}, [initialSession]);
|
|
333
|
+
return {
|
|
334
|
+
state,
|
|
335
|
+
dispatch,
|
|
336
|
+
helpers: {
|
|
337
|
+
refreshSession
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCCachingManager;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
:::info
|
|
10
|
+
This custom hook manages cached data and the loading state.
|
|
11
|
+
:::
|
|
12
|
+
*/
|
|
13
|
+
function useSCCachingManager() {
|
|
14
|
+
const cache = (0, _react.useRef)([]);
|
|
15
|
+
const [loading, setLoading] = (0, _react.useState)([]);
|
|
16
|
+
const [data, setData] = (0, _react.useState)([]);
|
|
17
|
+
/**
|
|
18
|
+
* Update cache
|
|
19
|
+
* @param ids
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const updateCache = (0, _react.useMemo)(() => ids => {
|
|
23
|
+
ids.map(c => {
|
|
24
|
+
if (!cache.current.includes(c)) {
|
|
25
|
+
cache.current.push(c);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}, [cache]);
|
|
29
|
+
/**
|
|
30
|
+
* Empty cache
|
|
31
|
+
* emptying the cache each isFollow request
|
|
32
|
+
* results in a request to the server
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const emptyCache = (0, _react.useMemo)(() => () => {
|
|
36
|
+
cache.current = [];
|
|
37
|
+
}, [cache]);
|
|
38
|
+
/**
|
|
39
|
+
* Category is checking
|
|
40
|
+
* Return true if the manager is checking
|
|
41
|
+
* the follow status of the obj
|
|
42
|
+
* @param category
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
const isLoading = (0, _react.useMemo)(() => obj => {
|
|
46
|
+
return loading.includes(obj.id);
|
|
47
|
+
}, [loading]);
|
|
48
|
+
return {
|
|
49
|
+
cache: cache.current,
|
|
50
|
+
updateCache,
|
|
51
|
+
emptyCache,
|
|
52
|
+
data,
|
|
53
|
+
setData,
|
|
54
|
+
loading,
|
|
55
|
+
setLoading,
|
|
56
|
+
isLoading
|
|
57
|
+
};
|
|
58
|
+
}
|