@selfcommunity/react-core 0.4.9-alpha.41 → 0.4.9-alpha.43

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.
@@ -3,8 +3,6 @@ import { CacheStrategies } from '@selfcommunity/utils';
3
3
  /**
4
4
  :::info
5
5
  This custom hook is used to fetch categories.
6
- @param object
7
- @param object.cacheStrategy
8
6
 
9
7
  :::tip Context can be consumed in this way:
10
8
 
@@ -12,6 +10,7 @@ import { CacheStrategies } from '@selfcommunity/utils';
12
10
  const {categories, isLoading} = useSCFetchCategories();
13
11
  ```
14
12
  :::
13
+ * @param props
15
14
  */
16
15
  declare const useSCFetchCategories: (props?: {
17
16
  cacheStrategy?: CacheStrategies;
@@ -25,8 +25,6 @@ const hydrate = (ids) => {
25
25
  /**
26
26
  :::info
27
27
  This custom hook is used to fetch categories.
28
- @param object
29
- @param object.cacheStrategy
30
28
 
31
29
  :::tip Context can be consumed in this way:
32
30
 
@@ -34,6 +32,7 @@ const hydrate = (ids) => {
34
32
  const {categories, isLoading} = useSCFetchCategories();
35
33
  ```
36
34
  :::
35
+ * @param props
37
36
  */
38
37
  const useSCFetchCategories = (props) => {
39
38
  // PROPS
@@ -47,15 +46,8 @@ const useSCFetchCategories = (props) => {
47
46
  * Fetch categories
48
47
  */
49
48
  const fetchCategories = (next = api_services_1.Endpoints.CategoryList.url()) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
50
- const response = yield api_services_1.http.request({
51
- url: next,
52
- method: api_services_1.Endpoints.CategoryList.method,
53
- });
54
- const data = response.data;
55
- if (data.next) {
56
- return data.results.concat(yield fetchCategories(data.next));
57
- }
58
- return data.results;
49
+ const data = yield api_services_1.CategoryService.getAllCategories({ active: true }, { url: next });
50
+ return data.next ? data.results.concat(yield fetchCategories(data.next)) : data.results;
59
51
  });
60
52
  /**
61
53
  * Get categories
@@ -3,8 +3,6 @@ import { CacheStrategies } from '@selfcommunity/utils';
3
3
  /**
4
4
  :::info
5
5
  This custom hook is used to fetch categories.
6
- @param object
7
- @param object.cacheStrategy
8
6
 
9
7
  :::tip Context can be consumed in this way:
10
8
 
@@ -12,6 +10,7 @@ import { CacheStrategies } from '@selfcommunity/utils';
12
10
  const {categories, isLoading} = useSCFetchCategories();
13
11
  ```
14
12
  :::
13
+ * @param props
15
14
  */
16
15
  declare const useSCFetchCategories: (props?: {
17
16
  cacheStrategy?: CacheStrategies;
@@ -1,7 +1,7 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import { useEffect, useState } from 'react';
3
3
  import { SCOPE_SC_CORE } from '../constants/Errors';
4
- import { Endpoints, http } from '@selfcommunity/api-services';
4
+ import { CategoryService, Endpoints } from '@selfcommunity/api-services';
5
5
  import { CacheStrategies, Logger, LRUCache } from '@selfcommunity/utils';
6
6
  import { getCategoriesObjectCacheKey, getCategoryObjectCacheKey } from '../constants/Cache';
7
7
  const init = { categories: [], isLoading: true };
@@ -23,8 +23,6 @@ const hydrate = (ids) => {
23
23
  /**
24
24
  :::info
25
25
  This custom hook is used to fetch categories.
26
- @param object
27
- @param object.cacheStrategy
28
26
 
29
27
  :::tip Context can be consumed in this way:
30
28
 
@@ -32,6 +30,7 @@ const hydrate = (ids) => {
32
30
  const {categories, isLoading} = useSCFetchCategories();
33
31
  ```
34
32
  :::
33
+ * @param props
35
34
  */
36
35
  const useSCFetchCategories = (props) => {
37
36
  // PROPS
@@ -45,15 +44,8 @@ const useSCFetchCategories = (props) => {
45
44
  * Fetch categories
46
45
  */
47
46
  const fetchCategories = (next = Endpoints.CategoryList.url()) => __awaiter(void 0, void 0, void 0, function* () {
48
- const response = yield http.request({
49
- url: next,
50
- method: Endpoints.CategoryList.method,
51
- });
52
- const data = response.data;
53
- if (data.next) {
54
- return data.results.concat(yield fetchCategories(data.next));
55
- }
56
- return data.results;
47
+ const data = yield CategoryService.getAllCategories({ active: true }, { url: next });
48
+ return data.next ? data.results.concat(yield fetchCategories(data.next)) : data.results;
57
49
  });
58
50
  /**
59
51
  * Get categories