@selfcommunity/react-core 0.6.0-alpha.5 → 0.6.0-alpha.6

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.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const react_1 = require("react");
4
- const Errors_1 = require("../constants/Errors");
5
- const types_1 = require("@selfcommunity/types");
6
3
  const api_services_1 = require("@selfcommunity/api-services");
4
+ const types_1 = require("@selfcommunity/types");
7
5
  const utils_1 = require("@selfcommunity/utils");
8
- const Cache_1 = require("../constants/Cache");
6
+ const react_1 = require("react");
9
7
  const use_deep_compare_effect_1 = require("use-deep-compare-effect");
10
8
  const SCUserProvider_1 = require("../components/provider/SCUserProvider");
9
+ const Cache_1 = require("../constants/Cache");
10
+ const Errors_1 = require("../constants/Errors");
11
11
  /**
12
12
  :::info
13
13
  This custom hook is used to fetch an event object.
@@ -57,10 +57,10 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
57
57
  /**
58
58
  * Memoized fetchTag
59
59
  */
60
- const fetchEvent = (0, react_1.useMemo)(() => () => {
60
+ const fetchEvent = (0, react_1.useMemo)(() => (id) => {
61
61
  return api_services_1.http
62
62
  .request({
63
- url: api_services_1.Endpoints.GetEventInfo.url({ id: __eventId }),
63
+ url: api_services_1.Endpoints.GetEventInfo.url({ id }),
64
64
  method: api_services_1.Endpoints.GetEventInfo.method,
65
65
  })
66
66
  .then((res) => {
@@ -69,13 +69,13 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
69
69
  }
70
70
  return Promise.resolve(res.data);
71
71
  });
72
- }, [__eventId]);
72
+ }, []);
73
73
  /**
74
74
  * If id attempt to get the event by id
75
75
  */
76
76
  (0, react_1.useEffect)(() => {
77
- if ((__eventId === null || __eventId === void 0 ? void 0 : __eventId.toString()) !== undefined && !event) {
78
- fetchEvent()
77
+ if (id !== null && id !== undefined && !event) {
78
+ fetchEvent(id)
79
79
  .then((e) => {
80
80
  setSCEvent(e);
81
81
  })
@@ -86,7 +86,7 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
86
86
  utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
87
87
  });
88
88
  }
89
- }, [__eventId, event]);
89
+ }, [id, event, authUserId]);
90
90
  (0, use_deep_compare_effect_1.useDeepCompareEffectNoCheck)(() => {
91
91
  if (event) {
92
92
  setSCEvent(event);
@@ -1,11 +1,11 @@
1
- import { useEffect, useMemo, useState } from 'react';
2
- import { SCOPE_SC_CORE } from '../constants/Errors';
3
- import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
4
1
  import { Endpoints, EventService, http } from '@selfcommunity/api-services';
2
+ import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
5
3
  import { CacheStrategies, Logger, LRUCache, objectWithoutProperties } from '@selfcommunity/utils';
6
- import { getEventObjectCacheKey } from '../constants/Cache';
4
+ import { useEffect, useMemo, useState } from 'react';
7
5
  import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect';
8
6
  import { useSCUser } from '../components/provider/SCUserProvider';
7
+ import { getEventObjectCacheKey } from '../constants/Cache';
8
+ import { SCOPE_SC_CORE } from '../constants/Errors';
9
9
  /**
10
10
  :::info
11
11
  This custom hook is used to fetch an event object.
@@ -55,10 +55,10 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
55
55
  /**
56
56
  * Memoized fetchTag
57
57
  */
58
- const fetchEvent = useMemo(() => () => {
58
+ const fetchEvent = useMemo(() => (id) => {
59
59
  return http
60
60
  .request({
61
- url: Endpoints.GetEventInfo.url({ id: __eventId }),
61
+ url: Endpoints.GetEventInfo.url({ id }),
62
62
  method: Endpoints.GetEventInfo.method,
63
63
  })
64
64
  .then((res) => {
@@ -67,13 +67,13 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
67
67
  }
68
68
  return Promise.resolve(res.data);
69
69
  });
70
- }, [__eventId]);
70
+ }, []);
71
71
  /**
72
72
  * If id attempt to get the event by id
73
73
  */
74
74
  useEffect(() => {
75
- if ((__eventId === null || __eventId === void 0 ? void 0 : __eventId.toString()) !== undefined && !event) {
76
- fetchEvent()
75
+ if (id !== null && id !== undefined && !event) {
76
+ fetchEvent(id)
77
77
  .then((e) => {
78
78
  setSCEvent(e);
79
79
  })
@@ -84,7 +84,7 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
84
84
  Logger.error(SCOPE_SC_CORE, err.message);
85
85
  });
86
86
  }
87
- }, [__eventId, event]);
87
+ }, [id, event, authUserId]);
88
88
  useDeepCompareEffectNoCheck(() => {
89
89
  if (event) {
90
90
  setSCEvent(event);