@selfcommunity/react-core 0.4.9-alpha.0 → 0.4.9-alpha.10
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/constants/Cache.d.ts +9 -0
- package/lib/cjs/constants/Cache.js +13 -1
- package/lib/cjs/constants/Routes.d.ts +4 -0
- package/lib/cjs/constants/Routes.js +9 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/cjs/hooks/useSCFetchGroup.js +73 -0
- package/lib/cjs/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/cjs/hooks/useSCFetchGroups.js +83 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +38 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +218 -0
- package/lib/cjs/index.d.ts +4 -2
- package/lib/cjs/index.js +5 -1
- package/lib/cjs/themes/theme.js +8 -0
- package/lib/cjs/types/context.d.ts +37 -2
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/types/theme.d.ts +13 -0
- package/lib/esm/components/provider/SCUserProvider/index.js +6 -0
- package/lib/esm/constants/Cache.d.ts +9 -0
- package/lib/esm/constants/Cache.js +9 -0
- package/lib/esm/constants/Routes.d.ts +4 -0
- package/lib/esm/constants/Routes.js +8 -0
- package/lib/esm/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchGroup.js +70 -0
- package/lib/esm/hooks/useSCFetchGroups.d.ts +22 -0
- package/lib/esm/hooks/useSCFetchGroups.js +81 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +38 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +214 -0
- package/lib/esm/index.d.ts +4 -2
- package/lib/esm/index.js +3 -1
- package/lib/esm/themes/theme.js +8 -0
- package/lib/esm/types/context.d.ts +37 -2
- package/lib/esm/types/index.d.ts +2 -2
- package/lib/esm/types/theme.d.ts +13 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
3
|
+
import { SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
4
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
5
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
6
|
+
import { Logger } from '@selfcommunity/utils';
|
|
7
|
+
/**
|
|
8
|
+
:::info
|
|
9
|
+
This custom hook is used to manage the groups followed.
|
|
10
|
+
:::
|
|
11
|
+
|
|
12
|
+
:::tip How to use it:
|
|
13
|
+
Follow these steps:
|
|
14
|
+
```jsx
|
|
15
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
16
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
17
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
18
|
+
```
|
|
19
|
+
:::
|
|
20
|
+
*/
|
|
21
|
+
export default function useSCSubscribedGroupsManager(user) {
|
|
22
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
23
|
+
const authUserId = user ? user.id : null;
|
|
24
|
+
/**
|
|
25
|
+
* Memoized refresh all groups
|
|
26
|
+
* It makes a single request to the server and retrieves
|
|
27
|
+
* all the groups followed by the user in a single solution
|
|
28
|
+
* It might be useful for multi-tab sync
|
|
29
|
+
*/
|
|
30
|
+
const refresh = useMemo(() => () => {
|
|
31
|
+
emptyCache();
|
|
32
|
+
if (user) {
|
|
33
|
+
// Only if user is authenticated
|
|
34
|
+
http
|
|
35
|
+
.request({
|
|
36
|
+
url: Endpoints.GetUserGroups.url(),
|
|
37
|
+
method: Endpoints.GetUserGroups.method,
|
|
38
|
+
})
|
|
39
|
+
.then((res) => {
|
|
40
|
+
if (res.status >= 300) {
|
|
41
|
+
return Promise.reject(res);
|
|
42
|
+
}
|
|
43
|
+
const groupsIds = res.data.map((g) => g.id);
|
|
44
|
+
updateCache(groupsIds);
|
|
45
|
+
setData(groupsIds);
|
|
46
|
+
return Promise.resolve(res.data);
|
|
47
|
+
})
|
|
48
|
+
.catch((e) => {
|
|
49
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh the authenticated user groups.');
|
|
50
|
+
Logger.error(SCOPE_SC_CORE, e);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}, [data, user, cache]);
|
|
54
|
+
/**
|
|
55
|
+
* Memoized subscribe Group
|
|
56
|
+
* Toggle action
|
|
57
|
+
*/
|
|
58
|
+
const subscribe = useMemo(() => (group, userId) => {
|
|
59
|
+
setLoading(group.id);
|
|
60
|
+
if (userId) {
|
|
61
|
+
return http
|
|
62
|
+
.request({
|
|
63
|
+
url: Endpoints.InviteOrAcceptGroupRequest.url({ id: group.id }),
|
|
64
|
+
method: Endpoints.InviteOrAcceptGroupRequest.method,
|
|
65
|
+
data: { users: [userId] },
|
|
66
|
+
})
|
|
67
|
+
.then((res) => {
|
|
68
|
+
if (res.status >= 300) {
|
|
69
|
+
return Promise.reject(res);
|
|
70
|
+
}
|
|
71
|
+
updateCache([group.id]);
|
|
72
|
+
setData((prev) => getDataUpdated(prev, group.id, SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
73
|
+
setUnLoading(group.id);
|
|
74
|
+
return Promise.resolve(res.data);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return http
|
|
79
|
+
.request({
|
|
80
|
+
url: Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
81
|
+
method: Endpoints.SubscribeToGroup.method,
|
|
82
|
+
})
|
|
83
|
+
.then((res) => {
|
|
84
|
+
if (res.status >= 300) {
|
|
85
|
+
return Promise.reject(res);
|
|
86
|
+
}
|
|
87
|
+
updateCache([group.id]);
|
|
88
|
+
setData((prev) => getDataUpdated(prev, group.id, group.privacy === SCGroupPrivacyType.PRIVATE ? SCGroupSubscriptionStatusType.REQUESTED : SCGroupSubscriptionStatusType.SUBSCRIBED));
|
|
89
|
+
setUnLoading(group.id);
|
|
90
|
+
return Promise.resolve(res.data);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}, [data, loading, cache]);
|
|
94
|
+
/**
|
|
95
|
+
* Memoized subscribe Group
|
|
96
|
+
* Toggle action
|
|
97
|
+
*/
|
|
98
|
+
const unsubscribe = useMemo(() => (group) => {
|
|
99
|
+
if (group.subscription_status !== SCGroupSubscriptionStatusType.REQUESTED) {
|
|
100
|
+
setLoading(group.id);
|
|
101
|
+
return http
|
|
102
|
+
.request({
|
|
103
|
+
url: Endpoints.UnsubscribeFromGroup.url({ id: group.id }),
|
|
104
|
+
method: Endpoints.UnsubscribeFromGroup.method,
|
|
105
|
+
})
|
|
106
|
+
.then((res) => {
|
|
107
|
+
if (res.status >= 300) {
|
|
108
|
+
return Promise.reject(res);
|
|
109
|
+
}
|
|
110
|
+
updateCache([group.id]);
|
|
111
|
+
setData((prev) => getDataUpdated(prev, group.id, null));
|
|
112
|
+
setUnLoading(group.id);
|
|
113
|
+
return Promise.resolve(res.data);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}, [data, loading, cache]);
|
|
117
|
+
/**
|
|
118
|
+
* Check the authenticated user subscription status to the group
|
|
119
|
+
* Update the groups cached
|
|
120
|
+
* Update groups subscription statuses
|
|
121
|
+
* @param group
|
|
122
|
+
*/
|
|
123
|
+
const checkGroupSubscriptionStatus = (group) => {
|
|
124
|
+
setLoading(group.id);
|
|
125
|
+
return http
|
|
126
|
+
.request({
|
|
127
|
+
url: Endpoints.GetGroupSubscriptionStatus.url({ id: group.id }),
|
|
128
|
+
method: Endpoints.GetGroupSubscriptionStatus.method,
|
|
129
|
+
})
|
|
130
|
+
.then((res) => {
|
|
131
|
+
if (res.status >= 300) {
|
|
132
|
+
return Promise.reject(res);
|
|
133
|
+
}
|
|
134
|
+
setData((prev) => getDataUpdated(prev, group.id, res.data.status));
|
|
135
|
+
updateCache([group.id]);
|
|
136
|
+
setUnLoading(group.id);
|
|
137
|
+
return Promise.resolve(res.data);
|
|
138
|
+
})
|
|
139
|
+
.catch((e) => {
|
|
140
|
+
setUnLoading(group.id);
|
|
141
|
+
return Promise.reject(e);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Get updated data
|
|
146
|
+
* @param data
|
|
147
|
+
* @param groupId
|
|
148
|
+
* @param subscriptionStatus
|
|
149
|
+
*/
|
|
150
|
+
const getDataUpdated = (data, groupId, subscriptionStatus) => {
|
|
151
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === groupId);
|
|
152
|
+
let _data;
|
|
153
|
+
if (_index < 0) {
|
|
154
|
+
_data = [...data, ...[{ [groupId]: subscriptionStatus }]];
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
_data = data.map((k, i) => {
|
|
158
|
+
if (parseInt(Object.keys(k)[0]) === groupId) {
|
|
159
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
160
|
+
}
|
|
161
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return _data;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Return current group subscription status if exists,
|
|
168
|
+
* otherwise return null
|
|
169
|
+
*/
|
|
170
|
+
const getCurrentGroupCacheStatus = useMemo(() => (group) => {
|
|
171
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === group.id);
|
|
172
|
+
return d.length ? d[0][group.id] : null;
|
|
173
|
+
}, [data]);
|
|
174
|
+
/**
|
|
175
|
+
* Bypass remote check if the group is subscribed
|
|
176
|
+
*/
|
|
177
|
+
const getSubscriptionStatus = useMemo(() => (group) => {
|
|
178
|
+
updateCache([group.id]);
|
|
179
|
+
setData((prev) => getDataUpdated(prev, group.id, group.subscription_status));
|
|
180
|
+
return group.subscription_status;
|
|
181
|
+
}, [data, cache]);
|
|
182
|
+
/**
|
|
183
|
+
* Memoized subscriptionStatus
|
|
184
|
+
* If group is already in cache -> check if the group is in groups,
|
|
185
|
+
* otherwise, check if user subscribe the group
|
|
186
|
+
*/
|
|
187
|
+
const subscriptionStatus = useMemo(() => (group) => {
|
|
188
|
+
// Cache is valid also for anonymous user
|
|
189
|
+
if (cache.includes(group.id)) {
|
|
190
|
+
return getCurrentGroupCacheStatus(group);
|
|
191
|
+
}
|
|
192
|
+
if (authUserId) {
|
|
193
|
+
if ('subscription_status' in group) {
|
|
194
|
+
return getSubscriptionStatus(group);
|
|
195
|
+
}
|
|
196
|
+
if (!isLoading(group)) {
|
|
197
|
+
checkGroupSubscriptionStatus(group);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}, [data, loading, cache, authUserId]);
|
|
202
|
+
/**
|
|
203
|
+
* Empty cache on logout
|
|
204
|
+
*/
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
if (!authUserId) {
|
|
207
|
+
emptyCache();
|
|
208
|
+
}
|
|
209
|
+
}, [authUserId]);
|
|
210
|
+
if (!user) {
|
|
211
|
+
return { groups: data, loading, isLoading };
|
|
212
|
+
}
|
|
213
|
+
return { groups: data, loading, isLoading, subscribe, unsubscribe, subscriptionStatus, refresh, emptyCache };
|
|
214
|
+
}
|
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 } 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 } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* ContextProvider component
|
|
7
7
|
*/
|
|
@@ -60,6 +60,8 @@ import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSn
|
|
|
60
60
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
61
61
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
62
62
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
63
|
+
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
64
|
+
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
63
65
|
/**
|
|
64
66
|
* Routing component
|
|
65
67
|
*/
|
|
@@ -79,4 +81,4 @@ import * as Locale from './constants/Locale';
|
|
|
79
81
|
/**
|
|
80
82
|
* List all exports
|
|
81
83
|
*/
|
|
82
|
-
export { SCUserContextType, SCFollowedCategoriesManagerType, SCContextProviderType, SCContextType, SCSettingsType, SCSessionType, SCSettingsManagerType, SCFollowedManagerType, SCFollowersManagerType, SCConnectionsManagerType, SCSubscribedIncubatorsManagerType, SCLocaleType, SCNotificationContextType, SCPreferencesContextType, SCThemeContextType, SCRoutingContextType, SCLocaleContextType, SCAlertMessagesContextType, SCThemeAvatarVariableType, SCThemeCategoryIconVariableType, SCThemeCategoryVariableType, SCThemeVariablesType, SCThemeType, 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, };
|
|
84
|
+
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, };
|
package/lib/esm/index.js
CHANGED
|
@@ -56,6 +56,8 @@ import useSCFetchPrivateMessageSnippets from './hooks/useSCFetchPrivateMessageSn
|
|
|
56
56
|
import useSCFetchBroadcastMessages from './hooks/useSCFetchBroadcastMessages';
|
|
57
57
|
import useSCFetchUserBlockedBy from './hooks/useSCFetchUserBlockedBy';
|
|
58
58
|
import useSCUserIsBlocked from './hooks/useSCUserIsBlocked';
|
|
59
|
+
import useSCFetchGroup from './hooks/useSCFetchGroup';
|
|
60
|
+
import useSCFetchGroups from './hooks/useSCFetchGroups';
|
|
59
61
|
/**
|
|
60
62
|
* Routing component
|
|
61
63
|
*/
|
|
@@ -75,4 +77,4 @@ import * as Locale from './constants/Locale';
|
|
|
75
77
|
/**
|
|
76
78
|
* List all exports
|
|
77
79
|
*/
|
|
78
|
-
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, };
|
|
80
|
+
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, };
|
package/lib/esm/themes/theme.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType } from
|
|
2
|
+
import { SCAuthTokenType, SCIncubatorType, SCCategoryType, SCUserType, SCUserSettingsType, SCReactionType, SCGroupType } from '@selfcommunity/types';
|
|
3
3
|
import { SCThemeType } from './theme';
|
|
4
4
|
/**
|
|
5
5
|
* Interface SCSettingsType
|
|
@@ -132,7 +132,7 @@ export interface SCUserContextType {
|
|
|
132
132
|
*/
|
|
133
133
|
refreshCounters: () => Promise<any>;
|
|
134
134
|
/**
|
|
135
|
-
* Managers: followed, connections, categories, incubators, etc...
|
|
135
|
+
* Managers: followed, connections, categories, incubators, groups, etc...
|
|
136
136
|
*/
|
|
137
137
|
managers: {
|
|
138
138
|
settings?: SCSettingsManagerType;
|
|
@@ -142,6 +142,7 @@ export interface SCUserContextType {
|
|
|
142
142
|
categories: SCFollowedCategoriesManagerType;
|
|
143
143
|
incubators?: SCSubscribedIncubatorsManagerType;
|
|
144
144
|
blockedUsers?: SCBlockedUsersManagerType;
|
|
145
|
+
groups?: SCSubscribedGroupsManagerType;
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
148
|
export interface SCSettingsManagerType {
|
|
@@ -248,6 +249,40 @@ export interface SCFollowedCategoriesManagerType {
|
|
|
248
249
|
*/
|
|
249
250
|
emptyCache?: () => void;
|
|
250
251
|
}
|
|
252
|
+
export interface SCSubscribedGroupsManagerType {
|
|
253
|
+
/**
|
|
254
|
+
* List of all groups ids followed by the authenticated user
|
|
255
|
+
*/
|
|
256
|
+
groups: number[];
|
|
257
|
+
/**
|
|
258
|
+
* List of all groups in loading state
|
|
259
|
+
*/
|
|
260
|
+
loading: number[];
|
|
261
|
+
/**
|
|
262
|
+
* List of current groups in loading state
|
|
263
|
+
*/
|
|
264
|
+
isLoading: (group: SCGroupType) => boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Handle user subscription to a group
|
|
267
|
+
*/
|
|
268
|
+
subscribe?: (group: SCGroupType, userId?: number) => Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Handle user unsubscription from a group
|
|
271
|
+
*/
|
|
272
|
+
unsubscribe?: (group: SCGroupType) => Promise<any>;
|
|
273
|
+
/**
|
|
274
|
+
* Handles a user subscription status to a group, caching data
|
|
275
|
+
*/
|
|
276
|
+
subscriptionStatus?: (group: SCGroupType) => string;
|
|
277
|
+
/**
|
|
278
|
+
* Refresh groups
|
|
279
|
+
*/
|
|
280
|
+
refresh?: () => void;
|
|
281
|
+
/**
|
|
282
|
+
* Empty cache to revalidate all groups
|
|
283
|
+
*/
|
|
284
|
+
emptyCache?: () => void;
|
|
285
|
+
}
|
|
251
286
|
export interface SCConnectionsManagerType {
|
|
252
287
|
/**
|
|
253
288
|
* List of all users in relations(social graph) with 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 } 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 } 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, };
|
|
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, };
|
package/lib/esm/types/theme.d.ts
CHANGED
|
@@ -29,6 +29,15 @@ export interface SCThemeUserVariableType {
|
|
|
29
29
|
*/
|
|
30
30
|
avatar: SCThemeAvatarVariableType;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface SCThemeGroupVariableType
|
|
34
|
+
*/
|
|
35
|
+
export interface SCThemeGroupVariableType {
|
|
36
|
+
/**
|
|
37
|
+
* Avatar variables
|
|
38
|
+
*/
|
|
39
|
+
avatar: SCThemeAvatarVariableType;
|
|
40
|
+
}
|
|
32
41
|
/**
|
|
33
42
|
* Interface SCThemeCategoryVariableType
|
|
34
43
|
*/
|
|
@@ -67,6 +76,10 @@ export interface SCThemeVariablesType {
|
|
|
67
76
|
* Category
|
|
68
77
|
*/
|
|
69
78
|
category: SCThemeCategoryVariableType;
|
|
79
|
+
/**
|
|
80
|
+
* Group
|
|
81
|
+
*/
|
|
82
|
+
group: SCThemeGroupVariableType;
|
|
70
83
|
}
|
|
71
84
|
export interface SCThemeType extends MuiTheme {
|
|
72
85
|
/**
|