@selfcommunity/react-core 0.5.0-live.105 → 0.5.0-live.109
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/hooks/useSCFetchEvent.js +8 -10
- package/lib/cjs/hooks/useSCGoogleApiLoader.d.ts +6 -0
- package/lib/cjs/hooks/useSCGoogleApiLoader.js +22 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +1 -1
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +36 -47
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +3 -1
- package/lib/esm/hooks/useSCFetchEvent.js +8 -10
- package/lib/esm/hooks/useSCGoogleApiLoader.d.ts +6 -0
- package/lib/esm/hooks/useSCGoogleApiLoader.js +19 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +1 -1
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +36 -47
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/umd/440.js +2 -0
- package/lib/umd/440.js.LICENSE.txt +16 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
- package/lib/umd/251.js +0 -2
- package/lib/umd/251.js.LICENSE.txt +0 -1
|
@@ -19,13 +19,13 @@ const Errors_1 = require("../constants/Errors");
|
|
|
19
19
|
* @param object.cacheStrategy
|
|
20
20
|
*/
|
|
21
21
|
function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
|
|
22
|
-
const __eventId = event ? event.id
|
|
22
|
+
const __eventId = (0, react_1.useMemo)(() => (event === null || event === void 0 ? void 0 : event.id) || id, [event, id]);
|
|
23
23
|
// CONTEXT
|
|
24
24
|
const scUserContext = (0, SCUserProvider_1.useSCUser)();
|
|
25
|
-
const authUserId = scUserContext.user ?
|
|
25
|
+
const authUserId = (0, react_1.useMemo)(() => { var _a; return ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) || null; }, [scUserContext.user]);
|
|
26
26
|
// CACHE
|
|
27
|
-
const __eventCacheKey = (0, Cache_1.getEventObjectCacheKey)(__eventId);
|
|
28
|
-
const __event = authUserId ? event : (0, utils_1.objectWithoutProperties)(event, ['subscription_status']);
|
|
27
|
+
const __eventCacheKey = (0, react_1.useMemo)(() => (0, Cache_1.getEventObjectCacheKey)(__eventId), [__eventId]);
|
|
28
|
+
const __event = (0, react_1.useMemo)(() => (authUserId ? event : (0, utils_1.objectWithoutProperties)(event, ['subscription_status'])), [authUserId, event]);
|
|
29
29
|
const [scEvent, setScEvent] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__eventCacheKey, __event) : null);
|
|
30
30
|
const [error, setError] = (0, react_1.useState)(null);
|
|
31
31
|
/**
|
|
@@ -43,15 +43,13 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
|
|
|
43
43
|
utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
|
|
44
44
|
})
|
|
45
45
|
.catch(() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
|
|
46
|
+
setScEvent(e);
|
|
47
|
+
utils_1.LRUCache.set(__eventCacheKey, e);
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
|
|
51
|
+
setScEvent(e);
|
|
52
|
+
utils_1.LRUCache.set(__eventCacheKey, e);
|
|
55
53
|
}
|
|
56
54
|
}, [autoSubscribe, authUserId, setScEvent]);
|
|
57
55
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const api_1 = require("@react-google-maps/api");
|
|
6
|
+
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
7
|
+
const SCPreferences = tslib_1.__importStar(require("../constants/Preferences"));
|
|
8
|
+
const GOOGLE_MAPS_LIBRARIES = ['places', 'geocoding', 'maps'];
|
|
9
|
+
const useSCGoogleApiLoader = () => {
|
|
10
|
+
const { preferences } = (0, SCPreferencesProvider_1.useSCPreferences)();
|
|
11
|
+
const geocodingApiKey = (0, react_1.useMemo)(() => {
|
|
12
|
+
return preferences && SCPreferences.PROVIDERS_GOOGLE_GEOCODING_API_KEY in preferences
|
|
13
|
+
? preferences[SCPreferences.PROVIDERS_GOOGLE_GEOCODING_API_KEY].value
|
|
14
|
+
: null;
|
|
15
|
+
}, [preferences]);
|
|
16
|
+
const { isLoaded, loadError } = (0, api_1.useLoadScript)({
|
|
17
|
+
googleMapsApiKey: geocodingApiKey,
|
|
18
|
+
libraries: GOOGLE_MAPS_LIBRARIES,
|
|
19
|
+
});
|
|
20
|
+
return { isLoaded, loadError, geocodingApiKey };
|
|
21
|
+
};
|
|
22
|
+
exports.default = useSCGoogleApiLoader;
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedEventsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
toggleEventAttendance: (event: SCEventType
|
|
33
|
+
toggleEventAttendance: (event: SCEventType) => Promise<any>;
|
|
34
34
|
toggleEventNonattendance: (event: SCEventType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (event?: SCEventType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -10,9 +10,9 @@ const use_deep_compare_effect_1 = require("use-deep-compare-effect");
|
|
|
10
10
|
const SCPreferencesProvider_1 = require("../components/provider/SCPreferencesProvider");
|
|
11
11
|
const Errors_1 = require("../constants/Errors");
|
|
12
12
|
const Notification_1 = require("../constants/Notification");
|
|
13
|
-
const useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
14
|
-
const event_1 = require("../utils/event");
|
|
15
13
|
const Preferences_1 = require("../constants/Preferences");
|
|
14
|
+
const event_1 = require("../utils/event");
|
|
15
|
+
const useSCCachingManager_1 = tslib_1.__importDefault(require("./useSCCachingManager"));
|
|
16
16
|
/**
|
|
17
17
|
:::info
|
|
18
18
|
This custom hook is used to manage the events followed.
|
|
@@ -115,50 +115,35 @@ function useSCSubscribedEventsManager(user) {
|
|
|
115
115
|
* Memoized toggleEventAttendance Event
|
|
116
116
|
* Toggle action
|
|
117
117
|
*/
|
|
118
|
-
const toggleEventAttendance = (0, react_1.useMemo)(() => (event
|
|
118
|
+
const toggleEventAttendance = (0, react_1.useMemo)(() => (event) => {
|
|
119
119
|
setLoading(event.id);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
127
|
-
.then((res) => {
|
|
128
|
-
if (res.status >= 300) {
|
|
129
|
-
return Promise.reject(res);
|
|
130
|
-
}
|
|
131
|
-
updateCache([event.id]);
|
|
132
|
-
setData((prev) => getDataUpdated(prev, event.id, types_1.SCEventSubscriptionStatusType.SUBSCRIBED));
|
|
133
|
-
setUnLoading(event.id);
|
|
134
|
-
return Promise.resolve(res.data);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
const requestConfig = !event.subscription_status || event.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED
|
|
120
|
+
const requestConfig = !event.subscription_status || event.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED
|
|
121
|
+
? {
|
|
122
|
+
url: api_services_1.Endpoints.SubscribeToEvent.url({ id: event.id }),
|
|
123
|
+
method: api_services_1.Endpoints.SubscribeToEvent.method,
|
|
124
|
+
}
|
|
125
|
+
: event.subscription_status === types_1.SCEventSubscriptionStatusType.GOING
|
|
139
126
|
? {
|
|
140
|
-
url: api_services_1.Endpoints.
|
|
141
|
-
method: api_services_1.Endpoints.
|
|
127
|
+
url: api_services_1.Endpoints.RemoveGoingToEvent.url({ id: event.id }),
|
|
128
|
+
method: api_services_1.Endpoints.RemoveGoingToEvent.method,
|
|
142
129
|
}
|
|
143
|
-
:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
}
|
|
130
|
+
: {
|
|
131
|
+
url: api_services_1.Endpoints.GoToEvent.url({ id: event.id }),
|
|
132
|
+
method: api_services_1.Endpoints.GoToEvent.method,
|
|
133
|
+
};
|
|
134
|
+
return api_services_1.http.request(requestConfig).then((res) => {
|
|
135
|
+
if (res.status >= 300) {
|
|
136
|
+
return Promise.reject(res);
|
|
137
|
+
}
|
|
138
|
+
let newStatus = (0, event_1.getEventStatus)(event, true);
|
|
139
|
+
if (event.subscription_status === types_1.SCEventSubscriptionStatusType.NOT_GOING) {
|
|
140
|
+
newStatus = (0, event_1.getEventStatus)(Object.assign({}, event, { subscription_status: types_1.SCEventSubscriptionStatusType.SUBSCRIBED }), true);
|
|
141
|
+
}
|
|
142
|
+
setData((prev) => getDataUpdated(prev, event.id, newStatus));
|
|
143
|
+
updateCache([event.id]);
|
|
144
|
+
setUnLoading(event.id);
|
|
145
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: newStatus }));
|
|
146
|
+
});
|
|
162
147
|
}, [data, loading, cache]);
|
|
163
148
|
/**
|
|
164
149
|
* Memoized toggleEventNonattendance Event
|
|
@@ -180,10 +165,14 @@ function useSCSubscribedEventsManager(user) {
|
|
|
180
165
|
if (res.status >= 300) {
|
|
181
166
|
return Promise.reject(res);
|
|
182
167
|
}
|
|
168
|
+
let newStatus = (0, event_1.getEventStatus)(event, false);
|
|
169
|
+
if (event.subscription_status === types_1.SCEventSubscriptionStatusType.GOING) {
|
|
170
|
+
newStatus = (0, event_1.getEventStatus)(Object.assign({}, event, { subscription_status: types_1.SCEventSubscriptionStatusType.SUBSCRIBED }), false);
|
|
171
|
+
}
|
|
172
|
+
setData((prev) => getDataUpdated(prev, event.id, newStatus));
|
|
183
173
|
updateCache([event.id]);
|
|
184
|
-
setData((prev) => getDataUpdated(prev, event.id, (0, event_1.getEventStatus)(event, false)));
|
|
185
174
|
setUnLoading(event.id);
|
|
186
|
-
return Promise.resolve(
|
|
175
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: newStatus }));
|
|
187
176
|
});
|
|
188
177
|
}
|
|
189
178
|
else {
|
|
@@ -197,7 +186,7 @@ function useSCSubscribedEventsManager(user) {
|
|
|
197
186
|
updateCache([event.id]);
|
|
198
187
|
setData((prev) => getDataUpdated(prev, event.id, null));
|
|
199
188
|
setUnLoading(event.id);
|
|
200
|
-
return Promise.resolve(
|
|
189
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: null }));
|
|
201
190
|
});
|
|
202
191
|
}
|
|
203
192
|
}, [data, loading, cache]);
|
|
@@ -285,7 +274,7 @@ function useSCSubscribedEventsManager(user) {
|
|
|
285
274
|
}
|
|
286
275
|
}
|
|
287
276
|
return null;
|
|
288
|
-
}, [loading, cache, authUserId]);
|
|
277
|
+
}, [loading, cache, authUserId, getSubscriptionStatus, getCurrentEventCacheStatus]);
|
|
289
278
|
/**
|
|
290
279
|
* Empty cache on logout
|
|
291
280
|
*/
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
|
65
65
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
66
66
|
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
67
67
|
import useSCFetchLiveStream from './hooks/useSCFetchLiveStream';
|
|
68
|
+
import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
|
|
68
69
|
/**
|
|
69
70
|
* Routing component
|
|
70
71
|
*/
|
|
@@ -87,4 +88,4 @@ import * as Preferences from './constants/Preferences';
|
|
|
87
88
|
/**
|
|
88
89
|
* List all exports
|
|
89
90
|
*/
|
|
90
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, };
|
|
91
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSCMediaClick = exports.useSCFetchIncubator = exports.useSCFetchCategories = exports.useSCFetchCategory = exports.useSCFetchAddressingTagList = exports.useSCFetchTag = exports.useSCFetchCustomAdv = exports.useSCFetchCommentObjects = exports.useSCFetchCommentObject = exports.useSCFetchFeedObject = exports.useSCFetchVote = exports.useSCFetchUserProviders = exports.useSCFetchUser = exports.Preferences = exports.Locale = exports.getEventStatus = exports.UserUtils = exports.SCCache = exports.SCRoutes = exports.Link = exports.useSCAlertMessages = exports.SCAlertMessagesContext = exports.SCAlertMessagesProvider = exports.useSCNotification = exports.SCNotificationContext = exports.SCNotificationProvider = exports.SCNotification = exports.SCFeatures = exports.SCPreferences = exports.SCPreferencesProvider = exports.withSCLocale = exports.useSCLocale = exports.SCLocaleProvider = exports.useSCRouting = exports.SCRoutingProvider = exports.getTheme = exports.withSCTheme = exports.useSCTheme = exports.SCThemeProvider = exports.useSCPreferences = exports.useSCUser = exports.SCUserProvider = exports.SCContextProvider = exports.useSCContext = exports.SCPreferencesContext = exports.SCLocaleContext = exports.SCRoutingContext = exports.SCThemeContext = exports.SCUserContext = exports.SCContext = void 0;
|
|
4
|
-
exports.useSCFetchLiveStream = exports.useSCFetchEvents = exports.useSCFetchEvent = exports.useSCFetchGroups = exports.useSCFetchGroup = exports.useSCUserIsBlocked = exports.useSCFetchUserBlockedBy = exports.useSCFetchBroadcastMessages = exports.useSCFetchPrivateMessageSnippets = exports.usePageVisibility = exports.useNoInitialEffect = exports.useEffectOnce = exports.useIsomorphicLayoutEffect = exports.usePreviousValue = exports.useIsComponentMountedRef = exports.useSCFetchFeed = exports.useSCFetchContributors = void 0;
|
|
4
|
+
exports.useSCGoogleApiLoader = exports.useSCFetchLiveStream = exports.useSCFetchEvents = exports.useSCFetchEvent = exports.useSCFetchGroups = exports.useSCFetchGroup = exports.useSCUserIsBlocked = exports.useSCFetchUserBlockedBy = exports.useSCFetchBroadcastMessages = exports.useSCFetchPrivateMessageSnippets = exports.usePageVisibility = exports.useNoInitialEffect = exports.useEffectOnce = exports.useIsomorphicLayoutEffect = exports.usePreviousValue = exports.useIsComponentMountedRef = exports.useSCFetchFeed = exports.useSCFetchContributors = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
/**
|
|
7
7
|
* ContextProvider component
|
|
@@ -120,6 +120,8 @@ const useSCFetchEvents_1 = tslib_1.__importDefault(require("./hooks/useSCFetchEv
|
|
|
120
120
|
exports.useSCFetchEvents = useSCFetchEvents_1.default;
|
|
121
121
|
const useSCFetchLiveStream_1 = tslib_1.__importDefault(require("./hooks/useSCFetchLiveStream"));
|
|
122
122
|
exports.useSCFetchLiveStream = useSCFetchLiveStream_1.default;
|
|
123
|
+
const useSCGoogleApiLoader_1 = tslib_1.__importDefault(require("./hooks/useSCGoogleApiLoader"));
|
|
124
|
+
exports.useSCGoogleApiLoader = useSCGoogleApiLoader_1.default;
|
|
123
125
|
/**
|
|
124
126
|
* Routing component
|
|
125
127
|
*/
|
|
@@ -17,13 +17,13 @@ import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
|
17
17
|
* @param object.cacheStrategy
|
|
18
18
|
*/
|
|
19
19
|
export default function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = CacheStrategies.CACHE_FIRST, }) {
|
|
20
|
-
const __eventId = event ? event.id
|
|
20
|
+
const __eventId = useMemo(() => (event === null || event === void 0 ? void 0 : event.id) || id, [event, id]);
|
|
21
21
|
// CONTEXT
|
|
22
22
|
const scUserContext = useSCUser();
|
|
23
|
-
const authUserId = scUserContext.user ?
|
|
23
|
+
const authUserId = useMemo(() => { var _a; return ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id) || null; }, [scUserContext.user]);
|
|
24
24
|
// CACHE
|
|
25
|
-
const __eventCacheKey = getEventObjectCacheKey(__eventId);
|
|
26
|
-
const __event = authUserId ? event : objectWithoutProperties(event, ['subscription_status']);
|
|
25
|
+
const __eventCacheKey = useMemo(() => getEventObjectCacheKey(__eventId), [__eventId]);
|
|
26
|
+
const __event = useMemo(() => (authUserId ? event : objectWithoutProperties(event, ['subscription_status'])), [authUserId, event]);
|
|
27
27
|
const [scEvent, setScEvent] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__eventCacheKey, __event) : null);
|
|
28
28
|
const [error, setError] = useState(null);
|
|
29
29
|
/**
|
|
@@ -41,15 +41,13 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
|
|
|
41
41
|
LRUCache.set(__eventCacheKey, updatedEvent);
|
|
42
42
|
})
|
|
43
43
|
.catch(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
LRUCache.set(__eventCacheKey, updatedEvent);
|
|
44
|
+
setScEvent(e);
|
|
45
|
+
LRUCache.set(__eventCacheKey, e);
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
LRUCache.set(__eventCacheKey, updatedEvent);
|
|
49
|
+
setScEvent(e);
|
|
50
|
+
LRUCache.set(__eventCacheKey, e);
|
|
53
51
|
}
|
|
54
52
|
}, [autoSubscribe, authUserId, setScEvent]);
|
|
55
53
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useLoadScript } from '@react-google-maps/api';
|
|
3
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
4
|
+
import * as SCPreferences from '../constants/Preferences';
|
|
5
|
+
const GOOGLE_MAPS_LIBRARIES = ['places', 'geocoding', 'maps'];
|
|
6
|
+
const useSCGoogleApiLoader = () => {
|
|
7
|
+
const { preferences } = useSCPreferences();
|
|
8
|
+
const geocodingApiKey = useMemo(() => {
|
|
9
|
+
return preferences && SCPreferences.PROVIDERS_GOOGLE_GEOCODING_API_KEY in preferences
|
|
10
|
+
? preferences[SCPreferences.PROVIDERS_GOOGLE_GEOCODING_API_KEY].value
|
|
11
|
+
: null;
|
|
12
|
+
}, [preferences]);
|
|
13
|
+
const { isLoaded, loadError } = useLoadScript({
|
|
14
|
+
googleMapsApiKey: geocodingApiKey,
|
|
15
|
+
libraries: GOOGLE_MAPS_LIBRARIES,
|
|
16
|
+
});
|
|
17
|
+
return { isLoaded, loadError, geocodingApiKey };
|
|
18
|
+
};
|
|
19
|
+
export default useSCGoogleApiLoader;
|
|
@@ -30,7 +30,7 @@ export default function useSCSubscribedEventsManager(user?: SCUserType): {
|
|
|
30
30
|
isLoading: (v: number | {
|
|
31
31
|
id: number;
|
|
32
32
|
}) => boolean;
|
|
33
|
-
toggleEventAttendance: (event: SCEventType
|
|
33
|
+
toggleEventAttendance: (event: SCEventType) => Promise<any>;
|
|
34
34
|
toggleEventNonattendance: (event: SCEventType) => Promise<any>;
|
|
35
35
|
subscriptionStatus: (event?: SCEventType) => string;
|
|
36
36
|
refresh: () => void;
|
|
@@ -7,9 +7,9 @@ import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
|
7
7
|
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
8
8
|
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
9
9
|
import { SCNotificationMapping } from '../constants/Notification';
|
|
10
|
-
import useSCCachingManager from './useSCCachingManager';
|
|
11
|
-
import { getEventStatus } from '../utils/event';
|
|
12
10
|
import { CONFIGURATIONS_EVENTS_ENABLED } from '../constants/Preferences';
|
|
11
|
+
import { getEventStatus } from '../utils/event';
|
|
12
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
13
13
|
/**
|
|
14
14
|
:::info
|
|
15
15
|
This custom hook is used to manage the events followed.
|
|
@@ -112,50 +112,35 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
112
112
|
* Memoized toggleEventAttendance Event
|
|
113
113
|
* Toggle action
|
|
114
114
|
*/
|
|
115
|
-
const toggleEventAttendance = useMemo(() => (event
|
|
115
|
+
const toggleEventAttendance = useMemo(() => (event) => {
|
|
116
116
|
setLoading(event.id);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
.then((res) => {
|
|
125
|
-
if (res.status >= 300) {
|
|
126
|
-
return Promise.reject(res);
|
|
127
|
-
}
|
|
128
|
-
updateCache([event.id]);
|
|
129
|
-
setData((prev) => getDataUpdated(prev, event.id, SCEventSubscriptionStatusType.SUBSCRIBED));
|
|
130
|
-
setUnLoading(event.id);
|
|
131
|
-
return Promise.resolve(res.data);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
const requestConfig = !event.subscription_status || event.subscription_status === SCEventSubscriptionStatusType.INVITED
|
|
117
|
+
const requestConfig = !event.subscription_status || event.subscription_status === SCEventSubscriptionStatusType.INVITED
|
|
118
|
+
? {
|
|
119
|
+
url: Endpoints.SubscribeToEvent.url({ id: event.id }),
|
|
120
|
+
method: Endpoints.SubscribeToEvent.method,
|
|
121
|
+
}
|
|
122
|
+
: event.subscription_status === SCEventSubscriptionStatusType.GOING
|
|
136
123
|
? {
|
|
137
|
-
url: Endpoints.
|
|
138
|
-
method: Endpoints.
|
|
124
|
+
url: Endpoints.RemoveGoingToEvent.url({ id: event.id }),
|
|
125
|
+
method: Endpoints.RemoveGoingToEvent.method,
|
|
139
126
|
}
|
|
140
|
-
:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
}
|
|
127
|
+
: {
|
|
128
|
+
url: Endpoints.GoToEvent.url({ id: event.id }),
|
|
129
|
+
method: Endpoints.GoToEvent.method,
|
|
130
|
+
};
|
|
131
|
+
return http.request(requestConfig).then((res) => {
|
|
132
|
+
if (res.status >= 300) {
|
|
133
|
+
return Promise.reject(res);
|
|
134
|
+
}
|
|
135
|
+
let newStatus = getEventStatus(event, true);
|
|
136
|
+
if (event.subscription_status === SCEventSubscriptionStatusType.NOT_GOING) {
|
|
137
|
+
newStatus = getEventStatus(Object.assign({}, event, { subscription_status: SCEventSubscriptionStatusType.SUBSCRIBED }), true);
|
|
138
|
+
}
|
|
139
|
+
setData((prev) => getDataUpdated(prev, event.id, newStatus));
|
|
140
|
+
updateCache([event.id]);
|
|
141
|
+
setUnLoading(event.id);
|
|
142
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: newStatus }));
|
|
143
|
+
});
|
|
159
144
|
}, [data, loading, cache]);
|
|
160
145
|
/**
|
|
161
146
|
* Memoized toggleEventNonattendance Event
|
|
@@ -177,10 +162,14 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
177
162
|
if (res.status >= 300) {
|
|
178
163
|
return Promise.reject(res);
|
|
179
164
|
}
|
|
165
|
+
let newStatus = getEventStatus(event, false);
|
|
166
|
+
if (event.subscription_status === SCEventSubscriptionStatusType.GOING) {
|
|
167
|
+
newStatus = getEventStatus(Object.assign({}, event, { subscription_status: SCEventSubscriptionStatusType.SUBSCRIBED }), false);
|
|
168
|
+
}
|
|
169
|
+
setData((prev) => getDataUpdated(prev, event.id, newStatus));
|
|
180
170
|
updateCache([event.id]);
|
|
181
|
-
setData((prev) => getDataUpdated(prev, event.id, getEventStatus(event, false)));
|
|
182
171
|
setUnLoading(event.id);
|
|
183
|
-
return Promise.resolve(
|
|
172
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: newStatus }));
|
|
184
173
|
});
|
|
185
174
|
}
|
|
186
175
|
else {
|
|
@@ -194,7 +183,7 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
194
183
|
updateCache([event.id]);
|
|
195
184
|
setData((prev) => getDataUpdated(prev, event.id, null));
|
|
196
185
|
setUnLoading(event.id);
|
|
197
|
-
return Promise.resolve(
|
|
186
|
+
return Promise.resolve(Object.assign({}, event, { subscription_status: null }));
|
|
198
187
|
});
|
|
199
188
|
}
|
|
200
189
|
}, [data, loading, cache]);
|
|
@@ -282,7 +271,7 @@ export default function useSCSubscribedEventsManager(user) {
|
|
|
282
271
|
}
|
|
283
272
|
}
|
|
284
273
|
return null;
|
|
285
|
-
}, [loading, cache, authUserId]);
|
|
274
|
+
}, [loading, cache, authUserId, getSubscriptionStatus, getCurrentEventCacheStatus]);
|
|
286
275
|
/**
|
|
287
276
|
* Empty cache on logout
|
|
288
277
|
*/
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
|
65
65
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
66
66
|
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
67
67
|
import useSCFetchLiveStream from './hooks/useSCFetchLiveStream';
|
|
68
|
+
import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
|
|
68
69
|
/**
|
|
69
70
|
* Routing component
|
|
70
71
|
*/
|
|
@@ -87,4 +88,4 @@ import * as Preferences from './constants/Preferences';
|
|
|
87
88
|
/**
|
|
88
89
|
* List all exports
|
|
89
90
|
*/
|
|
90
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, };
|
|
91
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, };
|
package/lib/esm/index.js
CHANGED
|
@@ -61,6 +61,7 @@ import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
|
61
61
|
import useSCFetchEvent from './hooks/useSCFetchEvent';
|
|
62
62
|
import useSCFetchEvents from './hooks/useSCFetchEvents';
|
|
63
63
|
import useSCFetchLiveStream from './hooks/useSCFetchLiveStream';
|
|
64
|
+
import useSCGoogleApiLoader from './hooks/useSCGoogleApiLoader';
|
|
64
65
|
/**
|
|
65
66
|
* Routing component
|
|
66
67
|
*/
|
|
@@ -83,4 +84,4 @@ import * as Preferences from './constants/Preferences';
|
|
|
83
84
|
/**
|
|
84
85
|
* List all exports
|
|
85
86
|
*/
|
|
86
|
-
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, };
|
|
87
|
+
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, getTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, getEventStatus, Locale, Preferences, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, usePageVisibility, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, useSCFetchEvents, useSCFetchLiveStream, useSCGoogleApiLoader, };
|