@selfcommunity/react-core 0.4.50-events.34 → 0.4.50-events.39
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/SCUserProvider/index.js +6 -0
- package/lib/cjs/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/cjs/hooks/useSCFetchEvent.js +15 -5
- package/lib/cjs/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedEventsManager.js +283 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/types/context.d.ts +40 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/esm/components/provider/SCUserProvider/index.js +6 -0
- package/lib/esm/hooks/useSCFetchEvent.d.ts +3 -1
- package/lib/esm/hooks/useSCFetchEvent.js +16 -6
- package/lib/esm/hooks/useSCSubscribedEventsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedEventsManager.js +279 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/types/context.d.ts +40 -1
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/umd/react-core.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
3
|
+
import { SCEventPrivacyType, SCEventSubscriptionStatusType, SCFeatureName, SCNotificationTopicType, SCNotificationTypologyType, } from '@selfcommunity/types';
|
|
4
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
5
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
6
|
+
import { Logger } from '@selfcommunity/utils';
|
|
7
|
+
import { useSCPreferences } from '../components/provider/SCPreferencesProvider';
|
|
8
|
+
import { SCNotificationMapping } from '../constants/Notification';
|
|
9
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
10
|
+
import PubSub from 'pubsub-js';
|
|
11
|
+
/**
|
|
12
|
+
:::info
|
|
13
|
+
This custom hook is used to manage the events followed.
|
|
14
|
+
:::
|
|
15
|
+
|
|
16
|
+
:::tip How to use it:
|
|
17
|
+
Follow these steps:
|
|
18
|
+
```jsx
|
|
19
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
20
|
+
2. const scSubscribedEventsManager: SCSubscribedEventsManagerType = scUserContext.manager.events;
|
|
21
|
+
3. scSubscribedEventsManager.isSubscribed(event)
|
|
22
|
+
```
|
|
23
|
+
:::
|
|
24
|
+
*/
|
|
25
|
+
export default function useSCSubscribedEventsManager(user) {
|
|
26
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
27
|
+
const { features } = useSCPreferences();
|
|
28
|
+
const authUserId = user ? user.id : null;
|
|
29
|
+
const eventsEnabled = useMemo(() => features && features.includes(SCFeatureName.EVENT) && features.includes(SCFeatureName.TAGGING), [features]);
|
|
30
|
+
const notificationInvitedToJoinEvent = useRef(null);
|
|
31
|
+
const notificationRequestedToJoinEvent = useRef(null);
|
|
32
|
+
const notificationAcceptedToJoinEvent = useRef(null);
|
|
33
|
+
const notificationAddedToEvent = useRef(null);
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to notification types user_follow, user_unfollow
|
|
36
|
+
*/
|
|
37
|
+
useDeepCompareEffectNoCheck(() => {
|
|
38
|
+
notificationInvitedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
39
|
+
notificationRequestedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
40
|
+
notificationAcceptedToJoinEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT}`, notificationSubscriber);
|
|
41
|
+
notificationAddedToEvent.current = PubSub.subscribe(`${SCNotificationTopicType.INTERACTION}.${SCNotificationTypologyType.USER_ADDED_TO_EVENT}`, notificationSubscriber);
|
|
42
|
+
return () => {
|
|
43
|
+
PubSub.unsubscribe(notificationInvitedToJoinEvent.current);
|
|
44
|
+
PubSub.unsubscribe(notificationRequestedToJoinEvent.current);
|
|
45
|
+
PubSub.unsubscribe(notificationAcceptedToJoinEvent.current);
|
|
46
|
+
PubSub.unsubscribe(notificationAddedToEvent.current);
|
|
47
|
+
};
|
|
48
|
+
}, [data]);
|
|
49
|
+
/**
|
|
50
|
+
* Notification subscriber handler
|
|
51
|
+
* @param msg
|
|
52
|
+
* @param dataMsg
|
|
53
|
+
*/
|
|
54
|
+
const notificationSubscriber = (msg, dataMsg) => {
|
|
55
|
+
if (dataMsg.data.event !== undefined) {
|
|
56
|
+
let _status;
|
|
57
|
+
switch (SCNotificationMapping[dataMsg.data.activity_type]) {
|
|
58
|
+
case SCNotificationTypologyType.USER_INVITED_TO_JOIN_EVENT:
|
|
59
|
+
_status = SCEventSubscriptionStatusType.INVITED;
|
|
60
|
+
break;
|
|
61
|
+
case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_EVENT:
|
|
62
|
+
_status = SCEventSubscriptionStatusType.REQUESTED;
|
|
63
|
+
break;
|
|
64
|
+
case SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_EVENT:
|
|
65
|
+
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
66
|
+
break;
|
|
67
|
+
case SCNotificationTypologyType.USER_ADDED_TO_EVENT:
|
|
68
|
+
_status = SCEventSubscriptionStatusType.SUBSCRIBED;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
updateCache([dataMsg.data.event.id]);
|
|
72
|
+
setData((prev) => getDataUpdated(prev, dataMsg.data.event.id, _status));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Memoized refresh all events
|
|
77
|
+
* It makes a single request to the server and retrieves
|
|
78
|
+
* all the events followed by the user in a single solution
|
|
79
|
+
* It might be useful for multi-tab sync
|
|
80
|
+
*/
|
|
81
|
+
const refresh = useMemo(() => () => {
|
|
82
|
+
emptyCache();
|
|
83
|
+
if (user) {
|
|
84
|
+
// Only if user is authenticated
|
|
85
|
+
http
|
|
86
|
+
.request({
|
|
87
|
+
url: Endpoints.GetUserEvents.url(),
|
|
88
|
+
method: Endpoints.GetUserEvents.method,
|
|
89
|
+
})
|
|
90
|
+
.then((res) => {
|
|
91
|
+
if (res.status >= 300) {
|
|
92
|
+
return Promise.reject(res);
|
|
93
|
+
}
|
|
94
|
+
const eventsIds = res.data.results.map((e) => e.id);
|
|
95
|
+
updateCache(eventsIds);
|
|
96
|
+
setData(res.data.results.map((e) => ({ [e.id]: e.subscription_status })));
|
|
97
|
+
return Promise.resolve(res.data);
|
|
98
|
+
})
|
|
99
|
+
.catch((e) => {
|
|
100
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh the authenticated user events.');
|
|
101
|
+
Logger.error(SCOPE_SC_CORE, e);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}, [data, user, cache]);
|
|
105
|
+
/**
|
|
106
|
+
* Memoized toggleEventAttendance Event
|
|
107
|
+
* Toggle action
|
|
108
|
+
*/
|
|
109
|
+
const toggleEventAttendance = useMemo(() => (event, userId) => {
|
|
110
|
+
setLoading(event.id);
|
|
111
|
+
if (userId) {
|
|
112
|
+
return http
|
|
113
|
+
.request({
|
|
114
|
+
url: Endpoints.InviteOrAcceptEventRequest.url({ id: event.id }),
|
|
115
|
+
method: Endpoints.InviteOrAcceptEventRequest.method,
|
|
116
|
+
data: { users: [userId] },
|
|
117
|
+
})
|
|
118
|
+
.then((res) => {
|
|
119
|
+
if (res.status >= 300) {
|
|
120
|
+
return Promise.reject(res);
|
|
121
|
+
}
|
|
122
|
+
updateCache([event.id]);
|
|
123
|
+
setData((prev) => getDataUpdated(prev, event.id, SCEventSubscriptionStatusType.SUBSCRIBED));
|
|
124
|
+
setUnLoading(event.id);
|
|
125
|
+
return Promise.resolve(res.data);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const requestConfig = event.subscription_status === SCEventSubscriptionStatusType.GOING
|
|
130
|
+
? {
|
|
131
|
+
url: Endpoints.RemoveGoingToEvent.url({ id: event.id }),
|
|
132
|
+
method: Endpoints.RemoveGoingToEvent.method,
|
|
133
|
+
}
|
|
134
|
+
: {
|
|
135
|
+
url: Endpoints.GoToEvent.url({ id: event.id }),
|
|
136
|
+
method: Endpoints.GoToEvent.method,
|
|
137
|
+
};
|
|
138
|
+
return http.request(requestConfig).then((res) => {
|
|
139
|
+
if (res.status >= 300) {
|
|
140
|
+
return Promise.reject(res);
|
|
141
|
+
}
|
|
142
|
+
updateCache([event.id]);
|
|
143
|
+
setData((prev) => getDataUpdated(prev, event.id, event.privacy === SCEventPrivacyType.PRIVATE && event.subscription_status !== SCEventSubscriptionStatusType.INVITED
|
|
144
|
+
? SCEventSubscriptionStatusType.REQUESTED
|
|
145
|
+
: event.subscription_status === SCEventSubscriptionStatusType.GOING
|
|
146
|
+
? SCEventSubscriptionStatusType.SUBSCRIBED
|
|
147
|
+
: SCEventSubscriptionStatusType.GOING));
|
|
148
|
+
setUnLoading(event.id);
|
|
149
|
+
return Promise.resolve(res.data);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}, [data, loading, cache]);
|
|
153
|
+
/**
|
|
154
|
+
* Memoized toggleEventNonattendance Event
|
|
155
|
+
* Toggle action
|
|
156
|
+
*/
|
|
157
|
+
const toggleEventNonattendance = useMemo(() => (event) => {
|
|
158
|
+
if (event.subscription_status !== SCEventSubscriptionStatusType.REQUESTED) {
|
|
159
|
+
setLoading(event.id);
|
|
160
|
+
const requestConfig = event.subscription_status === SCEventSubscriptionStatusType.NOT_GOING
|
|
161
|
+
? {
|
|
162
|
+
url: Endpoints.RemoveNotGoingToEvent.url({ id: event.id }),
|
|
163
|
+
method: Endpoints.RemoveNotGoingToEvent.method,
|
|
164
|
+
}
|
|
165
|
+
: {
|
|
166
|
+
url: Endpoints.NotGoingToEvent.url({ id: event.id }),
|
|
167
|
+
method: Endpoints.NotGoingToEvent.method,
|
|
168
|
+
};
|
|
169
|
+
return http.request(requestConfig).then((res) => {
|
|
170
|
+
if (res.status >= 300) {
|
|
171
|
+
return Promise.reject(res);
|
|
172
|
+
}
|
|
173
|
+
updateCache([event.id]);
|
|
174
|
+
setData((prev) => getDataUpdated(prev, event.id, event.subscription_status === SCEventSubscriptionStatusType.NOT_GOING
|
|
175
|
+
? SCEventSubscriptionStatusType.SUBSCRIBED
|
|
176
|
+
: SCEventSubscriptionStatusType.NOT_GOING));
|
|
177
|
+
setUnLoading(event.id);
|
|
178
|
+
return Promise.resolve(res.data);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}, [data, loading, cache]);
|
|
182
|
+
/**
|
|
183
|
+
* Check the authenticated user subscription status to the event
|
|
184
|
+
* Update the events cached
|
|
185
|
+
* Update events subscription statuses
|
|
186
|
+
* @param event
|
|
187
|
+
*/
|
|
188
|
+
const checkEventSubscriptionStatus = (event) => {
|
|
189
|
+
setLoading(event.id);
|
|
190
|
+
return http
|
|
191
|
+
.request({
|
|
192
|
+
url: Endpoints.GetEventSubscriptionStatus.url({ id: event.id }),
|
|
193
|
+
method: Endpoints.GetEventSubscriptionStatus.method,
|
|
194
|
+
})
|
|
195
|
+
.then((res) => {
|
|
196
|
+
if (res.status >= 300) {
|
|
197
|
+
return Promise.reject(res);
|
|
198
|
+
}
|
|
199
|
+
setData((prev) => getDataUpdated(prev, event.id, res.data.status));
|
|
200
|
+
updateCache([event.id]);
|
|
201
|
+
setUnLoading(event.id);
|
|
202
|
+
return Promise.resolve(res.data);
|
|
203
|
+
})
|
|
204
|
+
.catch((e) => {
|
|
205
|
+
setUnLoading(event.id);
|
|
206
|
+
return Promise.reject(e);
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Get updated data
|
|
211
|
+
* @param data
|
|
212
|
+
* @param eventId
|
|
213
|
+
* @param subscriptionStatus
|
|
214
|
+
*/
|
|
215
|
+
const getDataUpdated = (data, eventId, subscriptionStatus) => {
|
|
216
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === eventId);
|
|
217
|
+
let _data;
|
|
218
|
+
if (_index < 0) {
|
|
219
|
+
_data = [...data, ...[{ [eventId]: subscriptionStatus }]];
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
_data = data.map((k, i) => {
|
|
223
|
+
if (parseInt(Object.keys(k)[0]) === eventId) {
|
|
224
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
225
|
+
}
|
|
226
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return _data;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Return current event subscription status if exists,
|
|
233
|
+
* otherwise return null
|
|
234
|
+
*/
|
|
235
|
+
const getCurrentEventCacheStatus = useMemo(() => (event) => {
|
|
236
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === event.id);
|
|
237
|
+
return d.length ? d[0][event.id] : !data.length ? event.subscription_status : null;
|
|
238
|
+
}, [data]);
|
|
239
|
+
/**
|
|
240
|
+
* Bypass remote check if the event is subscribed
|
|
241
|
+
*/
|
|
242
|
+
const getSubscriptionStatus = useMemo(() => (event) => {
|
|
243
|
+
updateCache([event.id]);
|
|
244
|
+
setData((prev) => getDataUpdated(prev, event.id, event.subscription_status));
|
|
245
|
+
return event.subscription_status;
|
|
246
|
+
}, [data, cache]);
|
|
247
|
+
/**
|
|
248
|
+
* Memoized subscriptionStatus
|
|
249
|
+
* If event is already in cache -> check if the event is in events,
|
|
250
|
+
* otherwise, check if user toggleEventAttendance the event
|
|
251
|
+
*/
|
|
252
|
+
const subscriptionStatus = useMemo(() => (event) => {
|
|
253
|
+
// Cache is valid also for anonymous user
|
|
254
|
+
if (cache.includes(event === null || event === void 0 ? void 0 : event.id)) {
|
|
255
|
+
return getCurrentEventCacheStatus(event);
|
|
256
|
+
}
|
|
257
|
+
if (authUserId) {
|
|
258
|
+
if ('subscription_status' in event) {
|
|
259
|
+
return getSubscriptionStatus(event);
|
|
260
|
+
}
|
|
261
|
+
if (!isLoading(event)) {
|
|
262
|
+
checkEventSubscriptionStatus(event);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}, [loading, cache, authUserId]);
|
|
267
|
+
/**
|
|
268
|
+
* Empty cache on logout
|
|
269
|
+
*/
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (!authUserId) {
|
|
272
|
+
emptyCache();
|
|
273
|
+
}
|
|
274
|
+
}, [authUserId]);
|
|
275
|
+
if (!eventsEnabled || !user) {
|
|
276
|
+
return { events: data, loading, isLoading };
|
|
277
|
+
}
|
|
278
|
+
return { events: data, loading, isLoading, toggleEventAttendance, toggleEventNonattendance, subscriptionStatus, refresh, emptyCache };
|
|
279
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types
|
|
3
3
|
*/
|
|
4
|
-
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType } from './types';
|
|
4
|
+
import { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCSettingsManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -82,4 +82,4 @@ import * as Locale from './constants/Locale';
|
|
|
82
82
|
/**
|
|
83
83
|
* List all exports
|
|
84
84
|
*/
|
|
85
|
-
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, SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent };
|
|
85
|
+
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, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, };
|
package/lib/esm/index.js
CHANGED
|
@@ -78,4 +78,4 @@ import * as Locale from './constants/Locale';
|
|
|
78
78
|
/**
|
|
79
79
|
* List all exports
|
|
80
80
|
*/
|
|
81
|
-
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent };
|
|
81
|
+
export { SCContext, SCUserContext, SCThemeContext, SCRoutingContext, SCLocaleContext, SCPreferencesContext, useSCContext, SCContextProvider, SCUserProvider, useSCUser, useSCPreferences, SCThemeProvider, useSCTheme, withSCTheme, SCRoutingProvider, useSCRouting, SCLocaleProvider, useSCLocale, withSCLocale, SCPreferencesProvider, SCPreferences, SCFeatures, SCNotification, SCNotificationProvider, SCNotificationContext, useSCNotification, SCAlertMessagesProvider, SCAlertMessagesContext, useSCAlertMessages, Link, SCRoutes, SCCache, UserUtils, Locale, useSCFetchUser, useSCFetchUserProviders, useSCFetchVote, useSCFetchFeedObject, useSCFetchCommentObject, useSCFetchCommentObjects, useSCFetchCustomAdv, useSCFetchTag, useSCFetchAddressingTagList, useSCFetchCategory, useSCFetchCategories, useSCFetchIncubator, useSCMediaClick, useSCFetchContributors, useSCFetchFeed, useIsComponentMountedRef, usePreviousValue, useIsomorphicLayoutEffect, useEffectOnce, useNoInitialEffect, useSCFetchPrivateMessageSnippets, useSCFetchBroadcastMessages, useSCFetchUserBlockedBy, useSCUserIsBlocked, useSCFetchGroup, useSCFetchGroups, useSCFetchEvent, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -147,6 +147,7 @@ export interface SCUserContextType {
|
|
|
147
147
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
148
148
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
149
149
|
groups?: SCSubscribedGroupsManagerType;
|
|
150
|
+
events?: SCSubscribedEventsManagerType;
|
|
150
151
|
};
|
|
151
152
|
}
|
|
152
153
|
export interface SCSettingsManagerType {
|
|
@@ -253,6 +254,44 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
253
254
|
*/
|
|
254
255
|
emptyCache?: () => void;
|
|
255
256
|
}
|
|
257
|
+
export interface SCSubscribedEventsManagerType {
|
|
258
|
+
/**
|
|
259
|
+
* List of all events ids followed by the authenticated user
|
|
260
|
+
*/
|
|
261
|
+
events: number[];
|
|
262
|
+
/**
|
|
263
|
+
* List of all events in loading state
|
|
264
|
+
*/
|
|
265
|
+
loading: number[];
|
|
266
|
+
/**
|
|
267
|
+
* List of current events in loading state
|
|
268
|
+
*/
|
|
269
|
+
isLoading: (event: SCEventType) => boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Handle user subscription to an event
|
|
272
|
+
*/
|
|
273
|
+
subscribe?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
274
|
+
/**
|
|
275
|
+
* Handle user going to an event
|
|
276
|
+
*/
|
|
277
|
+
toggleEventAttendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
278
|
+
/**
|
|
279
|
+
* Handle user not going to an event
|
|
280
|
+
*/
|
|
281
|
+
toggleEventNonattendance?: (event: SCEventType, userId?: number) => Promise<any>;
|
|
282
|
+
/**
|
|
283
|
+
* Handles a user subscription status to an event, caching data
|
|
284
|
+
*/
|
|
285
|
+
subscriptionStatus?: (event: SCEventType) => string;
|
|
286
|
+
/**
|
|
287
|
+
* Refresh groups
|
|
288
|
+
*/
|
|
289
|
+
refresh?: () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Empty cache to revalidate all groups
|
|
292
|
+
*/
|
|
293
|
+
emptyCache?: () => void;
|
|
294
|
+
}
|
|
256
295
|
export interface SCSubscribedGroupsManagerType {
|
|
257
296
|
/**
|
|
258
297
|
* List of all groups ids followed by the authenticated user
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType } from './context';
|
|
1
|
+
import { SCUserContextType, SCFollowedManagerType, SCFollowersManagerType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCSubscribedIncubatorsManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCPreferencesContextType, SCNotificationContextType, SCLocaleType, SCVoteType, SCVoteContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType } from './context';
|
|
2
2
|
import { SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType } from './theme';
|
|
3
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, };
|
|
3
|
+
export { SCUserContextType, SCFollowedCategoriesManagerType, SCSettingsManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCBlockedUsersManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCVoteType, SCVoteContextType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeUserVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, SCSubscribedGroupsManagerType, SCSubscribedEventsManagerType, };
|