@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,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFollowedCategoriesManager;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
9
|
+
|
|
10
|
+
var _useSCCachingManager = _interopRequireDefault(require("./useSCCachingManager"));
|
|
11
|
+
|
|
12
|
+
var _Errors = require("../constants/Errors");
|
|
13
|
+
|
|
14
|
+
var _logger = require("../utils/logger");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
:::info
|
|
20
|
+
This custom hook is used to manage the categories followed.
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
:::tipHow to use it:
|
|
24
|
+
Follow these steps:
|
|
25
|
+
```jsx
|
|
26
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
27
|
+
2. const scFollowedCategoriesManager: SCFollowedCategoriesManagerType = scUserContext.manager.categories;
|
|
28
|
+
3. scFollowedCategoriesManager.isFollowed(category)
|
|
29
|
+
```
|
|
30
|
+
:::
|
|
31
|
+
*/
|
|
32
|
+
function useSCFollowedCategoriesManager(user) {
|
|
33
|
+
const {
|
|
34
|
+
cache,
|
|
35
|
+
updateCache,
|
|
36
|
+
emptyCache,
|
|
37
|
+
data,
|
|
38
|
+
setData,
|
|
39
|
+
loading,
|
|
40
|
+
setLoading,
|
|
41
|
+
isLoading
|
|
42
|
+
} = (0, _useSCCachingManager.default)();
|
|
43
|
+
/**
|
|
44
|
+
* Memoized refresh all categories
|
|
45
|
+
* It makes a single request to the server and retrieves
|
|
46
|
+
* all the categories followed by the user in a single solution
|
|
47
|
+
* It might be useful for multi-tab sync
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
const refresh = (0, _react.useMemo)(() => () => {
|
|
51
|
+
emptyCache();
|
|
52
|
+
|
|
53
|
+
if (user) {
|
|
54
|
+
// Only if user is authenticated
|
|
55
|
+
_apiServices.http.request({
|
|
56
|
+
url: _apiServices.Endpoints.FollowedCategories.url({
|
|
57
|
+
id: user.id
|
|
58
|
+
}),
|
|
59
|
+
method: _apiServices.Endpoints.FollowedCategories.method
|
|
60
|
+
}).then(res => {
|
|
61
|
+
if (res.status >= 300) {
|
|
62
|
+
return Promise.reject(res);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const categoryIds = res.data.map(c => c.id);
|
|
66
|
+
updateCache(categoryIds);
|
|
67
|
+
setData(categoryIds);
|
|
68
|
+
return Promise.resolve(res.data);
|
|
69
|
+
}).catch(e => {
|
|
70
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh categories followed by the authenticated user.');
|
|
71
|
+
|
|
72
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, e);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, [data, user, cache]);
|
|
76
|
+
/**
|
|
77
|
+
* Memoized follow/unfollow Category
|
|
78
|
+
* Toggle action
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
const follow = (0, _react.useMemo)(() => category => {
|
|
82
|
+
setLoading(prev => [...prev, ...[category.id]]);
|
|
83
|
+
return _apiServices.http.request({
|
|
84
|
+
url: _apiServices.Endpoints.FollowCategory.url({
|
|
85
|
+
id: category.id
|
|
86
|
+
}),
|
|
87
|
+
method: _apiServices.Endpoints.FollowCategory.method
|
|
88
|
+
}).then(res => {
|
|
89
|
+
if (res.status >= 300) {
|
|
90
|
+
return Promise.reject(res);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
updateCache([category.id]);
|
|
94
|
+
const isFollowed = data.includes(category.id);
|
|
95
|
+
setData(prev => isFollowed ? prev.filter(id => id !== category.id) : [...[category.id], ...prev]);
|
|
96
|
+
setLoading(prev => prev.filter(c => c !== category.id));
|
|
97
|
+
return Promise.resolve(res.data);
|
|
98
|
+
});
|
|
99
|
+
}, [data, loading, cache]);
|
|
100
|
+
/**
|
|
101
|
+
* Check if the user follow the category
|
|
102
|
+
* Update the categories cached
|
|
103
|
+
* Update categories followed
|
|
104
|
+
* @param category
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
const checkIsCategoryFollowed = category => {
|
|
108
|
+
setLoading(prev => prev.includes(category.id) ? prev : [...prev, ...[category.id]]);
|
|
109
|
+
|
|
110
|
+
_apiServices.http.request({
|
|
111
|
+
url: _apiServices.Endpoints.CheckCategoryIsFollowed.url({
|
|
112
|
+
id: category.id
|
|
113
|
+
}),
|
|
114
|
+
method: _apiServices.Endpoints.CheckCategoryIsFollowed.method
|
|
115
|
+
}).then(res => {
|
|
116
|
+
if (res.status >= 300) {
|
|
117
|
+
return Promise.reject(res);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updateCache([category.id]);
|
|
121
|
+
setData(prev => res.data.is_followed ? [...[category.id], ...prev] : prev.filter(id => id !== category.id));
|
|
122
|
+
setLoading(prev => prev.filter(c => c !== category.id));
|
|
123
|
+
return Promise.resolve(res.data);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Memoized isFollowed
|
|
128
|
+
* If category is already in cache -> check if the category is in categories,
|
|
129
|
+
* otherwise, check if user follow the category
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
const isFollowed = (0, _react.useMemo)(() => category => {
|
|
134
|
+
if (cache.includes(category.id)) {
|
|
135
|
+
return Boolean(data.includes(category.id));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!loading.includes(category.id)) {
|
|
139
|
+
checkIsCategoryFollowed(category);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return false;
|
|
143
|
+
}, [data, loading, cache]);
|
|
144
|
+
|
|
145
|
+
if (!user) {
|
|
146
|
+
return {
|
|
147
|
+
categories: data,
|
|
148
|
+
loading,
|
|
149
|
+
isLoading
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
categories: data,
|
|
155
|
+
loading,
|
|
156
|
+
isLoading,
|
|
157
|
+
follow,
|
|
158
|
+
isFollowed,
|
|
159
|
+
refresh,
|
|
160
|
+
emptyCache
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFollowedManager;
|
|
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 isFollowed method
|
|
30
|
+
* Check if the user status is 'followed'
|
|
31
|
+
* to update the cache and data
|
|
32
|
+
*/
|
|
33
|
+
const STATUS_FOLLOWED = 'followed';
|
|
34
|
+
/**
|
|
35
|
+
:::info
|
|
36
|
+
This custom hook is used to manage to manage followed users.
|
|
37
|
+
:::
|
|
38
|
+
:::tipHow to use it:
|
|
39
|
+
|
|
40
|
+
Follow these steps:
|
|
41
|
+
```jsx
|
|
42
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
43
|
+
2. const scFollowedManager: SCFollowedManagerType = scUserContext.manager.followed;
|
|
44
|
+
3. scFollowedManager.isFollowed(user)
|
|
45
|
+
```
|
|
46
|
+
:::
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
function useSCFollowedManager(user) {
|
|
50
|
+
const {
|
|
51
|
+
cache,
|
|
52
|
+
updateCache,
|
|
53
|
+
emptyCache,
|
|
54
|
+
data,
|
|
55
|
+
setData,
|
|
56
|
+
loading,
|
|
57
|
+
setLoading,
|
|
58
|
+
isLoading
|
|
59
|
+
} = (0, _useSCCachingManager.default)();
|
|
60
|
+
const scPreferencesContext = (0, _SCPreferencesProvider.useSCPreferences)();
|
|
61
|
+
const followEnabled = _Preferences.CONFIGURATIONS_FOLLOW_ENABLED in scPreferencesContext.preferences && scPreferencesContext.preferences[_Preferences.CONFIGURATIONS_FOLLOW_ENABLED].value;
|
|
62
|
+
const notificationFollowSubscription = (0, _react.useRef)(null);
|
|
63
|
+
const notificationUnFollowSubscription = (0, _react.useRef)(null);
|
|
64
|
+
/**
|
|
65
|
+
* Notification subscriber only for FOLLOW
|
|
66
|
+
* @param msg
|
|
67
|
+
* @param data
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
const notificationSubscriber = (msg, data) => {
|
|
71
|
+
if (data.connection && data.connection_id !== undefined) {
|
|
72
|
+
updateCache([data.connection_id]);
|
|
73
|
+
|
|
74
|
+
if (_Notification.SCNotificationMapping[data.data.activity_type] === _types.SCNotificationTypologyType.USER_FOLLOW) {
|
|
75
|
+
if (!data.includes(user.id)) {
|
|
76
|
+
setData(prev => [...[data.connection_id], ...prev]);
|
|
77
|
+
}
|
|
78
|
+
} else if (_Notification.SCNotificationMapping[data.data.activity_type] === _types.SCNotificationTypologyType.USER_UNFOLLOW) {
|
|
79
|
+
if (data.includes(user.id)) {
|
|
80
|
+
setData(prev => prev.filter(id => id !== data.connection_id));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
(0, _react.useEffect)(() => {
|
|
91
|
+
notificationFollowSubscription.current = _pubsubJs.default.subscribe(`${_types.SCNotificationTopicType.INTERACTION}.${_types.SCNotificationTypologyType.USER_FOLLOW}`, notificationSubscriber);
|
|
92
|
+
notificationUnFollowSubscription.current = _pubsubJs.default.subscribe(`${_types.SCNotificationTopicType.INTERACTION}.${_types.SCNotificationTypologyType.USER_UNFOLLOW}`, notificationSubscriber);
|
|
93
|
+
return () => {
|
|
94
|
+
_pubsubJs.default.unsubscribe(notificationFollowSubscription.current);
|
|
95
|
+
|
|
96
|
+
_pubsubJs.default.unsubscribe(notificationUnFollowSubscription.current);
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
/**
|
|
100
|
+
* Memoized refresh all followed
|
|
101
|
+
* It makes a single request to the server and retrieves
|
|
102
|
+
* all the users followed by the authenticated user in a single solution
|
|
103
|
+
* It might be useful for multi-tab sync
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
const refresh = (0, _react.useMemo)(() => () => {
|
|
107
|
+
emptyCache();
|
|
108
|
+
|
|
109
|
+
if (user && cache.length > 0) {
|
|
110
|
+
// Only if user is authenticated
|
|
111
|
+
_apiServices.http.request({
|
|
112
|
+
url: _apiServices.Endpoints.UserConnectionStatuses.url({}),
|
|
113
|
+
method: _apiServices.Endpoints.UserConnectionStatuses.method,
|
|
114
|
+
data: {
|
|
115
|
+
users: cache
|
|
116
|
+
}
|
|
117
|
+
}).then(res => {
|
|
118
|
+
if (res.status >= 300) {
|
|
119
|
+
return Promise.reject(res);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
updateCache(Object.keys(res.data.connection_statuses).map(id => parseInt(id)));
|
|
123
|
+
setData(Object.entries(res.data.connection_statuses).filter(([k, v]) => v === STATUS_FOLLOWED).map(([k, v]) => parseInt(k)));
|
|
124
|
+
return Promise.resolve(res.data);
|
|
125
|
+
}).catch(e => {
|
|
126
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh users followed by the authenticated user.');
|
|
127
|
+
|
|
128
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, e);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, [data, user, cache]);
|
|
132
|
+
/**
|
|
133
|
+
* Memoized follow/unfollow User
|
|
134
|
+
* Toggle action
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
const follow = (0, _react.useMemo)(() => user => {
|
|
138
|
+
setLoading(prev => [...prev, ...[user.id]]);
|
|
139
|
+
return _apiServices.http.request({
|
|
140
|
+
url: _apiServices.Endpoints.FollowUser.url({
|
|
141
|
+
id: user.id
|
|
142
|
+
}),
|
|
143
|
+
method: _apiServices.Endpoints.FollowUser.method
|
|
144
|
+
}).then(res => {
|
|
145
|
+
if (res.status >= 300) {
|
|
146
|
+
return Promise.reject(res);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
updateCache([user.id]);
|
|
150
|
+
const isFollowed = data.includes(user.id);
|
|
151
|
+
setData(prev => isFollowed ? prev.filter(id => id !== user.id) : [...[user.id], ...prev]);
|
|
152
|
+
setLoading(prev => prev.filter(u => u !== user.id));
|
|
153
|
+
return Promise.resolve(res.data);
|
|
154
|
+
});
|
|
155
|
+
}, [data, loading, cache]);
|
|
156
|
+
/**
|
|
157
|
+
* Check if the authenticated user follow the user
|
|
158
|
+
* Update the followed cached
|
|
159
|
+
* Update followed user
|
|
160
|
+
* @param user
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
const checkIsUserFollowed = user => {
|
|
164
|
+
setLoading(prev => prev.includes(user.id) ? prev : [...prev, ...[user.id]]);
|
|
165
|
+
|
|
166
|
+
_apiServices.http.request({
|
|
167
|
+
url: _apiServices.Endpoints.CheckUserFollowed.url({
|
|
168
|
+
id: user.id
|
|
169
|
+
}),
|
|
170
|
+
method: _apiServices.Endpoints.CheckUserFollowed.method
|
|
171
|
+
}).then(res => {
|
|
172
|
+
if (res.status >= 300) {
|
|
173
|
+
return Promise.reject(res);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
updateCache([user.id]);
|
|
177
|
+
setData(prev => res.data.is_followed ? [...prev, ...[user.id]] : prev.filter(id => id !== user.id));
|
|
178
|
+
setLoading(prev => prev.filter(u => u !== user.id));
|
|
179
|
+
return Promise.resolve(res.data);
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Bypass remote check if the user is followed
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
const getConnectionStatus = (0, _react.useMemo)(() => user => {
|
|
188
|
+
const isFollowed = user.connection_status === STATUS_FOLLOWED;
|
|
189
|
+
updateCache([user.id]);
|
|
190
|
+
setData(prev => isFollowed ? [...prev, ...[user.id]] : prev);
|
|
191
|
+
return isFollowed;
|
|
192
|
+
}, [data, cache]);
|
|
193
|
+
/**
|
|
194
|
+
* Memoized isFollowed
|
|
195
|
+
* If user is already in cache -> check if the user is in followed,
|
|
196
|
+
* otherwise, check if auth user follow the user
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
const isFollowed = (0, _react.useMemo)(() => user => {
|
|
200
|
+
if (cache.includes(user.id)) {
|
|
201
|
+
return Boolean(data.includes(user.id));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if ('connection_status' in user) {
|
|
205
|
+
return getConnectionStatus(user);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!loading.includes(user.id)) {
|
|
209
|
+
checkIsUserFollowed(user);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return false;
|
|
213
|
+
}, [data, loading, cache]);
|
|
214
|
+
|
|
215
|
+
if (!followEnabled || !user) {
|
|
216
|
+
return {
|
|
217
|
+
followed: data,
|
|
218
|
+
loading,
|
|
219
|
+
isLoading
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
followed: data,
|
|
225
|
+
loading,
|
|
226
|
+
isLoading,
|
|
227
|
+
follow,
|
|
228
|
+
isFollowed,
|
|
229
|
+
refresh,
|
|
230
|
+
emptyCache
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCMediaClick;
|
|
5
|
+
|
|
6
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
7
|
+
|
|
8
|
+
var _logger = require("../utils/logger");
|
|
9
|
+
|
|
10
|
+
var _Errors = require("../constants/Errors");
|
|
11
|
+
|
|
12
|
+
function useSCMediaClick() {
|
|
13
|
+
const handleMediaClick = mediaObj => {
|
|
14
|
+
_apiServices.http.request({
|
|
15
|
+
url: _apiServices.Endpoints.MediaClickTracker.url({
|
|
16
|
+
id: mediaObj.id
|
|
17
|
+
}),
|
|
18
|
+
method: _apiServices.Endpoints.MediaClickTracker.method
|
|
19
|
+
}).catch(error => {
|
|
20
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, error);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
handleMediaClick
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCSubscribedIncubatorsManager;
|
|
5
|
+
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
|
|
8
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
9
|
+
|
|
10
|
+
var _logger = require("../utils/logger");
|
|
11
|
+
|
|
12
|
+
var _Errors = require("../constants/Errors");
|
|
13
|
+
|
|
14
|
+
var _useSCCachingManager = _interopRequireDefault(require("./useSCCachingManager"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
:::info
|
|
20
|
+
This custom hook is used to manage to manage subscribed incubators.
|
|
21
|
+
:::
|
|
22
|
+
:::tipHow to use it:
|
|
23
|
+
|
|
24
|
+
Follow these steps:
|
|
25
|
+
```jsx
|
|
26
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
27
|
+
2. const scSubscribedIncubatorsManager: SCSubscribedIncubatorsManagerType = scUserContext.managers.incubators;
|
|
28
|
+
3. scSubscribedIncubatorsManager.isSubscribed(incubator)
|
|
29
|
+
```
|
|
30
|
+
:::
|
|
31
|
+
*/
|
|
32
|
+
function useSCSubscribedIncubatorsManager(user) {
|
|
33
|
+
const {
|
|
34
|
+
cache,
|
|
35
|
+
updateCache,
|
|
36
|
+
emptyCache,
|
|
37
|
+
data,
|
|
38
|
+
setData,
|
|
39
|
+
loading,
|
|
40
|
+
setLoading,
|
|
41
|
+
isLoading
|
|
42
|
+
} = (0, _useSCCachingManager.default)();
|
|
43
|
+
/**
|
|
44
|
+
* Memoized refresh all subscribed
|
|
45
|
+
* It makes a single request to the server and retrieves
|
|
46
|
+
* all the incubators subscribed by the authenticated user in a single solution
|
|
47
|
+
* It might be useful for multi-tab sync
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
const refresh = (0, _react.useMemo)(() => () => {
|
|
51
|
+
emptyCache();
|
|
52
|
+
|
|
53
|
+
if (user) {
|
|
54
|
+
// Only if user is authenticated
|
|
55
|
+
_apiServices.http.request({
|
|
56
|
+
url: _apiServices.Endpoints.GetAllIncubators.url({}),
|
|
57
|
+
method: _apiServices.Endpoints.GetAllIncubators.method
|
|
58
|
+
}).then(res => {
|
|
59
|
+
if (res.status >= 300) {
|
|
60
|
+
return Promise.reject(res);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateCache(Object.keys(res.data.results).map(id => parseInt(id)));
|
|
64
|
+
setData(Object.entries(res.data.results).filter(([k, v]) => v === true).map(([k, v]) => parseInt(k)));
|
|
65
|
+
return Promise.resolve(res.data);
|
|
66
|
+
}).catch(e => {
|
|
67
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh incubators subscribed by the authenticated user.');
|
|
68
|
+
|
|
69
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, e);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, [data, user, cache]);
|
|
73
|
+
/**
|
|
74
|
+
* Memoized subscribe/unsubscribe incubator
|
|
75
|
+
* Toggle action
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
const subscribe = (0, _react.useMemo)(() => incubator => {
|
|
79
|
+
setLoading(prev => [...prev, ...[incubator.id]]);
|
|
80
|
+
return _apiServices.http.request({
|
|
81
|
+
url: _apiServices.Endpoints.SubscribeToIncubator.url({
|
|
82
|
+
id: incubator.id
|
|
83
|
+
}),
|
|
84
|
+
method: _apiServices.Endpoints.SubscribeToIncubator.method
|
|
85
|
+
}).then(res => {
|
|
86
|
+
if (res.status >= 300) {
|
|
87
|
+
return Promise.reject(res);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updateCache([incubator.id]);
|
|
91
|
+
const isSubscribed = data.includes(incubator.id);
|
|
92
|
+
setData(prev => isSubscribed ? prev.filter(id => id !== incubator.id) : [...[incubator.id], ...prev]);
|
|
93
|
+
setLoading(prev => prev.filter(i => i !== incubator.id));
|
|
94
|
+
return Promise.resolve(res.data);
|
|
95
|
+
});
|
|
96
|
+
}, [data, loading, cache]);
|
|
97
|
+
/**
|
|
98
|
+
* Check if the authenticated user has subscribed the incubator
|
|
99
|
+
* Update the subscribed cached
|
|
100
|
+
* Update subscribed incubators
|
|
101
|
+
* @param incubator
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
const checkIsIncubatorFollowed = incubator => {
|
|
105
|
+
setLoading(prev => prev.includes(incubator.id) ? prev : [...prev, ...[incubator.id]]);
|
|
106
|
+
|
|
107
|
+
_apiServices.http.request({
|
|
108
|
+
url: _apiServices.Endpoints.CheckIncubatorSubscription.url({
|
|
109
|
+
id: incubator.id
|
|
110
|
+
}),
|
|
111
|
+
method: _apiServices.Endpoints.CheckIncubatorSubscription.method
|
|
112
|
+
}).then(res => {
|
|
113
|
+
if (res.status >= 300) {
|
|
114
|
+
return Promise.reject(res);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
updateCache([incubator.id]);
|
|
118
|
+
setData(prev => res.data.subscribed ? [...prev, ...[incubator.id]] : prev.filter(id => id !== incubator.id));
|
|
119
|
+
setLoading(prev => prev.filter(i => i !== incubator.id));
|
|
120
|
+
return Promise.resolve(res.data);
|
|
121
|
+
});
|
|
122
|
+
}; // /**
|
|
123
|
+
// * Bypass remote check if the incubator is subscribed
|
|
124
|
+
// */
|
|
125
|
+
// const getSubscriptionStatus = useMemo(
|
|
126
|
+
// () => (incubator: SCIncubatorType) => {
|
|
127
|
+
// const isSubscribed = incubator.subscribed === true;
|
|
128
|
+
// updateCache([incubator.id]);
|
|
129
|
+
// setData((prev) => (isSubscribed ? [...prev, ...[incubator.id]] : prev));
|
|
130
|
+
// return isSubscribed;
|
|
131
|
+
// },
|
|
132
|
+
// [data, cache]
|
|
133
|
+
// );
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Memoized isSubscribed
|
|
137
|
+
* If incubator is already in cache -> check if the incubator is in subscribed,
|
|
138
|
+
* otherwise, check if auth user is subscribed to the incubator
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
const isSubscribed = (0, _react.useMemo)(() => incubator => {
|
|
143
|
+
if (cache.includes(incubator.id)) {
|
|
144
|
+
return Boolean(data.includes(incubator.id));
|
|
145
|
+
} // if ('subscribed' in incubator) {
|
|
146
|
+
// return getSubscriptionStatus(incubator);
|
|
147
|
+
// }
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if (!loading.includes(incubator.id)) {
|
|
151
|
+
checkIsIncubatorFollowed(incubator);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return false;
|
|
155
|
+
}, [data, loading, cache]);
|
|
156
|
+
return {
|
|
157
|
+
incubators: data,
|
|
158
|
+
loading,
|
|
159
|
+
isLoading,
|
|
160
|
+
subscribe,
|
|
161
|
+
isSubscribed,
|
|
162
|
+
refresh,
|
|
163
|
+
emptyCache
|
|
164
|
+
};
|
|
165
|
+
}
|