@selfcommunity/react-core 0.6.7-alpha.12 → 0.6.7-alpha.14

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,4 +1,5 @@
1
1
  import { SCCategoryType } from '@selfcommunity/types';
2
+ import { CategoryParams } from '@selfcommunity/api-services';
2
3
  import { CacheStrategies } from '@selfcommunity/utils';
3
4
  /**
4
5
  :::info
@@ -14,6 +15,7 @@ import { CacheStrategies } from '@selfcommunity/utils';
14
15
  */
15
16
  declare const useSCFetchCategories: (props?: {
16
17
  cacheStrategy?: CacheStrategies;
18
+ endpointQueryParams?: CategoryParams;
17
19
  }) => {
18
20
  categories: SCCategoryType[];
19
21
  isLoading: boolean;
@@ -8,7 +8,7 @@ const utils_1 = require("@selfcommunity/utils");
8
8
  const Cache_1 = require("../constants/Cache");
9
9
  const init = { categories: [], isLoading: true };
10
10
  // HYDRATE the cache
11
- const hydrate = (ids) => {
11
+ const hydrate = (ids, endpointQueryParams) => {
12
12
  if (!ids) {
13
13
  return null;
14
14
  }
@@ -20,6 +20,9 @@ const hydrate = (ids) => {
20
20
  // REVALIDATE CACHE
21
21
  return null;
22
22
  }
23
+ if (endpointQueryParams === null || endpointQueryParams === void 0 ? void 0 : endpointQueryParams.can_create_content) {
24
+ return categories.filter((c) => c.content_only_staff);
25
+ }
23
26
  return categories;
24
27
  };
25
28
  /**
@@ -36,17 +39,17 @@ const hydrate = (ids) => {
36
39
  */
37
40
  const useSCFetchCategories = (props) => {
38
41
  // PROPS
39
- const { cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST } = props || {};
42
+ const { cacheStrategy = utils_1.CacheStrategies.CACHE_FIRST, endpointQueryParams = {} } = props || {};
40
43
  // CACHE
41
44
  const __categoriesCacheKey = (0, Cache_1.getCategoriesObjectCacheKey)();
42
45
  // STATE
43
- const categories = cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? hydrate(utils_1.LRUCache.get(__categoriesCacheKey, null)) : null;
46
+ const categories = cacheStrategy !== utils_1.CacheStrategies.NETWORK_ONLY ? hydrate(utils_1.LRUCache.get(__categoriesCacheKey, null), endpointQueryParams) : null;
44
47
  const [data, setData] = (0, react_1.useState)(categories !== null ? { categories, isLoading: false } : init);
45
48
  /**
46
49
  * Fetch categories
47
50
  */
48
51
  const fetchCategories = (next = api_services_1.Endpoints.CategoryList.url()) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
49
- const data = yield api_services_1.CategoryService.getAllCategories({ active: true }, { url: next });
52
+ const data = yield api_services_1.CategoryService.getAllCategories(Object.assign({ active: true }, endpointQueryParams), { url: next });
50
53
  return data.next ? data.results.concat(yield fetchCategories(data.next)) : data.results;
51
54
  });
52
55
  /**
@@ -71,7 +71,7 @@ function useSCFetchUserBlockedBy({ user = null, blockedByUser = null, sync = tru
71
71
  */
72
72
  (0, react_1.useEffect)(() => {
73
73
  let interval;
74
- if (scUserContext.user && blockedBy !== null && sync) {
74
+ if (scUserContext.user && scUserContext.user.id !== (user === null || user === void 0 ? void 0 : user.id) && blockedBy !== null && sync) {
75
75
  interval = setInterval(() => {
76
76
  fetchUserBlockedBy(user, false);
77
77
  }, 5000);
@@ -1,4 +1,5 @@
1
1
  import { SCCategoryType } from '@selfcommunity/types';
2
+ import { CategoryParams } from '@selfcommunity/api-services';
2
3
  import { CacheStrategies } from '@selfcommunity/utils';
3
4
  /**
4
5
  :::info
@@ -14,6 +15,7 @@ import { CacheStrategies } from '@selfcommunity/utils';
14
15
  */
15
16
  declare const useSCFetchCategories: (props?: {
16
17
  cacheStrategy?: CacheStrategies;
18
+ endpointQueryParams?: CategoryParams;
17
19
  }) => {
18
20
  categories: SCCategoryType[];
19
21
  isLoading: boolean;
@@ -6,7 +6,7 @@ import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
6
6
  import { getCategoriesObjectCacheKey, getCategoryObjectCacheKey } from '../constants/Cache';
7
7
  const init = { categories: [], isLoading: true };
8
8
  // HYDRATE the cache
9
- const hydrate = (ids) => {
9
+ const hydrate = (ids, endpointQueryParams) => {
10
10
  if (!ids) {
11
11
  return null;
12
12
  }
@@ -18,6 +18,9 @@ const hydrate = (ids) => {
18
18
  // REVALIDATE CACHE
19
19
  return null;
20
20
  }
21
+ if (endpointQueryParams === null || endpointQueryParams === void 0 ? void 0 : endpointQueryParams.can_create_content) {
22
+ return categories.filter((c) => c.content_only_staff);
23
+ }
21
24
  return categories;
22
25
  };
23
26
  /**
@@ -34,17 +37,17 @@ const hydrate = (ids) => {
34
37
  */
35
38
  const useSCFetchCategories = (props) => {
36
39
  // PROPS
37
- const { cacheStrategy = CacheStrategies.CACHE_FIRST } = props || {};
40
+ const { cacheStrategy = CacheStrategies.CACHE_FIRST, endpointQueryParams = {} } = props || {};
38
41
  // CACHE
39
42
  const __categoriesCacheKey = getCategoriesObjectCacheKey();
40
43
  // STATE
41
- const categories = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__categoriesCacheKey, null)) : null;
44
+ const categories = cacheStrategy !== CacheStrategies.NETWORK_ONLY ? hydrate(LRUCache.get(__categoriesCacheKey, null), endpointQueryParams) : null;
42
45
  const [data, setData] = useState(categories !== null ? { categories, isLoading: false } : init);
43
46
  /**
44
47
  * Fetch categories
45
48
  */
46
49
  const fetchCategories = (next = Endpoints.CategoryList.url()) => __awaiter(void 0, void 0, void 0, function* () {
47
- const data = yield CategoryService.getAllCategories({ active: true }, { url: next });
50
+ const data = yield CategoryService.getAllCategories(Object.assign({ active: true }, endpointQueryParams), { url: next });
48
51
  return data.next ? data.results.concat(yield fetchCategories(data.next)) : data.results;
49
52
  });
50
53
  /**
@@ -69,7 +69,7 @@ export default function useSCFetchUserBlockedBy({ user = null, blockedByUser = n
69
69
  */
70
70
  useEffect(() => {
71
71
  let interval;
72
- if (scUserContext.user && blockedBy !== null && sync) {
72
+ if (scUserContext.user && scUserContext.user.id !== (user === null || user === void 0 ? void 0 : user.id) && blockedBy !== null && sync) {
73
73
  interval = setInterval(() => {
74
74
  fetchUserBlockedBy(user, false);
75
75
  }, 5000);