@selfcommunity/react-core 0.5.1-alpha.0 → 0.6.0-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.
@@ -69,6 +69,7 @@ export declare const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uOtherEvents_"
69
69
  export declare const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uPartecipantsEvents_";
70
70
  export declare const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = "_uInvitedEvents_";
71
71
  export declare const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uRequestsEvents_";
72
+ export declare const EVENT_MEDIA_STATE_CACHE_PREFIX_KEY = "_eMedia_";
72
73
  export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
73
74
  export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
74
75
  export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
@@ -4,7 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_EVENTS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_FOLLOWERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_POPULAR_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_FOLLOWED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.CATEGORIES_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.getPmSnippetObjectCacheKey = exports.PM_SNIPPET_OBJECT_CACHE_PREFIX_KEY = exports.getPmSnippetsObjectCacheKey = exports.PM_SNIPPETS_OBJECT_CACHE_PREFIX_KEY = exports.getAdvObjectCacheKey = exports.ADV_OBJECT_CACHE_PREFIX_KEY = exports.getFeedSPCacheKey = exports.FEED_CACHE_SP_KEY = exports.getVirtualizedScrollStateCacheKey = exports.VIRTUALIZED_SCROLL_STATE_CACHE_PREFIX_KEY = exports.getStateFeedCacheKey = exports.FEED_STATE_CACHE_PREFIX_KEY = exports.getFeedCacheKey = exports.FEED_CACHE_PREFIX_KEY = exports.getBroadcastMessagesObjectCacheKey = exports.BROADCAST_MESSAGES_OBJECT_CACHE_PREFIX_KEY = exports.getContributorsCachePrefixKeys = exports.getContributorsCacheKey = exports.CONTRIBUTORS_CACHE_PREFIX_KEY = exports.getIncubatorObjectCacheKey = exports.INCUBATOR_OBJECT_CACHE_PREFIX_KEY = exports.getGroupsObjectCacheKey = exports.GROUPS_OBJECT_CACHE_PREFIX_KEY = exports.getGroupObjectCacheKey = exports.GROUP_OBJECT_CACHE_PREFIX_KEY = exports.getEventsObjectCacheKey = exports.EVENTS_OBJECT_CACHE_PREFIX_KEY = exports.getEventObjectCacheKey = exports.EVENT_OBJECT_CACHE_PREFIX_KEY = exports.getCategoryObjectCacheKey = exports.CATEGORY_OBJECT_CACHE_PREFIX_KEY = exports.getCategoriesObjectCacheKey = exports.CATEGORIES_OBJECT_CACHE_PREFIX_KEY = exports.getCommentObjectsCachePrefixKeys = exports.getCommentObjectsCacheKey = exports.COMMENT_OBJECTS_CACHE_PREFIX_KEY = exports.getCommentObjectCacheKey = exports.COMMENT_OBJECT_CACHE_PREFIX_KEY = exports.getFeedObjectCacheKey = exports.FEED_OBJECT_CACHE_PREFIX_KEY = void 0;
7
- exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_PEOPLE_TOOLS_STATE_CACHE_PREFIX_KEY = exports.RELATED_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = void 0;
7
+ exports.getWidgetStateCacheKey = exports.GROUPS_SUBSCRIBED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.GROUP_MEMBERS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.POLL_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.INCUBATOR_LIST_TOOLS_STATE_CACHE_PREFIX_KEY = exports.PEOPLE_SUGGESTION_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_PEOPLE_TOOLS_STATE_CACHE_PREFIX_KEY = exports.RELATED_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.TRENDING_FEED_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = exports.EVENT_MEDIA_STATE_CACHE_PREFIX_KEY = exports.USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = void 0;
8
8
  /** FEED OBJECT **/
9
9
  exports.FEED_OBJECT_CACHE_PREFIX_KEY = '_fo_';
10
10
  const getFeedObjectCacheKey = (id, type) => `${exports.FEED_OBJECT_CACHE_PREFIX_KEY}${type}_${id}`;
@@ -98,6 +98,7 @@ exports.USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uOtherEvents_';
98
98
  exports.USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uPartecipantsEvents_';
99
99
  exports.USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = '_uInvitedEvents_';
100
100
  exports.USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uRequestsEvents_';
101
+ exports.EVENT_MEDIA_STATE_CACHE_PREFIX_KEY = '_eMedia_';
101
102
  exports.USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
102
103
  exports.USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
103
104
  exports.USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
@@ -17,6 +17,6 @@ export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrateg
17
17
  cacheStrategy?: CacheStrategies;
18
18
  }): {
19
19
  scEvent: SCEventType;
20
- setSCEvent: (event: SCEventType) => void;
20
+ setSCEvent: (e: SCEventType) => void;
21
21
  error: string;
22
22
  };
@@ -19,6 +19,7 @@ const SCUserProvider_1 = require("../components/provider/SCUserProvider");
19
19
  * @param object.cacheStrategy
20
20
  */
21
21
  function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, }) {
22
+ console.log('Params: ', event, id);
22
23
  const __eventId = event ? event.id : id;
23
24
  // CONTEXT
24
25
  const scUserContext = (0, SCUserProvider_1.useSCUser)();
@@ -28,11 +29,27 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
28
29
  const __event = authUserId ? event : (0, utils_1.objectWithoutProperties)(event, ['subscription_status']);
29
30
  const [scEvent, setScEvent] = (0, react_1.useState)(cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? utils_1.LRUCache.get(__eventCacheKey, __event) : null);
30
31
  const [error, setError] = (0, react_1.useState)(null);
31
- const setSCEvent = (event) => {
32
- const _e = authUserId ? event : (0, utils_1.objectWithoutProperties)(event, ['subscription_status']);
33
- setScEvent(_e);
34
- utils_1.LRUCache.set(__eventCacheKey, _e);
35
- };
32
+ /**
33
+ * Memoized setSCEvent (auto-subscription if need it)
34
+ */
35
+ const setSCEvent = (0, react_1.useMemo)(() => (e) => {
36
+ if (autoSubscribe &&
37
+ authUserId !== null &&
38
+ ((e.privacy === types_1.SCEventPrivacyType.PUBLIC && !e.subscription_status) || e.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) {
39
+ // Auto subscribe to the event
40
+ api_services_1.EventService.subscribeToEvent(e.id).then(() => {
41
+ const updatedEvent = Object.assign(Object.assign({}, e), { subscription_status: types_1.SCEventSubscriptionStatusType.SUBSCRIBED });
42
+ console.log('Update event', updatedEvent.id);
43
+ setScEvent(updatedEvent);
44
+ utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
45
+ });
46
+ }
47
+ else {
48
+ const updatedEvent = authUserId ? e : (0, utils_1.objectWithoutProperties)(e, ['subscription_status']);
49
+ setScEvent(updatedEvent);
50
+ utils_1.LRUCache.set(__eventCacheKey, updatedEvent);
51
+ }
52
+ }, [autoSubscribe, authUserId, setScEvent]);
36
53
  /**
37
54
  * Memoized fetchTag
38
55
  */
@@ -53,21 +70,10 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
53
70
  * If id attempt to get the event by id
54
71
  */
55
72
  (0, react_1.useEffect)(() => {
56
- if (__eventId && scUserContext.user !== undefined && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
73
+ if ((__eventId === null || __eventId === void 0 ? void 0 : __eventId.toString()) !== undefined && !event) {
57
74
  fetchEvent()
58
- .then((event) => {
59
- if (autoSubscribe &&
60
- authUserId !== null &&
61
- ((event.privacy === types_1.SCEventPrivacyType.PUBLIC && !event.subscription_status) || event.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) {
62
- // Auto subscribe to the event
63
- api_services_1.EventService.subscribeToEvent(event.id).then(() => {
64
- const updatedEvent = Object.assign(Object.assign({}, event), { subscription_status: types_1.SCEventSubscriptionStatusType.SUBSCRIBED });
65
- setSCEvent(updatedEvent);
66
- });
67
- }
68
- else {
69
- setSCEvent(event);
70
- }
75
+ .then((e) => {
76
+ setSCEvent(e);
71
77
  })
72
78
  .catch((err) => {
73
79
  utils_1.LRUCache.delete(__eventCacheKey);
@@ -76,7 +82,7 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
76
82
  utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
77
83
  });
78
84
  }
79
- }, [__eventId, authUserId, scUserContext.user]);
85
+ }, [__eventId, event]);
80
86
  (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
81
87
  if (event) {
82
88
  setSCEvent(event);
@@ -69,6 +69,7 @@ export declare const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = "_uOtherEvents_"
69
69
  export declare const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uPartecipantsEvents_";
70
70
  export declare const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = "_uInvitedEvents_";
71
71
  export declare const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = "_uRequestsEvents_";
72
+ export declare const EVENT_MEDIA_STATE_CACHE_PREFIX_KEY = "_eMedia_";
72
73
  export declare const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConWidget_";
73
74
  export declare const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqWidget_";
74
75
  export declare const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = "_uConReqSentWidget_";
@@ -73,6 +73,7 @@ export const USER_OTHER_EVENTS_STATE_CACHE_PREFIX_KEY = '_uOtherEvents_';
73
73
  export const USER_PARTECIPANTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uPartecipantsEvents_';
74
74
  export const USER_INVITED_EVENTS_STATE_CACHE_PREFIX_KEY = '_uInvitedEvents_';
75
75
  export const USER_REQUESTS_EVENTS_STATE_CACHE_PREFIX_KEY = '_uRequestsEvents_';
76
+ export const EVENT_MEDIA_STATE_CACHE_PREFIX_KEY = '_eMedia_';
76
77
  export const USER_CONNECTIONS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConWidget_';
77
78
  export const USER_CONNECTIONS_REQUESTS_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqWidget_';
78
79
  export const USER_CONNECTIONS_REQUESTS_SENT_TOOLS_STATE_CACHE_PREFIX_KEY = '_uConReqSentWidget_';
@@ -17,6 +17,6 @@ export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrateg
17
17
  cacheStrategy?: CacheStrategies;
18
18
  }): {
19
19
  scEvent: SCEventType;
20
- setSCEvent: (event: SCEventType) => void;
20
+ setSCEvent: (e: SCEventType) => void;
21
21
  error: string;
22
22
  };
@@ -17,6 +17,7 @@ import { useSCUser } from '../components/provider/SCUserProvider';
17
17
  * @param object.cacheStrategy
18
18
  */
19
19
  export default function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheStrategy = CacheStrategies.CACHE_FIRST, }) {
20
+ console.log('Params: ', event, id);
20
21
  const __eventId = event ? event.id : id;
21
22
  // CONTEXT
22
23
  const scUserContext = useSCUser();
@@ -26,11 +27,27 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
26
27
  const __event = authUserId ? event : objectWithoutProperties(event, ['subscription_status']);
27
28
  const [scEvent, setScEvent] = useState(cacheStrategy !== CacheStrategies.NETWORK_ONLY ? LRUCache.get(__eventCacheKey, __event) : null);
28
29
  const [error, setError] = useState(null);
29
- const setSCEvent = (event) => {
30
- const _e = authUserId ? event : objectWithoutProperties(event, ['subscription_status']);
31
- setScEvent(_e);
32
- LRUCache.set(__eventCacheKey, _e);
33
- };
30
+ /**
31
+ * Memoized setSCEvent (auto-subscription if need it)
32
+ */
33
+ const setSCEvent = useMemo(() => (e) => {
34
+ if (autoSubscribe &&
35
+ authUserId !== null &&
36
+ ((e.privacy === SCEventPrivacyType.PUBLIC && !e.subscription_status) || e.subscription_status === SCEventSubscriptionStatusType.INVITED)) {
37
+ // Auto subscribe to the event
38
+ EventService.subscribeToEvent(e.id).then(() => {
39
+ const updatedEvent = Object.assign(Object.assign({}, e), { subscription_status: SCEventSubscriptionStatusType.SUBSCRIBED });
40
+ console.log('Update event', updatedEvent.id);
41
+ setScEvent(updatedEvent);
42
+ LRUCache.set(__eventCacheKey, updatedEvent);
43
+ });
44
+ }
45
+ else {
46
+ const updatedEvent = authUserId ? e : objectWithoutProperties(e, ['subscription_status']);
47
+ setScEvent(updatedEvent);
48
+ LRUCache.set(__eventCacheKey, updatedEvent);
49
+ }
50
+ }, [autoSubscribe, authUserId, setScEvent]);
34
51
  /**
35
52
  * Memoized fetchTag
36
53
  */
@@ -51,21 +68,10 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
51
68
  * If id attempt to get the event by id
52
69
  */
53
70
  useEffect(() => {
54
- if (__eventId && scUserContext.user !== undefined && (!scEvent || (scEvent && __eventId !== scEvent.id))) {
71
+ if ((__eventId === null || __eventId === void 0 ? void 0 : __eventId.toString()) !== undefined && !event) {
55
72
  fetchEvent()
56
- .then((event) => {
57
- if (autoSubscribe &&
58
- authUserId !== null &&
59
- ((event.privacy === SCEventPrivacyType.PUBLIC && !event.subscription_status) || event.subscription_status === SCEventSubscriptionStatusType.INVITED)) {
60
- // Auto subscribe to the event
61
- EventService.subscribeToEvent(event.id).then(() => {
62
- const updatedEvent = Object.assign(Object.assign({}, event), { subscription_status: SCEventSubscriptionStatusType.SUBSCRIBED });
63
- setSCEvent(updatedEvent);
64
- });
65
- }
66
- else {
67
- setSCEvent(event);
68
- }
73
+ .then((e) => {
74
+ setSCEvent(e);
69
75
  })
70
76
  .catch((err) => {
71
77
  LRUCache.delete(__eventCacheKey);
@@ -74,7 +80,7 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
74
80
  Logger.error(SCOPE_SC_CORE, err.message);
75
81
  });
76
82
  }
77
- }, [__eventId, authUserId, scUserContext.user]);
83
+ }, [__eventId, event]);
78
84
  useDeepCompareEffectNoCheck(() => {
79
85
  if (event) {
80
86
  setSCEvent(event);