@selfcommunity/react-core 0.4.50-event.30 → 0.4.50-events.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js +3 -4
- package/lib/cjs/components/provider/SCContextProvider/index.js +6 -5
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +4 -6
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +18 -3
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/cjs/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/cjs/components/provider/SCUserProvider/index.js +9 -2
- package/lib/cjs/components/provider/SCVoteProvider/index.js +3 -3
- package/lib/cjs/components/router/index.js +3 -2
- package/lib/cjs/constants/Cache.d.ts +8 -0
- package/lib/cjs/constants/Cache.js +11 -2
- package/lib/cjs/constants/Routes.d.ts +1 -0
- package/lib/cjs/constants/Routes.js +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.js +18 -5
- package/lib/cjs/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchEvents.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +297 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/cjs/index.d.ts +7 -3
- package/lib/cjs/index.js +11 -3
- package/lib/cjs/types/context.d.ts +52 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/utils/event.d.ts +8 -0
- package/lib/cjs/utils/event.js +29 -0
- package/lib/cjs/utils/user.d.ts +7 -0
- package/lib/cjs/utils/user.js +11 -1
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +3 -3
- package/lib/esm/components/provider/SCContextProvider/index.js +6 -5
- package/lib/esm/components/provider/SCLocaleProvider/index.js +4 -5
- package/lib/esm/components/provider/SCNotificationProvider/index.js +3 -2
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +18 -2
- package/lib/esm/components/provider/SCRoutingProvider/index.js +3 -2
- package/lib/esm/components/provider/SCThemeProvider/index.js +4 -5
- package/lib/esm/components/provider/SCUserProvider/index.js +9 -2
- package/lib/esm/components/provider/SCVoteProvider/index.js +3 -2
- package/lib/esm/components/router/index.js +3 -2
- package/lib/esm/constants/Cache.d.ts +8 -0
- package/lib/esm/constants/Cache.js +8 -0
- package/lib/esm/constants/Routes.d.ts +1 -0
- package/lib/esm/constants/Routes.js +2 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/esm/hooks/useSCFetchEvent.js +19 -6
- package/lib/esm/hooks/useSCFetchEvents.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchEvents.js +81 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +293 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +3 -4
- package/lib/esm/index.d.ts +7 -3
- package/lib/esm/index.js +6 -2
- package/lib/esm/types/context.d.ts +52 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/utils/event.d.ts +8 -0
- package/lib/esm/utils/event.js +25 -0
- package/lib/esm/utils/user.d.ts +7 -0
- package/lib/esm/utils/user.js +9 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCAlertMessages = exports.SCAlertMessagesContext = void 0;
|
|
4
|
-
const
|
|
5
|
-
const react_1 =
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
6
|
const notistack_1 = require("notistack");
|
|
7
7
|
/**
|
|
8
8
|
* Creates Global Context
|
|
@@ -32,8 +32,7 @@ exports.SCAlertMessagesContext = (0, react_1.createContext)({});
|
|
|
32
32
|
*/
|
|
33
33
|
function SCAlertMessagesProvider({ children = null }) {
|
|
34
34
|
const [options, setOptions] = (0, react_1.useState)({ maxSnack: 3, autoHideDuration: null });
|
|
35
|
-
return (
|
|
36
|
-
react_1.default.createElement(notistack_1.SnackbarProvider, Object.assign({}, options), children)));
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(exports.SCAlertMessagesContext.Provider, Object.assign({ value: { options, setOptions } }, { children: (0, jsx_runtime_1.jsx)(notistack_1.SnackbarProvider, Object.assign({}, options, { children: children })) })));
|
|
37
36
|
}
|
|
38
37
|
exports.default = SCAlertMessagesProvider;
|
|
39
38
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCContext = exports.SCContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
6
7
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
8
|
const use_deep_compare_effect_1 = require("use-deep-compare-effect");
|
|
8
9
|
const validator_1 = require("../../../utils/validator");
|
|
@@ -83,10 +84,10 @@ function SCContextProvider({ conf, children }) {
|
|
|
83
84
|
* Nesting all necessary providers
|
|
84
85
|
* All child components will use help contexts to works
|
|
85
86
|
*/
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
return ((0, jsx_runtime_1.jsx)(exports.SCContext.Provider, Object.assign({ value: { settings } }, { children: settings &&
|
|
88
|
+
settings.contextProviders.reduceRight((memo, ContextProvider) => {
|
|
89
|
+
return (0, jsx_runtime_1.jsx)(ContextProvider, { children: memo });
|
|
90
|
+
}, children) })));
|
|
90
91
|
}
|
|
91
92
|
exports.default = SCContextProvider;
|
|
92
93
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCLocale = exports.withSCLocale = exports.SCLocaleContext = void 0;
|
|
4
|
-
const
|
|
5
|
-
const react_1 =
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
6
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
7
7
|
const locale_1 = require("../../../utils/locale");
|
|
8
8
|
const Locale_1 = require("../../../constants/Locale");
|
|
@@ -76,8 +76,7 @@ function SCLocaleProvider({ children = null }) {
|
|
|
76
76
|
}
|
|
77
77
|
throw error;
|
|
78
78
|
};
|
|
79
|
-
return (
|
|
80
|
-
react_1.default.createElement(react_intl_1.IntlProvider, { key: locale, locale: locale, messages: messages, onError: handleIntlError }, children)));
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(exports.SCLocaleContext.Provider, Object.assign({ value: { locale, messages, selectLocale } }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.IntlProvider, Object.assign({ locale: locale, messages: messages, onError: handleIntlError }, { children: children }), locale) })));
|
|
81
80
|
}
|
|
82
81
|
exports.default = SCLocaleProvider;
|
|
83
82
|
/**
|
|
@@ -86,8 +85,7 @@ exports.default = SCLocaleProvider;
|
|
|
86
85
|
*/
|
|
87
86
|
const withSCLocale = (Component) => (props) => {
|
|
88
87
|
const scLocaleContext = (0, react_1.useContext)(exports.SCLocaleContext);
|
|
89
|
-
return (
|
|
90
|
-
react_1.default.createElement(Component, Object.assign({ setLanguage: scLocaleContext.selectLocale }, props))));
|
|
88
|
+
return ((0, jsx_runtime_1.jsx)(react_intl_1.IntlProvider, Object.assign({ locale: scLocaleContext.locale, messages: scLocaleContext.messages }, { children: (0, jsx_runtime_1.jsx)(Component, Object.assign({ setLanguage: scLocaleContext.selectLocale }, props)) })));
|
|
91
89
|
};
|
|
92
90
|
exports.withSCLocale = withSCLocale;
|
|
93
91
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCNotification = exports.SCNotificationContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
6
7
|
const useSCWebSocket_1 = tslib_1.__importDefault(require("../../../hooks/useSCWebSocket"));
|
|
7
8
|
const useSCWebPushMessaging_1 = tslib_1.__importDefault(require("../../../hooks/useSCWebPushMessaging"));
|
|
8
9
|
const useSCMobileNativePushMessaging_1 = tslib_1.__importDefault(require("../../../hooks/useSCMobileNativePushMessaging"));
|
|
@@ -36,7 +37,7 @@ function SCNotificationProvider({ children = null }) {
|
|
|
36
37
|
const { wsInstance } = (0, useSCWebSocket_1.default)();
|
|
37
38
|
const { wpSubscription } = (0, useSCWebPushMessaging_1.default)();
|
|
38
39
|
const { mnpmInstance } = (0, useSCMobileNativePushMessaging_1.default)();
|
|
39
|
-
return
|
|
40
|
+
return (0, jsx_runtime_1.jsx)(exports.SCNotificationContext.Provider, Object.assign({ value: { wsInstance, wpSubscription, mnpmInstance } }, { children: children }));
|
|
40
41
|
}
|
|
41
42
|
exports.default = SCNotificationProvider;
|
|
42
43
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCPreferences = exports.SCPreferencesContext = void 0;
|
|
4
|
-
const
|
|
5
|
-
const react_1 = tslib_1.__importStar(require("react"));
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
5
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
6
|
const utils_1 = require("@selfcommunity/utils");
|
|
7
|
+
const react_1 = require("react");
|
|
8
8
|
const Errors_1 = require("../../../constants/Errors");
|
|
9
9
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
10
10
|
/**
|
|
@@ -54,13 +54,28 @@ function SCPreferencesProvider({ children = null }) {
|
|
|
54
54
|
.catch((_error) => {
|
|
55
55
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, _error);
|
|
56
56
|
setError(_error);
|
|
57
|
+
// setLoading(false);
|
|
57
58
|
});
|
|
58
59
|
}, []);
|
|
60
|
+
/**
|
|
61
|
+
* Force refresh of preferences & features
|
|
62
|
+
*/
|
|
63
|
+
const refresh = () => {
|
|
64
|
+
Promise.all([api_services_1.PreferenceService.getAllPreferences(), api_services_1.FeatureService.getAllFeatures()])
|
|
65
|
+
.then(function ([preferences, features]) {
|
|
66
|
+
setPreferences(preferences['results'].reduce((obj, p) => (Object.assign(Object.assign({}, obj), { [`${p.section}.${p.name}`]: p })), {}));
|
|
67
|
+
setFeatures(features['results'].filter((f) => f.enabled).map((f) => f.name));
|
|
68
|
+
})
|
|
69
|
+
.catch((_error) => {
|
|
70
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, _error);
|
|
71
|
+
setError(_error);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
59
74
|
/**
|
|
60
75
|
* Nesting all necessary providers
|
|
61
76
|
* All child components will use help contexts to works
|
|
62
77
|
*/
|
|
63
|
-
return
|
|
78
|
+
return ((0, jsx_runtime_1.jsx)(exports.SCPreferencesContext.Provider, Object.assign({ value: { preferences, features, setPreferences, setFeatures, refresh } }, { children: !loading && children })));
|
|
64
79
|
}
|
|
65
80
|
exports.default = SCPreferencesProvider;
|
|
66
81
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCRouting = exports.SCRoutingContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
6
7
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
7
8
|
const SCPreferencesProvider_1 = require("../SCPreferencesProvider");
|
|
8
9
|
const SCPreferences = tslib_1.__importStar(require("../../../constants/Preferences"));
|
|
@@ -104,7 +105,7 @@ function SCRoutingProvider({ children = null }) {
|
|
|
104
105
|
routes,
|
|
105
106
|
url,
|
|
106
107
|
}), [routerLink, routes]);
|
|
107
|
-
return
|
|
108
|
+
return (0, jsx_runtime_1.jsx)(exports.SCRoutingContext.Provider, Object.assign({ value: contextValue }, { children: children }));
|
|
108
109
|
}
|
|
109
110
|
exports.default = SCRoutingProvider;
|
|
110
111
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCTheme = exports.withSCTheme = exports.SCThemeContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
6
7
|
const ThemeProvider_1 = tslib_1.__importDefault(require("@mui/material/styles/ThemeProvider"));
|
|
7
8
|
const theme_1 = tslib_1.__importDefault(require("../../../themes/theme"));
|
|
8
9
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
@@ -59,8 +60,7 @@ function SCThemeProvider({ children = null }) {
|
|
|
59
60
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
60
61
|
setCustomTheme(theme);
|
|
61
62
|
}, [scContext.settings.theme]);
|
|
62
|
-
return (
|
|
63
|
-
react_1.default.createElement(ThemeProvider_1.default, { theme: theme }, children)));
|
|
63
|
+
return ((0, jsx_runtime_1.jsx)(exports.SCThemeContext.Provider, Object.assign({ value: { theme, setTheme: setCustomTheme } }, { children: (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, Object.assign({ theme: theme }, { children: children })) })));
|
|
64
64
|
}
|
|
65
65
|
exports.default = SCThemeProvider;
|
|
66
66
|
/**
|
|
@@ -69,8 +69,7 @@ exports.default = SCThemeProvider;
|
|
|
69
69
|
*/
|
|
70
70
|
const withSCTheme = (Component) => (props) => {
|
|
71
71
|
const scThemeContext = (0, react_1.useContext)(exports.SCThemeContext);
|
|
72
|
-
return (
|
|
73
|
-
react_1.default.createElement(Component, Object.assign({ setTheme: scThemeContext.setTheme }, props))));
|
|
72
|
+
return ((0, jsx_runtime_1.jsx)(ThemeProvider_1.default, Object.assign({ theme: scThemeContext.theme }, { children: (0, jsx_runtime_1.jsx)(Component, Object.assign({ setTheme: scThemeContext.setTheme }, props)) })));
|
|
74
73
|
};
|
|
75
74
|
exports.withSCTheme = withSCTheme;
|
|
76
75
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCUser = exports.SCUserContext = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
6
7
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
8
|
const SCContextProvider_1 = require("../SCContextProvider");
|
|
8
9
|
const useSCAuth_1 = tslib_1.__importStar(require("../../../hooks/useSCAuth"));
|
|
@@ -20,6 +21,7 @@ const useSCSubscribedIncubatorsManager_1 = tslib_1.__importDefault(require("../.
|
|
|
20
21
|
const useSCBlockedUsersManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCBlockedUsersManager"));
|
|
21
22
|
const Session = tslib_1.__importStar(require("../../../constants/Session"));
|
|
22
23
|
const useSCSubscribedGroupsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedGroupsManager"));
|
|
24
|
+
const useSCSubscribedEventsManager_1 = tslib_1.__importDefault(require("../../../hooks/useSCSubscribedEventsManager"));
|
|
23
25
|
/**
|
|
24
26
|
* SCUserContext (Authentication Context)
|
|
25
27
|
*
|
|
@@ -72,6 +74,7 @@ function SCUserProvider({ children }) {
|
|
|
72
74
|
const categoriesManager = (0, useSCFollowedCategoriesManager_1.default)(state.user, updateUser);
|
|
73
75
|
const blockedUsersManager = (0, useSCBlockedUsersManager_1.default)(state.user);
|
|
74
76
|
const subscribedGroupsManager = (0, useSCSubscribedGroupsManager_1.default)(state.user);
|
|
77
|
+
const subscribedEventsManager = (0, useSCSubscribedEventsManager_1.default)(state.user);
|
|
75
78
|
/**
|
|
76
79
|
* Ref notifications subscribers: BLOCKED_USER, UNBLOCKED_USER
|
|
77
80
|
*/
|
|
@@ -123,6 +126,7 @@ function SCUserProvider({ children }) {
|
|
|
123
126
|
subscribedIncubatorsManager.refresh && subscribedIncubatorsManager.refresh();
|
|
124
127
|
blockedUsersManager.refresh && blockedUsersManager.refresh();
|
|
125
128
|
subscribedGroupsManager.refresh && subscribedGroupsManager.refresh();
|
|
129
|
+
subscribedEventsManager.refresh && subscribedEventsManager.refresh();
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
@@ -219,6 +223,7 @@ function SCUserProvider({ children }) {
|
|
|
219
223
|
incubators: subscribedIncubatorsManager,
|
|
220
224
|
blockedUsers: blockedUsersManager,
|
|
221
225
|
groups: subscribedGroupsManager,
|
|
226
|
+
events: subscribedEventsManager,
|
|
222
227
|
},
|
|
223
228
|
}), [
|
|
224
229
|
state,
|
|
@@ -237,12 +242,14 @@ function SCUserProvider({ children }) {
|
|
|
237
242
|
subscribedIncubatorsManager.incubators,
|
|
238
243
|
subscribedGroupsManager.loading,
|
|
239
244
|
subscribedGroupsManager.groups,
|
|
245
|
+
subscribedEventsManager.loading,
|
|
246
|
+
subscribedEventsManager.events,
|
|
240
247
|
]);
|
|
241
248
|
/**
|
|
242
249
|
* We only want to render the underlying app after we
|
|
243
250
|
* assert for the presence of a current user.
|
|
244
251
|
*/
|
|
245
|
-
return
|
|
252
|
+
return (0, jsx_runtime_1.jsx)(exports.SCUserContext.Provider, Object.assign({ value: contextValue }, { children: children }));
|
|
246
253
|
}
|
|
247
254
|
exports.default = SCUserProvider;
|
|
248
255
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCVote = exports.SCVoteContext = void 0;
|
|
4
|
-
const
|
|
5
|
-
const react_1 =
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
6
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
7
|
const utils_1 = require("@selfcommunity/utils");
|
|
8
8
|
const Errors_1 = require("../../../constants/Errors");
|
|
@@ -82,7 +82,7 @@ function SCVoteProvider({ children = null }) {
|
|
|
82
82
|
* Nesting all necessary providers
|
|
83
83
|
* All child components will use help contexts to works
|
|
84
84
|
*/
|
|
85
|
-
return
|
|
85
|
+
return (0, jsx_runtime_1.jsx)(exports.SCVoteContext.Provider, Object.assign({ value: { reactions, isLoading, refreshReactions } }, { children: initialized && children }));
|
|
86
86
|
}
|
|
87
87
|
exports.default = SCVoteProvider;
|
|
88
88
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
6
|
const SCRoutingProvider_1 = require("../provider/SCRoutingProvider");
|
|
6
7
|
/**
|
|
@@ -21,10 +22,10 @@ const Link = (_a, ref) => {
|
|
|
21
22
|
const scRoutingContext = (0, react_1.useContext)(SCRoutingProvider_1.SCRoutingContext);
|
|
22
23
|
if (scRoutingContext.routerLink) {
|
|
23
24
|
const ComponentLink = scRoutingContext.routerLink;
|
|
24
|
-
return (
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(ComponentLink, Object.assign({}, other, { ref: ref }, { children: children })));
|
|
25
26
|
}
|
|
26
27
|
const { to } = other, rest = tslib_1.__rest(other, ["to"]);
|
|
27
|
-
return (
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: to }, rest, { ref: ref }, { children: children })));
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
30
31
|
:::info
|
|
@@ -20,6 +20,9 @@ export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
|
20
20
|
/** EVENT OBJECT **/
|
|
21
21
|
export declare const EVENT_OBJECT_CACHE_PREFIX_KEY = "_evt_";
|
|
22
22
|
export declare const getEventObjectCacheKey: (id: any) => string;
|
|
23
|
+
/** EVENTS OBJECT **/
|
|
24
|
+
export declare const EVENTS_OBJECT_CACHE_PREFIX_KEY = "_evts_";
|
|
25
|
+
export declare const getEventsObjectCacheKey: () => string;
|
|
23
26
|
/** GROUP OBJECT **/
|
|
24
27
|
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
25
28
|
export declare const getGroupObjectCacheKey: (id: any) => string;
|
|
@@ -61,6 +64,11 @@ export declare const CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_cSug
|
|
|
61
64
|
export declare const CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = "_cPopWidget_";
|
|
62
65
|
export declare const USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFolWidget_";
|
|
63
66
|
export declare const USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = "_uFoldWidget_";
|
|
67
|
+
export declare const USER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uEvents_";
|
|
68
|
+
export declare const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uOtherEvents_";
|
|
69
|
+
export declare const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uPartecipantsEvents_";
|
|
70
|
+
export declare const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = "_uInvitedEvents_";
|
|
71
|
+
export declare const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uRequestsEvents_";
|
|
64
72
|
export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
|
|
65
73
|
export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
|
|
66
74
|
export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Cache prefixes
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
6
|
+
exports.USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.getPmSnippetObjectCacheKey = exports.PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY = exports.getPmSnippetsObjectCacheKey = exports.PM_SNIPPETS_OBJECT_CACHE_PREFIX_KEY = exports.getAdvObjectCacheKey = exports.ADV_OBJECT_CACHE_PREFIX_KEY = exports.getFeedSPCacheKey = exports.FEED_CACHE_SP_KEY = exports.getVirtualizedScrollStateCacheKey = exports.VIRTUALIZED_SCROLL_STATE_CACHE_PREFIX_KEY = exports.getStateFeedCacheKey = exports.FEED_STATE_CACHE_PREFIX_KEY = exports.getFeedCacheKey = exports.FEED_CACHE_PREFIX_KEY = exports.getBroadcastMessagesObjectCacheKey = exports.BROADCAST_MESSAGES_OBJECT_CACHE_PREFIX_KEY = exports.getContributorsCachePrefixKeys = exports.getContributorsCacheKey = exports.CONTRIBUTORS_CACHE_PREFIX_KEY = exports.getIncubatorObjectCacheKey = exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = exports.getGroupsObjectCacheKey = exports.GROUPS_OBJECT_CACHE_PREFIX_KEY = exports.getGroupObjectCacheKey = exports.GROUP_OBJECT_CACHE_PREFIX_KEY = exports.getEventsObjectCacheKey = exports.EVENTS_OBJECT_CACHE_PREFIX_KEY = exports.getEventObjectCacheKey = exports.EVENT_OBJECT_CACHE_PREFIX_KEY = exports.getCategoryObjectCacheKey = exports.CATEGORY_OBJECT_CACHE_PREFIX_KEY = exports.getCategoriesObjectCacheKey = exports.CATEGORIES_OBJECT_CACHE_PREFIX_KEY = exports.getCommentObjectsCachePrefixKeys = exports.getCommentObjectsCacheKey = exports.COMMENT_OBJECTS_CACHE_PREFIX_KEY = exports.getCommentObjectCacheKey = exports.COMMENT_OBJECT_CACHE_PREFIX_KEY = exports.getFeedObjectCacheKey = exports.FEED_OBJECT_CACHE_PREFIX_KEY = void 0;
|
|
7
|
+
exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_PEOPLE_TOOLS_STATE_CACHE_PREFIX_KEY = exports.RELATED_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = void 0;
|
|
8
8
|
/** FEED OBJECT **/
|
|
9
9
|
exports.FEED_OBJECT_CACHE_PREFIX_KEY = '_fo_';
|
|
10
10
|
const getFeedObjectCacheKey = (id, type) => `${exports.FEED_OBJECT_CACHE_PREFIX_KEY}${type}_${id}`;
|
|
@@ -31,6 +31,10 @@ exports.getCategoryObjectCacheKey = getCategoryObjectCacheKey;
|
|
|
31
31
|
exports.EVENT_OBJECT_CACHE_PREFIX_KEY = '_evt_';
|
|
32
32
|
const getEventObjectCacheKey = (id) => `${exports.EVENT_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
33
33
|
exports.getEventObjectCacheKey = getEventObjectCacheKey;
|
|
34
|
+
/** EVENTS OBJECT **/
|
|
35
|
+
exports.EVENTS_OBJECT_CACHE_PREFIX_KEY = '_evts_';
|
|
36
|
+
const getEventsObjectCacheKey = () => `${exports.EVENTS_OBJECT_CACHE_PREFIX_KEY}`;
|
|
37
|
+
exports.getEventsObjectCacheKey = getEventsObjectCacheKey;
|
|
34
38
|
/** GROUP OBJECT **/
|
|
35
39
|
exports.GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
36
40
|
const getGroupObjectCacheKey = (id) => `${exports.GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -89,6 +93,11 @@ exports.CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_cSugWidget_';
|
|
|
89
93
|
exports.CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = '_cPopWidget_';
|
|
90
94
|
exports.USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFolWidget_';
|
|
91
95
|
exports.USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = '_uFoldWidget_';
|
|
96
|
+
exports.USER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uEvents_';
|
|
97
|
+
exports.USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uOtherEvents_';
|
|
98
|
+
exports.USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uPartecipantsEvents_';
|
|
99
|
+
exports.USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = '_uInvitedEvents_';
|
|
100
|
+
exports.USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uRequestsEvents_';
|
|
92
101
|
exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
|
|
93
102
|
exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
|
|
94
103
|
exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
|
|
@@ -38,6 +38,7 @@ export declare const GROUPS_ROUTE_NAME = "groups";
|
|
|
38
38
|
export declare const GROUPS_SUBSCRIBED_ROUTE_NAME = "groups_subscribed";
|
|
39
39
|
export declare const EVENT_ROUTE_NAME = "event";
|
|
40
40
|
export declare const EVENTS_ROUTE_NAME = "events";
|
|
41
|
+
export declare const EVENTS_SUGGESTED_ROUTE_NAME = "events_suggested";
|
|
41
42
|
export declare const EVENTS_SUBSCRIBED_ROUTE_NAME = "events_subscribed";
|
|
42
43
|
export declare const EVENTS_HIGHLIGHT_ROUTE_NAME = "events_highlight";
|
|
43
44
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultRoutes = exports.EVENTS_HIGHLIGHT_ROUTE_NAME = exports.EVENTS_SUBSCRIBED_ROUTE_NAME = exports.EVENTS_ROUTE_NAME = exports.EVENT_ROUTE_NAME = exports.GROUPS_SUBSCRIBED_ROUTE_NAME = exports.GROUPS_ROUTE_NAME = exports.GROUP_MESSAGES_ROUTE_NAME = exports.GROUP_MEMBERS_ROUTE_NAME = exports.GROUP_ROUTE_NAME = exports.LEGAL_PAGES_ROUTE_NAME = exports.CUSTOM_PAGES_ROUTE_NAME = exports.RECOVER_ROUTE_NAME = exports.SIGNUP_ROUTE_NAME = exports.SIGNIN_ROUTE_NAME = exports.INCUBATOR_ROUTE_NAME = exports.LOYALTY_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = exports.USER_PROFILE_CATEGORIES_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWERS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWINGS_ROUTE_NAME = exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = exports.USER_NOTIFICATIONS_ROUTE_NAME = exports.USER_PROFILE_SETTINGS_ROUTE_NAME = exports.USER_PROFILE_ROUTE_NAME = exports.CATEGORIES_LIST_ROUTE_NAME = exports.CATEGORY_TRENDING_FEED_ROUTE_NAME = exports.CATEGORY_ROUTE_NAME = exports.COMMENT_ROUTE_NAME = exports.STATUS_ROUTE_NAME = exports.DISCUSSION_ROUTE_NAME = exports.POST_ROUTE_NAME = exports.EXPLORE_ROUTE_NAME = exports.HOME_ROUTE_NAME = exports.ROUTER_OPTION = exports.PORTAL_OPTION = void 0;
|
|
3
|
+
exports.defaultRoutes = exports.EVENTS_HIGHLIGHT_ROUTE_NAME = exports.EVENTS_SUBSCRIBED_ROUTE_NAME = exports.EVENTS_SUGGESTED_ROUTE_NAME = exports.EVENTS_ROUTE_NAME = exports.EVENT_ROUTE_NAME = exports.GROUPS_SUBSCRIBED_ROUTE_NAME = exports.GROUPS_ROUTE_NAME = exports.GROUP_MESSAGES_ROUTE_NAME = exports.GROUP_MEMBERS_ROUTE_NAME = exports.GROUP_ROUTE_NAME = exports.LEGAL_PAGES_ROUTE_NAME = exports.CUSTOM_PAGES_ROUTE_NAME = exports.RECOVER_ROUTE_NAME = exports.SIGNUP_ROUTE_NAME = exports.SIGNIN_ROUTE_NAME = exports.INCUBATOR_ROUTE_NAME = exports.LOYALTY_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_DISCUSSIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWED_POSTS_ROUTE_NAME = exports.USER_PROFILE_CATEGORIES_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_SENT_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_REQUESTS_ROUTE_NAME = exports.USER_PROFILE_CONNECTIONS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWERS_ROUTE_NAME = exports.USER_PROFILE_FOLLOWINGS_ROUTE_NAME = exports.USER_PRIVATE_MESSAGES_ROUTE_NAME = exports.USER_NOTIFICATIONS_ROUTE_NAME = exports.USER_PROFILE_SETTINGS_ROUTE_NAME = exports.USER_PROFILE_ROUTE_NAME = exports.CATEGORIES_LIST_ROUTE_NAME = exports.CATEGORY_TRENDING_FEED_ROUTE_NAME = exports.CATEGORY_ROUTE_NAME = exports.COMMENT_ROUTE_NAME = exports.STATUS_ROUTE_NAME = exports.DISCUSSION_ROUTE_NAME = exports.POST_ROUTE_NAME = exports.EXPLORE_ROUTE_NAME = exports.HOME_ROUTE_NAME = exports.ROUTER_OPTION = exports.PORTAL_OPTION = void 0;
|
|
4
4
|
exports.PORTAL_OPTION = 'portal';
|
|
5
5
|
exports.ROUTER_OPTION = 'router';
|
|
6
6
|
/**
|
|
@@ -41,6 +41,7 @@ exports.GROUPS_ROUTE_NAME = 'groups';
|
|
|
41
41
|
exports.GROUPS_SUBSCRIBED_ROUTE_NAME = 'groups_subscribed';
|
|
42
42
|
exports.EVENT_ROUTE_NAME = 'event';
|
|
43
43
|
exports.EVENTS_ROUTE_NAME = 'events';
|
|
44
|
+
exports.EVENTS_SUGGESTED_ROUTE_NAME = 'events_suggested';
|
|
44
45
|
exports.EVENTS_SUBSCRIBED_ROUTE_NAME = 'events_subscribed';
|
|
45
46
|
exports.EVENTS_HIGHLIGHT_ROUTE_NAME = 'events_highlight';
|
|
46
47
|
/**
|
|
@@ -82,6 +83,7 @@ exports.defaultRoutes = {
|
|
|
82
83
|
[exports.GROUPS_ROUTE_NAME]: '/groups/',
|
|
83
84
|
[exports.GROUPS_SUBSCRIBED_ROUTE_NAME]: '/groups/subscribed/',
|
|
84
85
|
[exports.EVENTS_ROUTE_NAME]: '/events/',
|
|
86
|
+
[exports.EVENTS_SUGGESTED_ROUTE_NAME]: '/events/suggested',
|
|
85
87
|
[exports.EVENT_ROUTE_NAME]: '/event/:id/:slug/',
|
|
86
88
|
[exports.EVENTS_SUBSCRIBED_ROUTE_NAME]: '/events/subscribed/',
|
|
87
89
|
[exports.EVENTS_HIGHLIGHT_ROUTE_NAME]: '/events/highlight/',
|
|
@@ -7,11 +7,13 @@ import { CacheStrategies } from '@selfcommunity/utils';
|
|
|
7
7
|
* @param object
|
|
8
8
|
* @param object.id
|
|
9
9
|
* @param object.event
|
|
10
|
+
* @param object.autosubscribe
|
|
10
11
|
* @param object.cacheStrategy
|
|
11
12
|
*/
|
|
12
|
-
export default function useSCFetchEvent({ id, event, cacheStrategy, }: {
|
|
13
|
+
export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrategy, }: {
|
|
13
14
|
id?: number | string;
|
|
14
15
|
event?: SCEventType;
|
|
16
|
+
autoSubscribe?: boolean;
|
|
15
17
|
cacheStrategy?: CacheStrategies;
|
|
16
18
|
}): {
|
|
17
19
|
scEvent: SCEventType;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const Errors_1 = require("../constants/Errors");
|
|
5
|
+
const types_1 = require("@selfcommunity/types");
|
|
5
6
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
6
7
|
const utils_1 = require("@selfcommunity/utils");
|
|
7
8
|
const Cache_1 = require("../constants/Cache");
|
|
@@ -14,9 +15,10 @@ const SCUserProvider_1 = require("../components/provider/SCUserProvider");
|
|
|
14
15
|
* @param object
|
|
15
16
|
* @param object.id
|
|
16
17
|
* @param object.event
|
|
18
|
+
* @param object.autosubscribe
|
|
17
19
|
* @param object.cacheStrategy
|
|
18
20
|
*/
|
|
19
|
-
function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
21
|
+
function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
20
22
|
const __eventId = event ? event.id : id;
|
|
21
23
|
// CONTEXT
|
|
22
24
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
@@ -51,10 +53,21 @@ function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.Cach
|
|
|
51
53
|
* If id attempt to get the event by id
|
|
52
54
|
*/
|
|
53
55
|
(0, react_1.useEffect)(() => {
|
|
54
|
-
if (__eventId && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
|
|
56
|
+
if (__eventId && scUserContext.user !== undefined && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
|
|
55
57
|
fetchEvent()
|
|
56
|
-
.then((
|
|
57
|
-
|
|
58
|
+
.then((event) => {
|
|
59
|
+
if (autoSubscribe &&
|
|
60
|
+
authUserId !== null &&
|
|
61
|
+
((event.privacy === types_1.SCEventPrivacyType.PUBLIC && !event.subscription_status) ||
|
|
62
|
+
(event.privacy === types_1.SCEventPrivacyType.PRIVATE && event.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED))) {
|
|
63
|
+
// Auto subscribe to the event
|
|
64
|
+
api_services_1.EventService.subscribeToEvent(event.id).then(() => {
|
|
65
|
+
setSCEvent(event);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
setSCEvent(event);
|
|
70
|
+
}
|
|
58
71
|
})
|
|
59
72
|
.catch((err) => {
|
|
60
73
|
utils_1.LRUCache.delete(__eventCacheKey);
|
|
@@ -63,7 +76,7 @@ function useSCFetchEvent({ id = null, event = null, cacheStrategy = utils_1.Cach
|
|
|
63
76
|
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
64
77
|
});
|
|
65
78
|
}
|
|
66
|
-
}, [__eventId, authUserId]);
|
|
79
|
+
}, [__eventId, authUserId, scUserContext.user]);
|
|
67
80
|
(0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
|
|
68
81
|
if (event) {
|
|
69
82
|
setSCEvent(event);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SCEventType } from '@selfcommunity/types';
|
|
2
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
3
|
+
/**
|
|
4
|
+
:::info
|
|
5
|
+
This custom hook is used to fetch events.
|
|
6
|
+
@param object.cacheStrategy
|
|
7
|
+
|
|
8
|
+
:::tip Context can be consumed in this way:
|
|
9
|
+
|
|
10
|
+
```jsx
|
|
11
|
+
const {events, isLoading} = useSCFetchEvents();
|
|
12
|
+
```
|
|
13
|
+
:::
|
|
14
|
+
* @param props
|
|
15
|
+
*/
|
|
16
|
+
declare const useSCFetchEvents: (props?: {
|
|
17
|
+
cacheStrategy?: CacheStrategies;
|
|
18
|
+
}) => {
|
|
19
|
+
events: SCEventType[];
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
};
|
|
22
|
+
export default useSCFetchEvents;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const Errors_1 = require("../constants/Errors");
|
|
6
|
+
const api_services_1 = require("@selfcommunity/api-services");
|
|
7
|
+
const utils_1 = require("@selfcommunity/utils");
|
|
8
|
+
const Cache_1 = require("../constants/Cache");
|
|
9
|
+
const init = { events: [], isLoading: true };
|
|
10
|
+
// HYDRATE the cache
|
|
11
|
+
const hydrate = (ids) => {
|
|
12
|
+
if (!ids) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const events = ids.map((id) => {
|
|
16
|
+
const __eventCacheKey = (0, Cache_1.getEventObjectCacheKey)(id);
|
|
17
|
+
return utils_1.LRUCache.get(__eventCacheKey);
|
|
18
|
+
});
|
|
19
|
+
if (events.filter((c) => !c).length > 0) {
|
|
20
|
+
// REVALIDATE CACHE
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return events;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
:::info
|
|
27
|
+
This custom hook is used to fetch events.
|
|
28
|
+
@param object.cacheStrategy
|
|
29
|
+
|
|
30
|
+
:::tip Context can be consumed in this way:
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
const {events, isLoading} = useSCFetchEvents();
|
|
34
|
+
```
|
|
35
|
+
:::
|
|
36
|
+
* @param props
|
|
37
|
+
*/
|
|
38
|
+
const useSCFetchEvents = (props) => {
|
|
39
|
+
// PROPS
|
|
40
|
+
const { cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST } = props || {};
|
|
41
|
+
// CACHE
|
|
42
|
+
const __eventsCacheKey = (0, Cache_1.getEventsObjectCacheKey)();
|
|
43
|
+
// STATE
|
|
44
|
+
const events = cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? hydrate(utils_1.LRUCache.get(__eventsCacheKey, null)) : null;
|
|
45
|
+
const [data, setData] = (0, react_1.useState)(events !== null ? { events, isLoading: false } : init);
|
|
46
|
+
/**
|
|
47
|
+
* Fetch events
|
|
48
|
+
*/
|
|
49
|
+
const fetchEvents = (next = api_services_1.Endpoints.GetUserEvents.url()) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const response = yield api_services_1.http.request({
|
|
51
|
+
url: next,
|
|
52
|
+
method: api_services_1.Endpoints.GetUserEvents.method,
|
|
53
|
+
});
|
|
54
|
+
const data = response.data;
|
|
55
|
+
if (data.next) {
|
|
56
|
+
return data.results.concat(yield fetchEvents(data.next));
|
|
57
|
+
}
|
|
58
|
+
return data.results;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Get events
|
|
62
|
+
*/
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (cacheStrategy === utils_1.CacheStrategies.CACHE_FIRST && events) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
fetchEvents()
|
|
68
|
+
.then((data) => {
|
|
69
|
+
setData({ events: data, isLoading: false });
|
|
70
|
+
utils_1.LRUCache.set(__eventsCacheKey, data.map((event) => {
|
|
71
|
+
const __eventCacheKey = (0, Cache_1.getEventObjectCacheKey)(event.id);
|
|
72
|
+
utils_1.LRUCache.set(__eventCacheKey, event);
|
|
73
|
+
return event.id;
|
|
74
|
+
}));
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
console.log(error);
|
|
78
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to retrieve events');
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
return data;
|
|
82
|
+
};
|
|
83
|
+
exports.default = useSCFetchEvents;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SCEventType, SCUserType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to manage the events followed.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
:::tip How to use it:
|
|
8
|
+
Follow these steps:
|
|
9
|
+
```jsx
|
|
10
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
11
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
12
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
*/
|
|
16
|
+
export default function useSCSubscribedEventsManager(user?: SCUserType): {
|
|
17
|
+
events: any[];
|
|
18
|
+
loading: any[];
|
|
19
|
+
isLoading: (v: number | {
|
|
20
|
+
id: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
toggleEventAttendance?: undefined;
|
|
23
|
+
toggleEventNonattendance?: undefined;
|
|
24
|
+
subscriptionStatus?: undefined;
|
|
25
|
+
refresh?: undefined;
|
|
26
|
+
emptyCache?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
events: any[];
|
|
29
|
+
loading: any[];
|
|
30
|
+
isLoading: (v: number | {
|
|
31
|
+
id: number;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
toggleEventAttendance: (event: SCEventType, userId?: number) => Promise<any>;
|
|
34
|
+
toggleEventNonattendance: (event: SCEventType) => Promise<any>;
|
|
35
|
+
subscriptionStatus: (event?: SCEventType) => string;
|
|
36
|
+
refresh: () => void;
|
|
37
|
+
emptyCache: () => void;
|
|
38
|
+
};
|