@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,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCConnectionsManager;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
9
|
+
|
|
10
|
+
var _types = require("@selfcommunity/types");
|
|
11
|
+
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
13
|
+
|
|
14
|
+
var _Errors = require("../constants/Errors");
|
|
15
|
+
|
|
16
|
+
var _SCPreferencesProvider = require("../components/provider/SCPreferencesProvider");
|
|
17
|
+
|
|
18
|
+
var _Preferences = require("../constants/Preferences");
|
|
19
|
+
|
|
20
|
+
var _useSCCachingManager = _interopRequireDefault(require("./useSCCachingManager"));
|
|
21
|
+
|
|
22
|
+
var _pubsubJs = _interopRequireDefault(require("pubsub-js"));
|
|
23
|
+
|
|
24
|
+
var _Notification = require("../constants/Notification");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Used on refresh and in status method
|
|
30
|
+
* Check if the user status is 'connected', 'sent_connection_request'
|
|
31
|
+
* 'received_connection_request', to update the cache and data
|
|
32
|
+
*/
|
|
33
|
+
const STATUS_CONNECTED = 'connected';
|
|
34
|
+
const STATUS_DISCONNECTED = 'disconnected';
|
|
35
|
+
const STATUS_CONNECTION_REQUEST_SENT = 'sent_connection_request';
|
|
36
|
+
const STATUS_CONNECTION_REQUEST_RECEIVED = 'received_connection_request';
|
|
37
|
+
/**
|
|
38
|
+
:::info
|
|
39
|
+
This custom hook is used to manage to manage friends.
|
|
40
|
+
:::
|
|
41
|
+
|
|
42
|
+
:::tipHow to use it:
|
|
43
|
+
|
|
44
|
+
Follow these steps:
|
|
45
|
+
```jsx
|
|
46
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
47
|
+
2. const scConnectionsManager: SCConnectionsManagerType = scUserContext.manager.connections;
|
|
48
|
+
3. scConnectionsManager.status(user)
|
|
49
|
+
```
|
|
50
|
+
:::
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
function useSCConnectionsManager(user) {
|
|
54
|
+
const {
|
|
55
|
+
cache,
|
|
56
|
+
updateCache,
|
|
57
|
+
emptyCache,
|
|
58
|
+
data,
|
|
59
|
+
setData,
|
|
60
|
+
loading,
|
|
61
|
+
setLoading,
|
|
62
|
+
isLoading
|
|
63
|
+
} = (0, _useSCCachingManager.default)();
|
|
64
|
+
const scPreferencesContext = (0, _SCPreferencesProvider.useSCPreferences)();
|
|
65
|
+
const connectionsDisabled = _Preferences.CONFIGURATIONS_FOLLOW_ENABLED in scPreferencesContext.preferences && scPreferencesContext.preferences[_Preferences.CONFIGURATIONS_FOLLOW_ENABLED].value;
|
|
66
|
+
const notificationConnAcceptSubscription = (0, _react.useRef)(null);
|
|
67
|
+
const notificationConnRequestSubscription = (0, _react.useRef)(null);
|
|
68
|
+
const notificationConnRemoveSubscription = (0, _react.useRef)(null);
|
|
69
|
+
/**
|
|
70
|
+
* Notification subscriber only for FOLLOW
|
|
71
|
+
* @param msg
|
|
72
|
+
* @param data
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
const notificationSubscriber = (msg, data) => {
|
|
76
|
+
if (data.connection && data.connection_id !== undefined) {
|
|
77
|
+
updateCache([data.data.connection.id]);
|
|
78
|
+
let _data = [];
|
|
79
|
+
|
|
80
|
+
if (_Notification.SCNotificationMapping[data.data.activity_type] === _types.SCNotificationTypologyType.CONNECTION_REQUEST) {
|
|
81
|
+
_data = data.map(([k, v]) => ({
|
|
82
|
+
k: k === data.data.connection_id ? STATUS_CONNECTION_REQUEST_SENT : v
|
|
83
|
+
}));
|
|
84
|
+
} else if (_Notification.SCNotificationMapping[data.data.activity_type] === _types.SCNotificationTypologyType.CONNECTION_ACCEPT) {
|
|
85
|
+
_data = data.map(([k, v]) => ({
|
|
86
|
+
k: k === data.data.connection_id ? STATUS_CONNECTED : v
|
|
87
|
+
}));
|
|
88
|
+
} else if (_Notification.SCNotificationMapping[data.data.activity_type] === _types.SCNotificationTypologyType.CONNECTION_REMOVE) {
|
|
89
|
+
_data = data.map(([k, v]) => ({
|
|
90
|
+
k: k === data.data.connection_id ? STATUS_DISCONNECTED : v
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setData(_data);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
(0, _react.useEffect)(() => {
|
|
103
|
+
notificationConnAcceptSubscription.current = _pubsubJs.default.subscribe(`${_types.SCNotificationTopicType.INTERACTION}.${_types.SCNotificationTypologyType.CONNECTION_ACCEPT}`, notificationSubscriber);
|
|
104
|
+
notificationConnRequestSubscription.current = _pubsubJs.default.subscribe(`${_types.SCNotificationTopicType.INTERACTION}.${_types.SCNotificationTypologyType.CONNECTION_REQUEST}`, notificationSubscriber);
|
|
105
|
+
notificationConnRemoveSubscription.current = _pubsubJs.default.subscribe(`${_types.SCNotificationTopicType.INTERACTION}.${_types.SCNotificationTypologyType.CONNECTION_REMOVE}`, notificationSubscriber);
|
|
106
|
+
return () => {
|
|
107
|
+
_pubsubJs.default.unsubscribe(notificationConnAcceptSubscription.current);
|
|
108
|
+
|
|
109
|
+
_pubsubJs.default.unsubscribe(notificationConnRequestSubscription.current);
|
|
110
|
+
|
|
111
|
+
_pubsubJs.default.unsubscribe(notificationConnRemoveSubscription.current);
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
/**
|
|
115
|
+
* Memoized refresh all connections
|
|
116
|
+
* It makes a single request to the server and retrieves
|
|
117
|
+
* all the users connected by the authenticated user in a single solution
|
|
118
|
+
* It might be useful for multi-tab sync
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
const refresh = (0, _react.useMemo)(() => () => {
|
|
122
|
+
emptyCache();
|
|
123
|
+
|
|
124
|
+
if (user && cache.length > 0) {
|
|
125
|
+
// Only if user is authenticated
|
|
126
|
+
_apiServices.http.request({
|
|
127
|
+
url: _apiServices.Endpoints.UserConnectionStatuses.url({}),
|
|
128
|
+
method: _apiServices.Endpoints.UserConnectionStatuses.method,
|
|
129
|
+
data: {
|
|
130
|
+
users: cache
|
|
131
|
+
}
|
|
132
|
+
}).then(res => {
|
|
133
|
+
if (res.status >= 300) {
|
|
134
|
+
return Promise.reject(res);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
updateCache(Object.keys(res.data.connection_statuses).map(id => parseInt(id)));
|
|
138
|
+
setData(Object.entries(res.data.connection_statuses).filter(([k, v]) => v !== null).map(([k, v]) => ({
|
|
139
|
+
[parseInt(k)]: v
|
|
140
|
+
})));
|
|
141
|
+
return Promise.resolve(res.data);
|
|
142
|
+
}).catch(e => {
|
|
143
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh users Connections by the authenticated user.');
|
|
144
|
+
|
|
145
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, e);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, [data, user, cache]);
|
|
149
|
+
/**
|
|
150
|
+
* Memoized Request connection
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
const requestConnection = (0, _react.useMemo)(() => user => {
|
|
154
|
+
setLoading(prev => [...prev, ...[user.id]]);
|
|
155
|
+
|
|
156
|
+
if (getCurrentStatus(user) === STATUS_CONNECTION_REQUEST_RECEIVED) {
|
|
157
|
+
return acceptConnection(user);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return _apiServices.http.request({
|
|
161
|
+
url: _apiServices.Endpoints.UserRequestConnection.url({
|
|
162
|
+
id: user.id
|
|
163
|
+
}),
|
|
164
|
+
method: _apiServices.Endpoints.UserRequestConnection.method
|
|
165
|
+
}).then(res => {
|
|
166
|
+
if (res.status >= 300) {
|
|
167
|
+
return Promise.reject(res);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
updateCache([user.id]);
|
|
171
|
+
|
|
172
|
+
const _data = data.map(([k, v]) => ({
|
|
173
|
+
k: k === user.id ? STATUS_CONNECTION_REQUEST_SENT : v
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
setData(_data);
|
|
177
|
+
setLoading(prev => prev.filter(u => u !== user.id));
|
|
178
|
+
return Promise.resolve(res.data);
|
|
179
|
+
});
|
|
180
|
+
}, [data, loading, cache]);
|
|
181
|
+
/**
|
|
182
|
+
* Memoized Accept Request connection
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
const acceptConnection = (0, _react.useMemo)(() => user => {
|
|
186
|
+
setLoading(prev => [...prev, ...[user.id]]);
|
|
187
|
+
|
|
188
|
+
if (getCurrentStatus(user) === STATUS_CONNECTION_REQUEST_RECEIVED) {
|
|
189
|
+
return _apiServices.http.request({
|
|
190
|
+
url: _apiServices.Endpoints.UserAcceptRequestConnection.url({
|
|
191
|
+
id: user.id
|
|
192
|
+
}),
|
|
193
|
+
method: _apiServices.Endpoints.UserAcceptRequestConnection.method
|
|
194
|
+
}).then(res => {
|
|
195
|
+
if (res.status >= 300) {
|
|
196
|
+
return Promise.reject(res);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
updateCache([user.id]);
|
|
200
|
+
|
|
201
|
+
const _data = data.map(([k, v]) => ({
|
|
202
|
+
k: k === user.id ? STATUS_CONNECTED : v
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
setData(_data);
|
|
206
|
+
setLoading(prev => prev.filter(u => u !== user.id));
|
|
207
|
+
return Promise.resolve(res.data);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}, [data, loading, cache]);
|
|
211
|
+
/**
|
|
212
|
+
* Return current user status if exist,
|
|
213
|
+
* otherwise return null
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
const getCurrentStatus = (0, _react.useMemo)(() => user => {
|
|
217
|
+
const d = data.filter(([id, v]) => id === user.id);
|
|
218
|
+
return d.length ? d[0][user.id] : null;
|
|
219
|
+
}, [data]);
|
|
220
|
+
/**
|
|
221
|
+
* Check if the authenticated user is connected with the user
|
|
222
|
+
* Update the users cached
|
|
223
|
+
* Update user statuses
|
|
224
|
+
* @param user
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
const checkUserConnectionStatus = user => {
|
|
228
|
+
setLoading(prev => prev.includes(user.id) ? prev : [...prev, ...[user.id]]);
|
|
229
|
+
|
|
230
|
+
_apiServices.http.request({
|
|
231
|
+
url: _apiServices.Endpoints.UserCheckConnection.url({
|
|
232
|
+
id: user.id
|
|
233
|
+
}),
|
|
234
|
+
method: _apiServices.Endpoints.UserCheckConnection.method
|
|
235
|
+
}).then(res => {
|
|
236
|
+
if (res.status >= 300) {
|
|
237
|
+
return Promise.reject(res);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
updateCache([user.id]);
|
|
241
|
+
setData(prev => res.data.is_connection ? [...prev, ...[{
|
|
242
|
+
[user.id]: STATUS_CONNECTED
|
|
243
|
+
}]] : prev.filter(([id, v]) => id !== user.id));
|
|
244
|
+
setLoading(prev => prev.filter(u => u !== user.id));
|
|
245
|
+
return Promise.resolve(res.data);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Memoized status
|
|
250
|
+
* If user is already in cache -> check data user statuses,
|
|
251
|
+
* otherwise, check if auth user is connected with user
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
const status = (0, _react.useMemo)(() => user => {
|
|
256
|
+
if (cache.includes(user.id)) {
|
|
257
|
+
return data.filter((k, v) => k === user.id)[0][user.id];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (!loading.includes(user.id)) {
|
|
261
|
+
checkUserConnectionStatus(user);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return null;
|
|
265
|
+
}, [data, loading, cache]);
|
|
266
|
+
|
|
267
|
+
if (connectionsDisabled || !user) {
|
|
268
|
+
return {
|
|
269
|
+
connections: data,
|
|
270
|
+
loading,
|
|
271
|
+
isLoading
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
connections: data,
|
|
277
|
+
loading,
|
|
278
|
+
isLoading,
|
|
279
|
+
status,
|
|
280
|
+
requestConnection,
|
|
281
|
+
acceptConnection,
|
|
282
|
+
refresh,
|
|
283
|
+
emptyCache
|
|
284
|
+
};
|
|
285
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _Errors = require("../constants/Errors");
|
|
9
|
+
|
|
10
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
11
|
+
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
13
|
+
|
|
14
|
+
var _reactSingletonHook = require("react-singleton-hook");
|
|
15
|
+
|
|
16
|
+
const init = {
|
|
17
|
+
categories: [],
|
|
18
|
+
isLoading: true
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
:::info
|
|
22
|
+
This custom hook is used to fetch categories.
|
|
23
|
+
|
|
24
|
+
:::tipContext can be consumed in this way:
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
const {categories, isLoading} = useSCFetchCategories();
|
|
28
|
+
```
|
|
29
|
+
:::
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const useSCFetchCategories = (0, _reactSingletonHook.singletonHook)(init, () => {
|
|
33
|
+
const [data, setData] = (0, _react.useState)(init);
|
|
34
|
+
/**
|
|
35
|
+
* Fetch categories
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const fetchCategories = async (next = _apiServices.Endpoints.CategoryList.url()) => {
|
|
39
|
+
const response = await _apiServices.http.request({
|
|
40
|
+
url: next,
|
|
41
|
+
method: _apiServices.Endpoints.CategoryList.method
|
|
42
|
+
});
|
|
43
|
+
const data = response.data;
|
|
44
|
+
|
|
45
|
+
if (data.next) {
|
|
46
|
+
return data.results.concat(await fetchCategories(data.next));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return data.results;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Get categories
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
fetchCategories().then(data => {
|
|
58
|
+
setData({
|
|
59
|
+
categories: data,
|
|
60
|
+
isLoading: false
|
|
61
|
+
});
|
|
62
|
+
}).catch(error => {
|
|
63
|
+
console.log(error);
|
|
64
|
+
|
|
65
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to retrieve categories');
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
return data;
|
|
69
|
+
});
|
|
70
|
+
var _default = useSCFetchCategories;
|
|
71
|
+
exports.default = _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFetchCategory;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _Errors = require("../constants/Errors");
|
|
9
|
+
|
|
10
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
11
|
+
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
:::info
|
|
16
|
+
This custom hook is used to fetch a category object.
|
|
17
|
+
:::
|
|
18
|
+
* @param object
|
|
19
|
+
* @param object.id
|
|
20
|
+
* @param object.category
|
|
21
|
+
*/
|
|
22
|
+
function useSCFetchCategory({
|
|
23
|
+
id = null,
|
|
24
|
+
category = null
|
|
25
|
+
}) {
|
|
26
|
+
const [scCategory, setSCCategory] = (0, _react.useState)(category);
|
|
27
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
28
|
+
/**
|
|
29
|
+
* Memoized fetchTag
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const fetchCategory = (0, _react.useMemo)(() => () => {
|
|
33
|
+
return _apiServices.http.request({
|
|
34
|
+
url: _apiServices.Endpoints.Category.url({
|
|
35
|
+
id: id
|
|
36
|
+
}),
|
|
37
|
+
method: _apiServices.Endpoints.Category.method
|
|
38
|
+
}).then(res => {
|
|
39
|
+
if (res.status >= 300) {
|
|
40
|
+
return Promise.reject(res);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Promise.resolve(res.data);
|
|
44
|
+
});
|
|
45
|
+
}, [id]);
|
|
46
|
+
/**
|
|
47
|
+
* If id attempt to get the category by id
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
(0, _react.useEffect)(() => {
|
|
51
|
+
if (id) {
|
|
52
|
+
fetchCategory().then(obj => {
|
|
53
|
+
setSCCategory(obj);
|
|
54
|
+
}).catch(err => {
|
|
55
|
+
setError(`Category with id ${id} not found`);
|
|
56
|
+
|
|
57
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, `Category with id ${id} not found`);
|
|
58
|
+
|
|
59
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, err.message);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [id]);
|
|
63
|
+
return {
|
|
64
|
+
scCategory,
|
|
65
|
+
setSCCategory,
|
|
66
|
+
error
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFetchCommentObject;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _Errors = require("../constants/Errors");
|
|
9
|
+
|
|
10
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
11
|
+
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
:::info
|
|
16
|
+
This custom hooks is used to fetch a comment.
|
|
17
|
+
:::
|
|
18
|
+
* @param object
|
|
19
|
+
* @param object.id
|
|
20
|
+
* @param object.commentObject
|
|
21
|
+
*/
|
|
22
|
+
function useSCFetchCommentObject({
|
|
23
|
+
id = null,
|
|
24
|
+
commentObject = null
|
|
25
|
+
}) {
|
|
26
|
+
const [obj, setObj] = (0, _react.useState)(commentObject);
|
|
27
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
28
|
+
/**
|
|
29
|
+
* Memoized fetchCommentObject
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const fetchCommentObject = (0, _react.useMemo)(() => () => {
|
|
33
|
+
return _apiServices.http.request({
|
|
34
|
+
url: _apiServices.Endpoints.Comment.url({
|
|
35
|
+
id: id
|
|
36
|
+
}),
|
|
37
|
+
method: _apiServices.Endpoints.Comment.method
|
|
38
|
+
}).then(res => {
|
|
39
|
+
if (res.status >= 300) {
|
|
40
|
+
return Promise.reject(res);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Promise.resolve(res.data);
|
|
44
|
+
});
|
|
45
|
+
}, [id]);
|
|
46
|
+
/**
|
|
47
|
+
* If id and feedObjectType resolve feddObject
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
(0, _react.useEffect)(() => {
|
|
51
|
+
if (id) {
|
|
52
|
+
fetchCommentObject().then(obj => {
|
|
53
|
+
setObj(obj);
|
|
54
|
+
}).catch(err => {
|
|
55
|
+
setError(`CommentObject with id ${id} not found`);
|
|
56
|
+
|
|
57
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, `CommentObject with id ${id} not found`);
|
|
58
|
+
|
|
59
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, err.message);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [id]);
|
|
63
|
+
return {
|
|
64
|
+
obj,
|
|
65
|
+
setObj,
|
|
66
|
+
error
|
|
67
|
+
};
|
|
68
|
+
}
|