@selfcommunity/react-core 0.4.9-alpha.0 → 0.4.9-alpha.1
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 +5 -0
- package/lib/cjs/constants/Cache.js +8 -1
- package/lib/cjs/constants/Routes.d.ts +1 -0
- package/lib/cjs/constants/Routes.js +3 -1
- package/lib/cjs/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/cjs/hooks/useSCFetchGroup.js +73 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.d.ts +36 -0
- package/lib/cjs/hooks/useSCSubscribedGroupsManager.js +176 -0
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/themes/theme.js +8 -0
- package/lib/cjs/types/context.d.ts +33 -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 +5 -0
- package/lib/esm/constants/Cache.js +5 -0
- package/lib/esm/constants/Routes.d.ts +1 -0
- package/lib/esm/constants/Routes.js +2 -0
- package/lib/esm/hooks/useSCFetchGroup.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchGroup.js +70 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.d.ts +36 -0
- package/lib/esm/hooks/useSCSubscribedGroupsManager.js +172 -0
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +2 -1
- package/lib/esm/themes/theme.js +8 -0
- package/lib/esm/types/context.d.ts +33 -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
|
@@ -17,6 +17,9 @@ export declare const getCategoriesObjectCacheKey: () => string;
|
|
|
17
17
|
/** CATEGORY OBJECT **/
|
|
18
18
|
export declare const CATEGORY_OBJECT_CACHE_PREFIX_KEY = "_ca_";
|
|
19
19
|
export declare const getCategoryObjectCacheKey: (id: any) => string;
|
|
20
|
+
/** GROUP OBJECT **/
|
|
21
|
+
export declare const GROUP_OBJECT_CACHE_PREFIX_KEY = "_grp_";
|
|
22
|
+
export declare const getGroupObjectCacheKey: (id: any) => string;
|
|
20
23
|
/** INCUBATOR OBJECT **/
|
|
21
24
|
export declare const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = "_inc_";
|
|
22
25
|
export declare const getIncubatorObjectCacheKey: (id: any) => string;
|
|
@@ -62,4 +65,6 @@ export declare const PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidg
|
|
|
62
65
|
export declare const INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = "_iListWidget_";
|
|
63
66
|
export declare const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_iSugWidget_";
|
|
64
67
|
export declare const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = "_pSugWidget_";
|
|
68
|
+
export declare const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gMemWidget_";
|
|
69
|
+
export declare const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_gReqWidget_";
|
|
65
70
|
export declare const getWidgetStateCacheKey: (p: any, id?: any) => string;
|
|
@@ -17,6 +17,9 @@ export const getCategoriesObjectCacheKey = () => `${CATEGORIES_OBJECT_CACHE_PREF
|
|
|
17
17
|
/** CATEGORY OBJECT **/
|
|
18
18
|
export const CATEGORY_OBJECT_CACHE_PREFIX_KEY = '_ca_';
|
|
19
19
|
export const getCategoryObjectCacheKey = (id) => `${CATEGORY_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
20
|
+
/** GROUP OBJECT **/
|
|
21
|
+
export const GROUP_OBJECT_CACHE_PREFIX_KEY = '_grp_';
|
|
22
|
+
export const getGroupObjectCacheKey = (id) => `${GROUP_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
20
23
|
/** INCUBATOR OBJECT **/
|
|
21
24
|
export const INCUBATOR_OBJECT_CACHE_PREFIX_KEY = '_inc_';
|
|
22
25
|
export const getIncubatorObjectCacheKey = (id) => `${INCUBATOR_OBJECT_CACHE_PREFIX_KEY}${id}`;
|
|
@@ -66,4 +69,6 @@ export const PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
|
66
69
|
export const INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = '_iListWidget_';
|
|
67
70
|
export const INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_iSugWidget_';
|
|
68
71
|
export const POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = '_pSugWidget_';
|
|
72
|
+
export const GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gMemWidget_';
|
|
73
|
+
export const GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_gReqWidget_';
|
|
69
74
|
export const getWidgetStateCacheKey = (p, id = undefined) => `${p}${id !== undefined ? id : ''}`;
|
|
@@ -31,6 +31,7 @@ export declare const SIGNUP_ROUTE_NAME = "signup";
|
|
|
31
31
|
export declare const RECOVER_ROUTE_NAME = "recover";
|
|
32
32
|
export declare const CUSTOM_PAGES_ROUTE_NAME = "custom_pages";
|
|
33
33
|
export declare const LEGAL_PAGES_ROUTE_NAME = "legal_pages";
|
|
34
|
+
export declare const GROUP_ROUTE_NAME = "group";
|
|
34
35
|
/**
|
|
35
36
|
* Default Routes
|
|
36
37
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -31,6 +31,7 @@ export const SIGNUP_ROUTE_NAME = 'signup';
|
|
|
31
31
|
export const RECOVER_ROUTE_NAME = 'recover';
|
|
32
32
|
export const CUSTOM_PAGES_ROUTE_NAME = 'custom_pages';
|
|
33
33
|
export const LEGAL_PAGES_ROUTE_NAME = 'legal_pages';
|
|
34
|
+
export const GROUP_ROUTE_NAME = 'group';
|
|
34
35
|
/**
|
|
35
36
|
* Default Routes
|
|
36
37
|
* @type {{[p: string]: string, '[POST_ROUTE_NAME]': string, '[INCUBATOR_ROUTE_NAME]': string, '[LOYALTY_ROUTE_NAME]': string, '[USER_NOTIFICATION_ROUTE_NAME]': string, '[USER_PRIVATE_MESSAGES_ROUTE_NAME]': string, '[COMMENT_ROUTE_NAME]': string, '[DISCUSSION_ROUTE_NAME]': string, '[CATEGORIES_ROUTE_NAME]': string, '[USER_PROFILE_ROUTE_NAME]': string, '[CATEGORY_ROUTE_NAME]': string, '[USER_PROFILE_SETTINGS_ROUTE_NAME]': string, '[STATUS_ROUTE_NAME]': string}}
|
|
@@ -64,4 +65,5 @@ export const defaultRoutes = {
|
|
|
64
65
|
[RECOVER_ROUTE_NAME]: '/recover/',
|
|
65
66
|
[CUSTOM_PAGES_ROUTE_NAME]: '/:id/:slug/',
|
|
66
67
|
[LEGAL_PAGES_ROUTE_NAME]: '/legal/:policy/',
|
|
68
|
+
[GROUP_ROUTE_NAME]: '/group/:id/',
|
|
67
69
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SCGroupType } from '@selfcommunity/types';
|
|
3
|
+
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
|
+
/**
|
|
5
|
+
:::info
|
|
6
|
+
This custom hook is used to fetch a group object.
|
|
7
|
+
:::
|
|
8
|
+
* @param object
|
|
9
|
+
* @param object.id
|
|
10
|
+
* @param object.group
|
|
11
|
+
* @param object.cacheStrategy
|
|
12
|
+
*/
|
|
13
|
+
export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
|
|
14
|
+
id?: number | string;
|
|
15
|
+
group?: SCGroupType;
|
|
16
|
+
cacheStrategy?: CacheStrategies;
|
|
17
|
+
}): {
|
|
18
|
+
scGroup: SCGroupType;
|
|
19
|
+
setSCGroup: import("react").Dispatch<import("react").SetStateAction<SCGroupType>>;
|
|
20
|
+
error: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
3
|
+
import { Endpoints, http } from '@selfcommunity/api-services';
|
|
4
|
+
import { CacheStrategies, Logger, LRUCache, objectWithoutProperties } from '@selfcommunity/utils';
|
|
5
|
+
import { getGroupObjectCacheKey } from '../constants/Cache';
|
|
6
|
+
import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
|
|
7
|
+
import { useSCUser } from '../components/provider/SCUserProvider';
|
|
8
|
+
/**
|
|
9
|
+
:::info
|
|
10
|
+
This custom hook is used to fetch a group object.
|
|
11
|
+
:::
|
|
12
|
+
* @param object
|
|
13
|
+
* @param object.id
|
|
14
|
+
* @param object.group
|
|
15
|
+
* @param object.cacheStrategy
|
|
16
|
+
*/
|
|
17
|
+
export default function useSCFetchGroup({ id = null, group = null, cacheStrategy = CacheStrategies.CACHE_FIRST, }) {
|
|
18
|
+
const __groupId = group ? group.id : id;
|
|
19
|
+
// CONTEXT
|
|
20
|
+
const scUserContext = useSCUser();
|
|
21
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
22
|
+
// CACHE
|
|
23
|
+
const __groupCacheKey = getGroupObjectCacheKey(__groupId);
|
|
24
|
+
const __group = authUserId ? group : objectWithoutProperties(group, ['subscribed']);
|
|
25
|
+
const [scGroup, setSCGroup] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__groupCacheKey, __group) : null);
|
|
26
|
+
const [error, setError] = useState(null);
|
|
27
|
+
/**
|
|
28
|
+
* Memoized fetchTag
|
|
29
|
+
*/
|
|
30
|
+
const fetchGroup = useMemo(() => () => {
|
|
31
|
+
return http
|
|
32
|
+
.request({
|
|
33
|
+
url: Endpoints.GetGroupInfo.url({ id: __groupId }),
|
|
34
|
+
method: Endpoints.GetGroupInfo.method,
|
|
35
|
+
})
|
|
36
|
+
.then((res) => {
|
|
37
|
+
if (res.status >= 300) {
|
|
38
|
+
return Promise.reject(res);
|
|
39
|
+
}
|
|
40
|
+
return Promise.resolve(res.data);
|
|
41
|
+
});
|
|
42
|
+
}, [__groupId]);
|
|
43
|
+
/**
|
|
44
|
+
* If id attempt to get the group by id
|
|
45
|
+
*/
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (__groupId && (!scGroup || (scGroup && __groupId !== scGroup.id))) {
|
|
48
|
+
fetchGroup()
|
|
49
|
+
.then((obj) => {
|
|
50
|
+
const _c = authUserId ? obj : objectWithoutProperties(obj, ['subscribed']);
|
|
51
|
+
setSCGroup(_c);
|
|
52
|
+
LRUCache.set(__groupCacheKey, _c);
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
LRUCache.delete(__groupCacheKey);
|
|
56
|
+
setError(`Group with id ${id} not found`);
|
|
57
|
+
Logger.error(SCOPE_SC_CORE, `Group with id ${id} not found`);
|
|
58
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}, [__groupId]);
|
|
62
|
+
useDeepCompareEffectNoCheck(() => {
|
|
63
|
+
if (group) {
|
|
64
|
+
const _c = authUserId ? group : objectWithoutProperties(group, ['subscribed']);
|
|
65
|
+
setSCGroup(_c);
|
|
66
|
+
LRUCache.set(__groupCacheKey, _c);
|
|
67
|
+
}
|
|
68
|
+
}, [group]);
|
|
69
|
+
return { scGroup, setSCGroup, error };
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SCGroupType, SCUserType } from '@selfcommunity/types';
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook is used to manage the groups followed.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
:::tip How to use it:
|
|
8
|
+
Follow these steps:
|
|
9
|
+
```jsx
|
|
10
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
11
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
12
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
*/
|
|
16
|
+
export default function useSCSubscribedGroupsManager(user?: SCUserType): {
|
|
17
|
+
groups: any[];
|
|
18
|
+
loading: any[];
|
|
19
|
+
isLoading: (v: number | {
|
|
20
|
+
id: number;
|
|
21
|
+
}) => boolean;
|
|
22
|
+
subscribe?: undefined;
|
|
23
|
+
subscriptionStatus?: undefined;
|
|
24
|
+
refresh?: undefined;
|
|
25
|
+
emptyCache?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
groups: any[];
|
|
28
|
+
loading: any[];
|
|
29
|
+
isLoading: (v: number | {
|
|
30
|
+
id: number;
|
|
31
|
+
}) => boolean;
|
|
32
|
+
subscribe: (group: SCGroupType) => Promise<any>;
|
|
33
|
+
subscriptionStatus: (group: SCGroupType) => string;
|
|
34
|
+
refresh: () => void;
|
|
35
|
+
emptyCache: () => void;
|
|
36
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { http, Endpoints } from '@selfcommunity/api-services';
|
|
3
|
+
import useSCCachingManager from './useSCCachingManager';
|
|
4
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
5
|
+
import { Logger } from '@selfcommunity/utils';
|
|
6
|
+
/**
|
|
7
|
+
:::info
|
|
8
|
+
This custom hook is used to manage the groups followed.
|
|
9
|
+
:::
|
|
10
|
+
|
|
11
|
+
:::tip How to use it:
|
|
12
|
+
Follow these steps:
|
|
13
|
+
```jsx
|
|
14
|
+
1. const scUserContext: SCUserContextType = useSCUser();
|
|
15
|
+
2. const scSubscribedGroupsManager: SCSubscribedGroupsManagerType = scUserContext.manager.groups;
|
|
16
|
+
3. scSubscribedGroupsManager.isSubscribed(group)
|
|
17
|
+
```
|
|
18
|
+
:::
|
|
19
|
+
*/
|
|
20
|
+
export default function useSCSubscribedGroupsManager(user) {
|
|
21
|
+
const { cache, updateCache, emptyCache, data, setData, loading, setLoading, setUnLoading, isLoading } = useSCCachingManager();
|
|
22
|
+
const authUserId = user ? user.id : null;
|
|
23
|
+
/**
|
|
24
|
+
* Memoized refresh all groups
|
|
25
|
+
* It makes a single request to the server and retrieves
|
|
26
|
+
* all the groups followed by the user in a single solution
|
|
27
|
+
* It might be useful for multi-tab sync
|
|
28
|
+
*/
|
|
29
|
+
const refresh = useMemo(() => () => {
|
|
30
|
+
emptyCache();
|
|
31
|
+
if (user) {
|
|
32
|
+
// Only if user is authenticated
|
|
33
|
+
http
|
|
34
|
+
.request({
|
|
35
|
+
url: Endpoints.GetUserGroups.url(),
|
|
36
|
+
method: Endpoints.GetUserGroups.method,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => {
|
|
39
|
+
if (res.status >= 300) {
|
|
40
|
+
return Promise.reject(res);
|
|
41
|
+
}
|
|
42
|
+
const groupsIds = res.data.map((g) => g.id);
|
|
43
|
+
updateCache(groupsIds);
|
|
44
|
+
setData(groupsIds);
|
|
45
|
+
return Promise.resolve(res.data);
|
|
46
|
+
})
|
|
47
|
+
.catch((e) => {
|
|
48
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh the authenticated user groups.');
|
|
49
|
+
Logger.error(SCOPE_SC_CORE, e);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, [data, user, cache]);
|
|
53
|
+
/**
|
|
54
|
+
* Memoized subscribe Group
|
|
55
|
+
* Toggle action
|
|
56
|
+
*/
|
|
57
|
+
const subscribe = useMemo(() => (group) => {
|
|
58
|
+
setLoading(group.id);
|
|
59
|
+
return http
|
|
60
|
+
.request({
|
|
61
|
+
url: Endpoints.SubscribeToGroup.url({ id: group.id }),
|
|
62
|
+
method: Endpoints.SubscribeToGroup.method,
|
|
63
|
+
})
|
|
64
|
+
.then((res) => {
|
|
65
|
+
if (res.status >= 300) {
|
|
66
|
+
return Promise.reject(res);
|
|
67
|
+
}
|
|
68
|
+
updateCache([group.id]);
|
|
69
|
+
const isSubscribed = data.includes(group.id);
|
|
70
|
+
setData((prev) => (isSubscribed ? prev.filter((id) => id !== group.id) : [...[group.id], ...prev]));
|
|
71
|
+
setUnLoading(group.id);
|
|
72
|
+
return Promise.resolve(res.data);
|
|
73
|
+
});
|
|
74
|
+
}, [data, loading, cache]);
|
|
75
|
+
/**
|
|
76
|
+
* Check the authenticated user subscription status to the group
|
|
77
|
+
* Update the groups cached
|
|
78
|
+
* Update groups subscription statuses
|
|
79
|
+
* @param group
|
|
80
|
+
*/
|
|
81
|
+
const checkGroupSubscriptionStatus = (group) => {
|
|
82
|
+
setLoading(group.id);
|
|
83
|
+
return http
|
|
84
|
+
.request({
|
|
85
|
+
url: Endpoints.GetGroupSubscriptionStatus.url({ id: group.id }),
|
|
86
|
+
method: Endpoints.GetGroupSubscriptionStatus.method,
|
|
87
|
+
})
|
|
88
|
+
.then((res) => {
|
|
89
|
+
if (res.status >= 300) {
|
|
90
|
+
return Promise.reject(res);
|
|
91
|
+
}
|
|
92
|
+
setData((prev) => getDataUpdated(prev, group.id, res.data.status));
|
|
93
|
+
updateCache([group.id]);
|
|
94
|
+
setUnLoading(group.id);
|
|
95
|
+
return Promise.resolve(res.data);
|
|
96
|
+
})
|
|
97
|
+
.catch((e) => {
|
|
98
|
+
setUnLoading(group.id);
|
|
99
|
+
return Promise.reject(e);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Get updated data
|
|
104
|
+
* @param data
|
|
105
|
+
* @param groupId
|
|
106
|
+
* @param subscriptionStatus
|
|
107
|
+
*/
|
|
108
|
+
const getDataUpdated = (data, groupId, subscriptionStatus) => {
|
|
109
|
+
const _index = data.findIndex((k) => parseInt(Object.keys(k)[0]) === groupId);
|
|
110
|
+
let _data;
|
|
111
|
+
if (_index < 0) {
|
|
112
|
+
_data = [...data, ...[{ [groupId]: subscriptionStatus }]];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
_data = data.map((k, i) => {
|
|
116
|
+
if (parseInt(Object.keys(k)[0]) === groupId) {
|
|
117
|
+
return { [Object.keys(k)[0]]: subscriptionStatus };
|
|
118
|
+
}
|
|
119
|
+
return { [Object.keys(k)[0]]: data[i][Object.keys(k)[0]] };
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return _data;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Return current group subscription status if exists,
|
|
126
|
+
* otherwise return null
|
|
127
|
+
*/
|
|
128
|
+
const getCurrentGroupCacheStatus = useMemo(() => (group) => {
|
|
129
|
+
const d = data.filter((k) => parseInt(Object.keys(k)[0]) === group.id);
|
|
130
|
+
return d.length ? d[0][group.id] : null;
|
|
131
|
+
}, [data]);
|
|
132
|
+
/**
|
|
133
|
+
* Bypass remote check if the group is subscribed
|
|
134
|
+
*/
|
|
135
|
+
const getSubscriptionStatus = useMemo(() => (group) => {
|
|
136
|
+
updateCache([group.id]);
|
|
137
|
+
setData((prev) => getDataUpdated(prev, group.id, group.subscription_status));
|
|
138
|
+
return group.subscription_status;
|
|
139
|
+
}, [data, cache]);
|
|
140
|
+
/**
|
|
141
|
+
* Memoized subscriptionStatus
|
|
142
|
+
* If group is already in cache -> check if the group is in groups,
|
|
143
|
+
* otherwise, check if user subscribe the group
|
|
144
|
+
*/
|
|
145
|
+
const subscriptionStatus = useMemo(() => (group) => {
|
|
146
|
+
// Cache is valid also for anonymous user
|
|
147
|
+
if (cache.includes(group.id)) {
|
|
148
|
+
return getCurrentGroupCacheStatus(group);
|
|
149
|
+
}
|
|
150
|
+
if (authUserId) {
|
|
151
|
+
if ('subscription_status' in group) {
|
|
152
|
+
return getSubscriptionStatus(group);
|
|
153
|
+
}
|
|
154
|
+
if (!isLoading(group)) {
|
|
155
|
+
checkGroupSubscriptionStatus(group);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}, [data, loading, cache, authUserId]);
|
|
160
|
+
/**
|
|
161
|
+
* Empty cache on logout
|
|
162
|
+
*/
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!authUserId) {
|
|
165
|
+
emptyCache();
|
|
166
|
+
}
|
|
167
|
+
}, [authUserId]);
|
|
168
|
+
if (!user) {
|
|
169
|
+
return { groups: data, loading, isLoading };
|
|
170
|
+
}
|
|
171
|
+
return { groups: data, loading, isLoading, subscribe, subscriptionStatus, refresh, emptyCache };
|
|
172
|
+
}
|
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,7 @@ 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';
|
|
63
64
|
/**
|
|
64
65
|
* Routing component
|
|
65
66
|
*/
|
|
@@ -79,4 +80,4 @@ import * as Locale from './constants/Locale';
|
|
|
79
80
|
/**
|
|
80
81
|
* List all exports
|
|
81
82
|
*/
|
|
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, };
|
|
83
|
+
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, };
|
package/lib/esm/index.js
CHANGED
|
@@ -56,6 +56,7 @@ 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';
|
|
59
60
|
/**
|
|
60
61
|
* Routing component
|
|
61
62
|
*/
|
|
@@ -75,4 +76,4 @@ import * as Locale from './constants/Locale';
|
|
|
75
76
|
/**
|
|
76
77
|
* List all exports
|
|
77
78
|
*/
|
|
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, };
|
|
79
|
+
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, };
|
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,36 @@ 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) => Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Handles a user subscription status to a group, caching data
|
|
271
|
+
*/
|
|
272
|
+
subscriptionStatus?: (group: SCGroupType) => string;
|
|
273
|
+
/**
|
|
274
|
+
* Refresh groups
|
|
275
|
+
*/
|
|
276
|
+
refresh?: () => void;
|
|
277
|
+
/**
|
|
278
|
+
* Empty cache to revalidate all groups
|
|
279
|
+
*/
|
|
280
|
+
emptyCache?: () => void;
|
|
281
|
+
}
|
|
251
282
|
export interface SCConnectionsManagerType {
|
|
252
283
|
/**
|
|
253
284
|
* 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
|
/**
|