@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,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
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.commentsObjectActionTypes = void 0;
|
|
5
|
+
exports.default = useSCFetchCommentObjects;
|
|
6
|
+
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
|
|
9
|
+
var _Errors = require("../constants/Errors");
|
|
10
|
+
|
|
11
|
+
var _types = require("@selfcommunity/types");
|
|
12
|
+
|
|
13
|
+
var _apiServices = require("@selfcommunity/api-services");
|
|
14
|
+
|
|
15
|
+
var _logger = require("../utils/logger");
|
|
16
|
+
|
|
17
|
+
var _useSCFetchFeedObject = _interopRequireDefault(require("./useSCFetchFeedObject"));
|
|
18
|
+
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @hidden
|
|
23
|
+
* We have complex state logic that involves multiple sub-values,
|
|
24
|
+
* so useReducer is preferable to useState.
|
|
25
|
+
* Define all possible auth action types label
|
|
26
|
+
* Use this to export actions and dispatch an action
|
|
27
|
+
*/
|
|
28
|
+
const commentsObjectActionTypes = {
|
|
29
|
+
LOADING_NEXT: '_loading_next',
|
|
30
|
+
LOADING_PREVIOUS: '_loading_previous',
|
|
31
|
+
DATA_NEXT_LOADED: '_data_next_loaded',
|
|
32
|
+
DATA_PREVIOUS_LOADED: '_data_previous_loaded',
|
|
33
|
+
DATA_RELOAD: '_data_reload',
|
|
34
|
+
DATA_RELOADED: '_data_reloaded'
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* commentsReducer:
|
|
38
|
+
* - manage the state of comments object
|
|
39
|
+
* - update the state base on action type
|
|
40
|
+
* @param state
|
|
41
|
+
* @param action
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
exports.commentsObjectActionTypes = commentsObjectActionTypes;
|
|
45
|
+
|
|
46
|
+
function commentsReducer(state, action) {
|
|
47
|
+
switch (action.type) {
|
|
48
|
+
case commentsObjectActionTypes.LOADING_NEXT:
|
|
49
|
+
return Object.assign({}, state, {
|
|
50
|
+
isLoadingNext: true,
|
|
51
|
+
isLoadingPrevious: false
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
case commentsObjectActionTypes.LOADING_PREVIOUS:
|
|
55
|
+
return Object.assign({}, state, {
|
|
56
|
+
isLoadingNext: false,
|
|
57
|
+
isLoadingPrevious: true
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
case commentsObjectActionTypes.DATA_NEXT_LOADED:
|
|
61
|
+
return Object.assign({}, state, {
|
|
62
|
+
page: action.payload.currentPage,
|
|
63
|
+
comments: action.payload.comments,
|
|
64
|
+
isLoadingNext: false,
|
|
65
|
+
componentLoaded: true,
|
|
66
|
+
next: action.payload.next
|
|
67
|
+
}, action.payload.previous ? {
|
|
68
|
+
previous: action.payload.previous
|
|
69
|
+
} : {}, action.payload.total ? {
|
|
70
|
+
total: action.payload.total
|
|
71
|
+
} : {});
|
|
72
|
+
|
|
73
|
+
case commentsObjectActionTypes.DATA_PREVIOUS_LOADED:
|
|
74
|
+
return Object.assign({}, state, {
|
|
75
|
+
page: action.payload.currentPage,
|
|
76
|
+
comments: action.payload.comments,
|
|
77
|
+
isLoadingPrevious: false,
|
|
78
|
+
previous: action.payload.previous
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
case commentsObjectActionTypes.DATA_RELOAD:
|
|
82
|
+
return Object.assign({}, state, {
|
|
83
|
+
next: action.payload.next,
|
|
84
|
+
comments: [],
|
|
85
|
+
total: 0,
|
|
86
|
+
previous: null,
|
|
87
|
+
reload: true
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
case commentsObjectActionTypes.DATA_RELOADED:
|
|
91
|
+
return Object.assign({}, state, {
|
|
92
|
+
componentLoaded: false,
|
|
93
|
+
reload: false
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Unhandled type: ${action.type}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Define initial state
|
|
102
|
+
* @param data
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
function stateInitializer(data) {
|
|
107
|
+
return {
|
|
108
|
+
componentLoaded: false,
|
|
109
|
+
comments: [],
|
|
110
|
+
total: 0,
|
|
111
|
+
next: data.next,
|
|
112
|
+
previous: null,
|
|
113
|
+
isLoadingNext: false,
|
|
114
|
+
isLoadingPrevious: false,
|
|
115
|
+
page: data.offset / data.pageSize + 1,
|
|
116
|
+
reload: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
:::info
|
|
121
|
+
This custom hooks is used to fetch paginated comments.
|
|
122
|
+
:::
|
|
123
|
+
* @param id
|
|
124
|
+
* @param feedObject
|
|
125
|
+
* @param feedObjectType
|
|
126
|
+
* @param offset
|
|
127
|
+
* @param pageSize
|
|
128
|
+
* @param orderBy
|
|
129
|
+
* @param parent
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
function useSCFetchCommentObjects(props) {
|
|
134
|
+
// PROPS
|
|
135
|
+
const {
|
|
136
|
+
id,
|
|
137
|
+
feedObject,
|
|
138
|
+
feedObjectType,
|
|
139
|
+
offset = 0,
|
|
140
|
+
pageSize = 5,
|
|
141
|
+
orderBy = _types.SCCommentsOrderBy.ADDED_AT_DESC,
|
|
142
|
+
parent,
|
|
143
|
+
onChangePage
|
|
144
|
+
} = props; // FeedObject
|
|
145
|
+
|
|
146
|
+
const {
|
|
147
|
+
obj,
|
|
148
|
+
setObj
|
|
149
|
+
} = (0, _useSCFetchFeedObject.default)({
|
|
150
|
+
id,
|
|
151
|
+
feedObject,
|
|
152
|
+
feedObjectType
|
|
153
|
+
});
|
|
154
|
+
const objId = obj ? obj.id : null;
|
|
155
|
+
/**
|
|
156
|
+
* Get next url
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
const getNextUrl = () => {
|
|
160
|
+
const _offset = offset ? `&offset=${offset}` : '';
|
|
161
|
+
|
|
162
|
+
const _parent = parent ? `&parent=${parent}` : '';
|
|
163
|
+
|
|
164
|
+
const _objectId = obj ? obj.id : id;
|
|
165
|
+
|
|
166
|
+
const _typeObject = obj ? obj.type : feedObjectType;
|
|
167
|
+
|
|
168
|
+
return `${_apiServices.Endpoints.Comments.url()}?${_typeObject}=${_objectId}&limit=${pageSize}&ordering=${orderBy}${_offset}${_parent}`;
|
|
169
|
+
}; // STATE
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
const [state, dispatch] = (0, _react.useReducer)(commentsReducer, {}, () => stateInitializer({
|
|
173
|
+
offset,
|
|
174
|
+
pageSize,
|
|
175
|
+
next: getNextUrl()
|
|
176
|
+
}));
|
|
177
|
+
/**
|
|
178
|
+
* Calculate current page
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
const getCurrentPage = url => {
|
|
182
|
+
const urlSearchParams = new URLSearchParams(url);
|
|
183
|
+
const params = Object.fromEntries(urlSearchParams.entries());
|
|
184
|
+
const currentOffset = params.offset ? parseInt(params.offset) : 0;
|
|
185
|
+
return currentOffset / pageSize + 1;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Get Comments
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
const performFetchComments = url => {
|
|
193
|
+
return _apiServices.http.request({
|
|
194
|
+
url,
|
|
195
|
+
method: _apiServices.Endpoints.Comments.method
|
|
196
|
+
}).then(res => {
|
|
197
|
+
if (res.status >= 300) {
|
|
198
|
+
return Promise.reject(res);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return Promise.resolve(res.data);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Fetch previous comments
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
function getPreviousPage() {
|
|
210
|
+
if (obj && state.previous && !state.isLoadingPrevious) {
|
|
211
|
+
dispatch({
|
|
212
|
+
type: commentsObjectActionTypes.LOADING_PREVIOUS
|
|
213
|
+
});
|
|
214
|
+
performFetchComments(state.previous).then(res => {
|
|
215
|
+
let currentPage = getCurrentPage(state.previous);
|
|
216
|
+
dispatch({
|
|
217
|
+
type: commentsObjectActionTypes.DATA_PREVIOUS_LOADED,
|
|
218
|
+
payload: {
|
|
219
|
+
page: currentPage,
|
|
220
|
+
comments: [...res.results, ...state.comments],
|
|
221
|
+
previous: res.previous
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
onChangePage && onChangePage(currentPage);
|
|
225
|
+
}).catch(error => {
|
|
226
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, error);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Fetch next comments
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
function getNextPage() {
|
|
236
|
+
if (obj && state.next && !state.isLoadingNext) {
|
|
237
|
+
dispatch({
|
|
238
|
+
type: commentsObjectActionTypes.LOADING_NEXT
|
|
239
|
+
});
|
|
240
|
+
performFetchComments(state.next).then(res => {
|
|
241
|
+
let currentPage = getCurrentPage(state.next);
|
|
242
|
+
dispatch({
|
|
243
|
+
type: commentsObjectActionTypes.DATA_NEXT_LOADED,
|
|
244
|
+
payload: Object.assign({
|
|
245
|
+
page: currentPage,
|
|
246
|
+
comments: [...state.comments, ...res.results],
|
|
247
|
+
next: res.next,
|
|
248
|
+
total: res.count,
|
|
249
|
+
componentLoaded: true
|
|
250
|
+
}, offset && state.comments.length === 0 ? {
|
|
251
|
+
previous: res.previous
|
|
252
|
+
} : {})
|
|
253
|
+
});
|
|
254
|
+
onChangePage && onChangePage(currentPage);
|
|
255
|
+
}).catch(error => {
|
|
256
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, error);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Reset component status on change orderBy, pageSize, offset
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
(0, _react.useEffect)(() => {
|
|
266
|
+
if (state.componentLoaded && Boolean(obj) && !state.reload) {
|
|
267
|
+
dispatch({
|
|
268
|
+
type: commentsObjectActionTypes.DATA_RELOAD,
|
|
269
|
+
payload: {
|
|
270
|
+
next: getNextUrl()
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}, [objId, parent, orderBy, pageSize, offset]);
|
|
275
|
+
/**
|
|
276
|
+
* Reload fetch comments
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
(0, _react.useEffect)(() => {
|
|
280
|
+
if (state.componentLoaded && state.reload && !state.isLoadingNext && !state.isLoadingPrevious) {
|
|
281
|
+
dispatch({
|
|
282
|
+
type: commentsObjectActionTypes.DATA_RELOADED
|
|
283
|
+
});
|
|
284
|
+
getNextPage();
|
|
285
|
+
}
|
|
286
|
+
}, [state.reload]);
|
|
287
|
+
return Object.assign({
|
|
288
|
+
feedObject: obj,
|
|
289
|
+
setFeedObject: setObj
|
|
290
|
+
}, state, {
|
|
291
|
+
pageSize,
|
|
292
|
+
getNextPage,
|
|
293
|
+
getPreviousPage,
|
|
294
|
+
orderBy
|
|
295
|
+
});
|
|
296
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFetchCustomAdv;
|
|
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 custom adv object.
|
|
17
|
+
:::
|
|
18
|
+
* @param object
|
|
19
|
+
* @param object.position
|
|
20
|
+
* @param object.categoryId
|
|
21
|
+
*/
|
|
22
|
+
function useSCFetchCustomAdv({
|
|
23
|
+
position = null,
|
|
24
|
+
categoriesId = null
|
|
25
|
+
}) {
|
|
26
|
+
const [scCustomAdv, setSCCustomAdv] = (0, _react.useState)(null);
|
|
27
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
28
|
+
const mounted = (0, _react.useRef)(false);
|
|
29
|
+
/**
|
|
30
|
+
* Memoized fetchCustomAdv
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const fetchCustomAdv = (0, _react.useMemo)(() => () => {
|
|
34
|
+
return _apiServices.http.request({
|
|
35
|
+
url: _apiServices.Endpoints.CustomAdvSearch.url(),
|
|
36
|
+
method: _apiServices.Endpoints.CustomAdvSearch.method,
|
|
37
|
+
params: Object.assign({}, position && {
|
|
38
|
+
position: position
|
|
39
|
+
}, categoriesId && {
|
|
40
|
+
categories: `[${categoriesId.toString()}]`
|
|
41
|
+
})
|
|
42
|
+
}).then(res => {
|
|
43
|
+
if (res.status >= 300) {
|
|
44
|
+
return Promise.reject(res);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return Promise.resolve(res.data.results);
|
|
48
|
+
});
|
|
49
|
+
}, [position, `${categoriesId}`]);
|
|
50
|
+
/**
|
|
51
|
+
* Track mount/unmount
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
(0, _react.useEffect)(() => {
|
|
55
|
+
mounted.current = true;
|
|
56
|
+
return () => {
|
|
57
|
+
mounted.current = false;
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
/**
|
|
61
|
+
* If id attempt to get the category by id
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
(0, _react.useEffect)(() => {
|
|
65
|
+
fetchCustomAdv().then(objects => {
|
|
66
|
+
if (mounted.current) {
|
|
67
|
+
setSCCustomAdv(objects[Math.floor(Math.random() * objects.length)]);
|
|
68
|
+
}
|
|
69
|
+
}).catch(err => {
|
|
70
|
+
if (mounted.current) {
|
|
71
|
+
setError(`Custom ADV with position ${position} not found`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, `Custom ADV with position ${position} not found`);
|
|
75
|
+
|
|
76
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, err.message);
|
|
77
|
+
});
|
|
78
|
+
}, [position, `${categoriesId}`]);
|
|
79
|
+
return {
|
|
80
|
+
scCustomAdv,
|
|
81
|
+
setSCCustomAdv,
|
|
82
|
+
error
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = useSCFetchFeedObject;
|
|
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 _types = require("@selfcommunity/types");
|
|
15
|
+
|
|
16
|
+
var _useDeepCompareEffect = require("use-deep-compare-effect");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
:::info
|
|
20
|
+
This custom hook is used to fetch a feed object.
|
|
21
|
+
:::
|
|
22
|
+
* @param object
|
|
23
|
+
* @param object.id
|
|
24
|
+
* @param object.feedObject
|
|
25
|
+
* @param object.feedObjectType
|
|
26
|
+
*/
|
|
27
|
+
function useSCFetchFeedObject({
|
|
28
|
+
id = null,
|
|
29
|
+
feedObject = null,
|
|
30
|
+
feedObjectType = _types.SCFeedObjectTypologyType.POST || _types.SCFeedObjectTypologyType.DISCUSSION || _types.SCFeedObjectTypologyType.STATUS
|
|
31
|
+
}) {
|
|
32
|
+
const [obj, setObj] = (0, _react.useState)(feedObject);
|
|
33
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
34
|
+
/**
|
|
35
|
+
* Memoized fetchFeedObject
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const fetchFeedObject = () => {
|
|
39
|
+
return _apiServices.http.request({
|
|
40
|
+
url: _apiServices.Endpoints.FeedObject.url({
|
|
41
|
+
type: feedObjectType,
|
|
42
|
+
id: id
|
|
43
|
+
}),
|
|
44
|
+
method: _apiServices.Endpoints.FeedObject.method
|
|
45
|
+
}).then(res => {
|
|
46
|
+
if (res.status >= 300) {
|
|
47
|
+
return Promise.reject(res);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return Promise.resolve(res.data);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* If id and feedObjectType resolve feddObject
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
(0, _react.useEffect)(() => {
|
|
59
|
+
if (id && feedObjectType) {
|
|
60
|
+
fetchFeedObject().then(obj => {
|
|
61
|
+
setObj(obj);
|
|
62
|
+
}).catch(err => {
|
|
63
|
+
setError(`FeedObject with id ${id} not found`);
|
|
64
|
+
|
|
65
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, `FeedObject with id ${id} not found`);
|
|
66
|
+
|
|
67
|
+
_logger.Logger.error(_Errors.SCOPE_SC_CORE, err.message);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}, [id, feedObjectType]);
|
|
71
|
+
(0, _useDeepCompareEffect.useDeepCompareEffectNoCheck)(() => {
|
|
72
|
+
setObj(feedObject);
|
|
73
|
+
}, [feedObject]);
|
|
74
|
+
return {
|
|
75
|
+
obj,
|
|
76
|
+
setObj,
|
|
77
|
+
error
|
|
78
|
+
};
|
|
79
|
+
}
|