@selfcommunity/react-core 0.6.4-courses.185 → 0.6.4-courses.186
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,7 +3,7 @@ import { SCCourseType } from '@selfcommunity/types';
|
|
|
3
3
|
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
4
|
/**
|
|
5
5
|
:::info
|
|
6
|
-
This custom hook is used to fetch
|
|
6
|
+
This custom hook is used to fetch a course object.
|
|
7
7
|
:::
|
|
8
8
|
* @param object
|
|
9
9
|
* @param object.id
|
|
@@ -20,4 +20,5 @@ export default function useSCFetchCourse({ id, course, cacheStrategy, params, }:
|
|
|
20
20
|
scCourse: SCCourseType;
|
|
21
21
|
setSCCourse: (c: SCCourseType) => void;
|
|
22
22
|
error: string;
|
|
23
|
+
refreshCourse: () => void;
|
|
23
24
|
};
|
|
@@ -9,7 +9,7 @@ const Cache_1 = require("../constants/Cache");
|
|
|
9
9
|
const Errors_1 = require("../constants/Errors");
|
|
10
10
|
/**
|
|
11
11
|
:::info
|
|
12
|
-
This custom hook is used to fetch
|
|
12
|
+
This custom hook is used to fetch a course object.
|
|
13
13
|
:::
|
|
14
14
|
* @param object
|
|
15
15
|
* @param object.id
|
|
@@ -76,6 +76,21 @@ function useSCFetchCourse({ id = null, course = null, cacheStrategy = utils_1.Ca
|
|
|
76
76
|
setSCCourse(course);
|
|
77
77
|
}
|
|
78
78
|
}, [course, authUserId]);
|
|
79
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Refreshes course data from the network
|
|
81
|
+
*/
|
|
82
|
+
const refreshCourse = (0, react_1.useCallback)(() => {
|
|
83
|
+
if (id) {
|
|
84
|
+
fetchCourse(id)
|
|
85
|
+
.then((e) => {
|
|
86
|
+
setSCCourse(e);
|
|
87
|
+
})
|
|
88
|
+
.catch((err) => {
|
|
89
|
+
setError(`Failed to refresh course data: ${err.message}`);
|
|
90
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}, [id, fetchCourse]);
|
|
94
|
+
return { scCourse, setSCCourse, error, refreshCourse };
|
|
80
95
|
}
|
|
81
96
|
exports.default = useSCFetchCourse;
|
|
@@ -3,7 +3,7 @@ import { SCCourseType } from '@selfcommunity/types';
|
|
|
3
3
|
import { CacheStrategies } from '@selfcommunity/utils';
|
|
4
4
|
/**
|
|
5
5
|
:::info
|
|
6
|
-
This custom hook is used to fetch
|
|
6
|
+
This custom hook is used to fetch a course object.
|
|
7
7
|
:::
|
|
8
8
|
* @param object
|
|
9
9
|
* @param object.id
|
|
@@ -20,4 +20,5 @@ export default function useSCFetchCourse({ id, course, cacheStrategy, params, }:
|
|
|
20
20
|
scCourse: SCCourseType;
|
|
21
21
|
setSCCourse: (c: SCCourseType) => void;
|
|
22
22
|
error: string;
|
|
23
|
+
refreshCourse: () => void;
|
|
23
24
|
};
|
|
@@ -7,7 +7,7 @@ import { getCourseObjectCacheKey } from '../constants/Cache';
|
|
|
7
7
|
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
8
8
|
/**
|
|
9
9
|
:::info
|
|
10
|
-
This custom hook is used to fetch
|
|
10
|
+
This custom hook is used to fetch a course object.
|
|
11
11
|
:::
|
|
12
12
|
* @param object
|
|
13
13
|
* @param object.id
|
|
@@ -74,5 +74,20 @@ export default function useSCFetchCourse({ id = null, course = null, cacheStrate
|
|
|
74
74
|
setSCCourse(course);
|
|
75
75
|
}
|
|
76
76
|
}, [course, authUserId]);
|
|
77
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Refreshes course data from the network
|
|
79
|
+
*/
|
|
80
|
+
const refreshCourse = useCallback(() => {
|
|
81
|
+
if (id) {
|
|
82
|
+
fetchCourse(id)
|
|
83
|
+
.then((e) => {
|
|
84
|
+
setSCCourse(e);
|
|
85
|
+
})
|
|
86
|
+
.catch((err) => {
|
|
87
|
+
setError(`Failed to refresh course data: ${err.message}`);
|
|
88
|
+
Logger.error(SCOPE_SC_CORE, err.message);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}, [id, fetchCourse]);
|
|
92
|
+
return { scCourse, setSCCourse, error, refreshCourse };
|
|
78
93
|
}
|