@elice/material-shared-utils 1.230208.0-style.1 → 1.230217.0-sepmatlec.0

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.
package/cjs/index.js CHANGED
@@ -9,7 +9,7 @@ var useMaterialConfig = require('./material-config/useMaterialConfig.js');
9
9
  var useMaterialConfigApiClientUpdate = require('./material-config/useMaterialConfigApiClientUpdate.js');
10
10
  var utils = require('./material-config/utils.js');
11
11
  var useMaterialFetch = require('./material-fetch/useMaterialFetch.js');
12
- var useMaterialInitFetch = require('./material-fetch/useMaterialInitFetch.js');
12
+ var useMaterialFetchRaw = require('./material-fetch/useMaterialFetchRaw.js');
13
13
  var withMaterial = require('./material-hoc/withMaterial.js');
14
14
 
15
15
 
@@ -21,6 +21,6 @@ exports.useMaterialConfig = useMaterialConfig.useMaterialConfig;
21
21
  exports.useMaterialConfigApiClientUpdate = useMaterialConfigApiClientUpdate.useMaterialConfigApiClientUpdate;
22
22
  exports.updateMaterialConfigSessionKey = utils.updateMaterialConfigSessionKey;
23
23
  exports.useMaterialFetch = useMaterialFetch.useMaterialFetch;
24
- exports.useMaterialInitFetch = useMaterialInitFetch.useMaterialInitFetch;
24
+ exports.useMaterialFetchRaw = useMaterialFetchRaw.useMaterialFetchRaw;
25
25
  exports.withForwardRefMaterial = withMaterial.withForwardRefMaterial;
26
26
  exports.withMaterial = withMaterial.withMaterial;
@@ -1,2 +1,2 @@
1
1
  export * from './useMaterialFetch';
2
- export * from './useMaterialInitFetch';
2
+ export * from './useMaterialFetchRaw';
@@ -1,21 +1,69 @@
1
- import type { EliceApiResponse } from '@elice/api-client';
2
- import type { APIStatus } from '@elice/material-shared-types';
3
- declare type FetchFn<R> = (signal: AbortSignal) => Promise<EliceApiResponse<R>>;
1
+ import type { EliceApiClientConfigs, EliceApiResponse } from '@elice/api-client';
2
+ declare type FetchClientInitializer = (config: EliceApiClientConfigs) => void;
4
3
  /**
5
4
  * Init api client and fetch material for contaner.
6
5
  *
7
- * @param fn API client wrapped with `React.useCallback` to fetch material.
8
- * @param isReady Is ready to fetch material.
9
- *
10
6
  * @example
11
- * const [materialPdf, materialPdfStatus] =
12
- * useMaterialFetch<GetOrgMaterialPdfGetResponses>(
7
+ * const { materialPdf, materialLecturePage, status ] =
8
+ * useMaterialFetch(
9
+ * 'materialPdf',
13
10
  * React.useCallback(
14
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
11
+ * signal =>
12
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
13
+ * { materialPdfId },
14
+ * { signal }
15
+ * ),
15
16
  * [materialPdfId]
16
17
  * ),
17
- * isReady // boolean
18
+ * eliceApiClientConfigs.init
18
19
  * );
19
20
  */
20
- export declare const useMaterialFetch: <R = any>(fn: FetchFn<R>, isReady?: boolean) => [R | null, APIStatus];
21
+ export declare const useMaterialFetch: <K extends string, R extends Record<K, Record<string, any>> = Record<K, Record<string, any>>>(materialKey: K, materialFetchFn: (signal?: AbortSignal | undefined) => Promise<EliceApiResponse<R>>, init: FetchClientInitializer) => Record<K, R[K] | null> & {
22
+ materialLecturePage: {
23
+ certificateDescription: string | null;
24
+ certificateFileUrl: string | null;
25
+ certificateTitle: string | null;
26
+ closeDatetime: number | null;
27
+ closeScheduleDatetime: number | null;
28
+ courseId: number;
29
+ createdDatetime: number;
30
+ description: string;
31
+ id: number;
32
+ isCertificateEnabled: boolean;
33
+ isCompleted: boolean;
34
+ isEnrolledStudentResponded: boolean;
35
+ isForStats: boolean;
36
+ isGraded: boolean;
37
+ isLibraryInstance: boolean;
38
+ isOpened: boolean;
39
+ isResponded: boolean;
40
+ lectureGroupType: import("@elice/types/es/enums").LectureGroupType | null;
41
+ lectureId: number;
42
+ mainOrderNo: number;
43
+ materialId: number;
44
+ materialKey: string;
45
+ materialType: import("@elice/types/es/enums").LectureMaterialType;
46
+ modifiedDatetime: number;
47
+ openScheduleDatetime: number | null;
48
+ originCourse: {
49
+ id: number;
50
+ title: string;
51
+ organization: {
52
+ id: number;
53
+ name: string;
54
+ nameShort: string;
55
+ };
56
+ } | null;
57
+ originLecturePageId: number | null;
58
+ point: number;
59
+ score: number;
60
+ subLecturePageIds: number[];
61
+ subOrderNo: number | null;
62
+ taglist: string[];
63
+ title: string;
64
+ } | null;
65
+ } & {
66
+ status: import("@elice/material-shared-types").APIStatus;
67
+ refetch: (signal?: AbortSignal | undefined) => Promise<void>;
68
+ };
21
69
  export {};
@@ -2,50 +2,36 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var React = require('react');
5
+ require('react');
6
+ require('../material-config/MaterialConfigContext.js');
7
+ var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
8
+ var useMaterialFetchRaw = require('./useMaterialFetchRaw.js');
9
+
10
+ //
11
+ //
6
12
 
7
13
  /**
8
14
  * Init api client and fetch material for contaner.
9
15
  *
10
- * @param fn API client wrapped with `React.useCallback` to fetch material.
11
- * @param isReady Is ready to fetch material.
12
- *
13
16
  * @example
14
- * const [materialPdf, materialPdfStatus] =
15
- * useMaterialFetch<GetOrgMaterialPdfGetResponses>(
17
+ * const { materialPdf, materialLecturePage, status ] =
18
+ * useMaterialFetch(
19
+ * 'materialPdf',
16
20
  * React.useCallback(
17
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
21
+ * signal =>
22
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
23
+ * { materialPdfId },
24
+ * { signal }
25
+ * ),
18
26
  * [materialPdfId]
19
27
  * ),
20
- * isReady // boolean
28
+ * eliceApiClientConfigs.init
21
29
  * );
22
30
  */
23
31
 
24
- const useMaterialFetch = (fn, isReady = true) => {
25
- const [material, setMaterial] = React.useState(null);
26
- const [materialStatus, setMaterialStatus] = React.useState('idle');
27
- React.useEffect(() => {
28
- if (!isReady) {
29
- return;
30
- }
31
-
32
- setMaterial(null);
33
- setMaterialStatus('pending');
34
- const abortCtrl = new AbortController();
35
- fn(abortCtrl.signal).then(res => {
36
- setMaterial(res);
37
- setMaterialStatus('resolved');
38
- }).catch(err => {
39
- if (err.name !== 'AbortError') {
40
- setMaterial(null);
41
- setMaterialStatus('rejected');
42
- }
43
- });
44
- return () => {
45
- abortCtrl.abort();
46
- };
47
- }, [isReady, fn]);
48
- return [material, materialStatus];
32
+ const useMaterialFetch = (materialKey, materialFetchFn, init) => {
33
+ const isReady = useMaterialConfigApiClientUpdate.useMaterialConfigApiClientUpdate(init);
34
+ return useMaterialFetchRaw.useMaterialFetchRaw(materialKey, materialFetchFn, isReady);
49
35
  };
50
36
 
51
37
  exports.useMaterialFetch = useMaterialFetch;
@@ -0,0 +1,27 @@
1
+ import type { EliceApiResponse } from '@elice/api-client';
2
+ import type { APIStatus } from '@elice/material-shared-types';
3
+ import type { GetOrgLecturePageGetResponses } from '@elice/types';
4
+ /**
5
+ * Init api client and fetch material for contaner.
6
+ *
7
+ * @example
8
+ * const { materialPdf, materialLecturePage, status ] =
9
+ * useMaterialFetchRaw(
10
+ * 'materialPdf',
11
+ * React.useCallback(
12
+ * signal =>
13
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
14
+ * { materialPdfId },
15
+ * { signal }
16
+ * ),
17
+ * [materialPdfId]
18
+ * ),
19
+ * isReady // boolean
20
+ * );
21
+ */
22
+ export declare const useMaterialFetchRaw: <K extends string, R extends Record<K, Record<string, any>> = Record<K, Record<string, any>>>(materialKey: K, materialFetchFn: (signal?: AbortSignal | undefined) => Promise<EliceApiResponse<R>>, isReady?: boolean) => Record<K, R[K] | null> & {
23
+ materialLecturePage: GetOrgLecturePageGetResponses['lecturePage'] | null;
24
+ } & {
25
+ status: APIStatus;
26
+ refetch: (signal?: AbortSignal | undefined) => Promise<void>;
27
+ };
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var apiClient = require('@elice/api-client');
7
+
8
+ //
9
+ //
10
+
11
+ /**
12
+ * Init api client and fetch material for contaner.
13
+ *
14
+ * @example
15
+ * const { materialPdf, materialLecturePage, status ] =
16
+ * useMaterialFetchRaw(
17
+ * 'materialPdf',
18
+ * React.useCallback(
19
+ * signal =>
20
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
21
+ * { materialPdfId },
22
+ * { signal }
23
+ * ),
24
+ * [materialPdfId]
25
+ * ),
26
+ * isReady // boolean
27
+ * );
28
+ */
29
+
30
+ const useMaterialFetchRaw = (materialKey, materialFetchFn, isReady = true) => {
31
+ const _return = React.useRef({});
32
+
33
+ const _createEmptyFetchRes = () => ({
34
+ [materialKey]: null,
35
+ materialLecturePage: null
36
+ });
37
+
38
+ const [matFetchRes, setMatFetchRes] = React.useState(_createEmptyFetchRes);
39
+ const [matFetchStatus, setMatFetchStatus] = React.useState('idle');
40
+ /**
41
+ * fetch material and lecture page
42
+ */
43
+
44
+ const fetch = React.useCallback(async signal => {
45
+ setMatFetchRes(_createEmptyFetchRes);
46
+ setMatFetchStatus('pending');
47
+ return materialFetchFn(signal).then(resMaterialGet => resMaterialGet[materialKey]).then(material => Promise.all([material, apiClient.getOrgLecturePageResolve({
48
+ materialId: material.id
49
+ }, {
50
+ signal: signal
51
+ }).then(resLecturePageResolve => apiClient.getOrgLecturePageGet({
52
+ lecturePageId: resLecturePageResolve.lecturePageId
53
+ }, {
54
+ signal: signal
55
+ })).then(resLecturePageGet => resLecturePageGet.lecturePage)])).then(([material, materialLecturePage]) => {
56
+ setMatFetchRes({
57
+ [materialKey]: material,
58
+ materialLecturePage
59
+ });
60
+ setMatFetchStatus('resolved');
61
+ }).catch(err => {
62
+ if (err.name !== 'AbortError') {
63
+ setMatFetchRes(_createEmptyFetchRes);
64
+ setMatFetchStatus('rejected');
65
+ }
66
+ });
67
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
68
+ [materialKey, materialFetchFn]); //
69
+ // emit `fetch` when `isReady` is changed
70
+ //
71
+
72
+ React.useEffect(() => {
73
+ if (!isReady) {
74
+ return;
75
+ }
76
+
77
+ const abortCtrl = new AbortController();
78
+ fetch(abortCtrl.signal).catch(() => void 0);
79
+ return () => {
80
+ abortCtrl.abort();
81
+ };
82
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
83
+ [isReady, fetch]); //
84
+ //
85
+ //
86
+
87
+ _return.current[materialKey] = matFetchRes[materialKey];
88
+ _return.current.materialLecturePage = matFetchRes.materialLecturePage;
89
+ _return.current.status = matFetchStatus;
90
+ _return.current.refetch = fetch;
91
+ return _return.current;
92
+ };
93
+
94
+ exports.useMaterialFetchRaw = useMaterialFetchRaw;
package/es/index.js CHANGED
@@ -5,5 +5,5 @@ export { useMaterialConfig } from './material-config/useMaterialConfig.js';
5
5
  export { useMaterialConfigApiClientUpdate } from './material-config/useMaterialConfigApiClientUpdate.js';
6
6
  export { updateMaterialConfigSessionKey } from './material-config/utils.js';
7
7
  export { useMaterialFetch } from './material-fetch/useMaterialFetch.js';
8
- export { useMaterialInitFetch } from './material-fetch/useMaterialInitFetch.js';
8
+ export { useMaterialFetchRaw } from './material-fetch/useMaterialFetchRaw.js';
9
9
  export { withForwardRefMaterial, withMaterial } from './material-hoc/withMaterial.js';
@@ -1,2 +1,2 @@
1
1
  export * from './useMaterialFetch';
2
- export * from './useMaterialInitFetch';
2
+ export * from './useMaterialFetchRaw';
@@ -1,21 +1,69 @@
1
- import type { EliceApiResponse } from '@elice/api-client';
2
- import type { APIStatus } from '@elice/material-shared-types';
3
- declare type FetchFn<R> = (signal: AbortSignal) => Promise<EliceApiResponse<R>>;
1
+ import type { EliceApiClientConfigs, EliceApiResponse } from '@elice/api-client';
2
+ declare type FetchClientInitializer = (config: EliceApiClientConfigs) => void;
4
3
  /**
5
4
  * Init api client and fetch material for contaner.
6
5
  *
7
- * @param fn API client wrapped with `React.useCallback` to fetch material.
8
- * @param isReady Is ready to fetch material.
9
- *
10
6
  * @example
11
- * const [materialPdf, materialPdfStatus] =
12
- * useMaterialFetch<GetOrgMaterialPdfGetResponses>(
7
+ * const { materialPdf, materialLecturePage, status ] =
8
+ * useMaterialFetch(
9
+ * 'materialPdf',
13
10
  * React.useCallback(
14
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
11
+ * signal =>
12
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
13
+ * { materialPdfId },
14
+ * { signal }
15
+ * ),
15
16
  * [materialPdfId]
16
17
  * ),
17
- * isReady // boolean
18
+ * eliceApiClientConfigs.init
18
19
  * );
19
20
  */
20
- export declare const useMaterialFetch: <R = any>(fn: FetchFn<R>, isReady?: boolean) => [R | null, APIStatus];
21
+ export declare const useMaterialFetch: <K extends string, R extends Record<K, Record<string, any>> = Record<K, Record<string, any>>>(materialKey: K, materialFetchFn: (signal?: AbortSignal | undefined) => Promise<EliceApiResponse<R>>, init: FetchClientInitializer) => Record<K, R[K] | null> & {
22
+ materialLecturePage: {
23
+ certificateDescription: string | null;
24
+ certificateFileUrl: string | null;
25
+ certificateTitle: string | null;
26
+ closeDatetime: number | null;
27
+ closeScheduleDatetime: number | null;
28
+ courseId: number;
29
+ createdDatetime: number;
30
+ description: string;
31
+ id: number;
32
+ isCertificateEnabled: boolean;
33
+ isCompleted: boolean;
34
+ isEnrolledStudentResponded: boolean;
35
+ isForStats: boolean;
36
+ isGraded: boolean;
37
+ isLibraryInstance: boolean;
38
+ isOpened: boolean;
39
+ isResponded: boolean;
40
+ lectureGroupType: import("@elice/types/es/enums").LectureGroupType | null;
41
+ lectureId: number;
42
+ mainOrderNo: number;
43
+ materialId: number;
44
+ materialKey: string;
45
+ materialType: import("@elice/types/es/enums").LectureMaterialType;
46
+ modifiedDatetime: number;
47
+ openScheduleDatetime: number | null;
48
+ originCourse: {
49
+ id: number;
50
+ title: string;
51
+ organization: {
52
+ id: number;
53
+ name: string;
54
+ nameShort: string;
55
+ };
56
+ } | null;
57
+ originLecturePageId: number | null;
58
+ point: number;
59
+ score: number;
60
+ subLecturePageIds: number[];
61
+ subOrderNo: number | null;
62
+ taglist: string[];
63
+ title: string;
64
+ } | null;
65
+ } & {
66
+ status: import("@elice/material-shared-types").APIStatus;
67
+ refetch: (signal?: AbortSignal | undefined) => Promise<void>;
68
+ };
21
69
  export {};
@@ -1,47 +1,33 @@
1
- import { useState, useEffect } from 'react';
1
+ import 'react';
2
+ import '../material-config/MaterialConfigContext.js';
3
+ import { useMaterialConfigApiClientUpdate } from '../material-config/useMaterialConfigApiClientUpdate.js';
4
+ import { useMaterialFetchRaw } from './useMaterialFetchRaw.js';
5
+
6
+ //
7
+ //
2
8
 
3
9
  /**
4
10
  * Init api client and fetch material for contaner.
5
11
  *
6
- * @param fn API client wrapped with `React.useCallback` to fetch material.
7
- * @param isReady Is ready to fetch material.
8
- *
9
12
  * @example
10
- * const [materialPdf, materialPdfStatus] =
11
- * useMaterialFetch<GetOrgMaterialPdfGetResponses>(
13
+ * const { materialPdf, materialLecturePage, status ] =
14
+ * useMaterialFetch(
15
+ * 'materialPdf',
12
16
  * React.useCallback(
13
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
17
+ * signal =>
18
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
19
+ * { materialPdfId },
20
+ * { signal }
21
+ * ),
14
22
  * [materialPdfId]
15
23
  * ),
16
- * isReady // boolean
24
+ * eliceApiClientConfigs.init
17
25
  * );
18
26
  */
19
27
 
20
- const useMaterialFetch = (fn, isReady = true) => {
21
- const [material, setMaterial] = useState(null);
22
- const [materialStatus, setMaterialStatus] = useState('idle');
23
- useEffect(() => {
24
- if (!isReady) {
25
- return;
26
- }
27
-
28
- setMaterial(null);
29
- setMaterialStatus('pending');
30
- const abortCtrl = new AbortController();
31
- fn(abortCtrl.signal).then(res => {
32
- setMaterial(res);
33
- setMaterialStatus('resolved');
34
- }).catch(err => {
35
- if (err.name !== 'AbortError') {
36
- setMaterial(null);
37
- setMaterialStatus('rejected');
38
- }
39
- });
40
- return () => {
41
- abortCtrl.abort();
42
- };
43
- }, [isReady, fn]);
44
- return [material, materialStatus];
28
+ const useMaterialFetch = (materialKey, materialFetchFn, init) => {
29
+ const isReady = useMaterialConfigApiClientUpdate(init);
30
+ return useMaterialFetchRaw(materialKey, materialFetchFn, isReady);
45
31
  };
46
32
 
47
33
  export { useMaterialFetch };
@@ -0,0 +1,27 @@
1
+ import type { EliceApiResponse } from '@elice/api-client';
2
+ import type { APIStatus } from '@elice/material-shared-types';
3
+ import type { GetOrgLecturePageGetResponses } from '@elice/types';
4
+ /**
5
+ * Init api client and fetch material for contaner.
6
+ *
7
+ * @example
8
+ * const { materialPdf, materialLecturePage, status ] =
9
+ * useMaterialFetchRaw(
10
+ * 'materialPdf',
11
+ * React.useCallback(
12
+ * signal =>
13
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
14
+ * { materialPdfId },
15
+ * { signal }
16
+ * ),
17
+ * [materialPdfId]
18
+ * ),
19
+ * isReady // boolean
20
+ * );
21
+ */
22
+ export declare const useMaterialFetchRaw: <K extends string, R extends Record<K, Record<string, any>> = Record<K, Record<string, any>>>(materialKey: K, materialFetchFn: (signal?: AbortSignal | undefined) => Promise<EliceApiResponse<R>>, isReady?: boolean) => Record<K, R[K] | null> & {
23
+ materialLecturePage: GetOrgLecturePageGetResponses['lecturePage'] | null;
24
+ } & {
25
+ status: APIStatus;
26
+ refetch: (signal?: AbortSignal | undefined) => Promise<void>;
27
+ };
@@ -0,0 +1,90 @@
1
+ import { useRef, useState, useCallback, useEffect } from 'react';
2
+ import { getOrgLecturePageResolve, getOrgLecturePageGet } from '@elice/api-client';
3
+
4
+ //
5
+ //
6
+
7
+ /**
8
+ * Init api client and fetch material for contaner.
9
+ *
10
+ * @example
11
+ * const { materialPdf, materialLecturePage, status ] =
12
+ * useMaterialFetchRaw(
13
+ * 'materialPdf',
14
+ * React.useCallback(
15
+ * signal =>
16
+ * getOrgMaterialPdfGet<GetOrgMaterialPdfGetResponses>(
17
+ * { materialPdfId },
18
+ * { signal }
19
+ * ),
20
+ * [materialPdfId]
21
+ * ),
22
+ * isReady // boolean
23
+ * );
24
+ */
25
+
26
+ const useMaterialFetchRaw = (materialKey, materialFetchFn, isReady = true) => {
27
+ const _return = useRef({});
28
+
29
+ const _createEmptyFetchRes = () => ({
30
+ [materialKey]: null,
31
+ materialLecturePage: null
32
+ });
33
+
34
+ const [matFetchRes, setMatFetchRes] = useState(_createEmptyFetchRes);
35
+ const [matFetchStatus, setMatFetchStatus] = useState('idle');
36
+ /**
37
+ * fetch material and lecture page
38
+ */
39
+
40
+ const fetch = useCallback(async signal => {
41
+ setMatFetchRes(_createEmptyFetchRes);
42
+ setMatFetchStatus('pending');
43
+ return materialFetchFn(signal).then(resMaterialGet => resMaterialGet[materialKey]).then(material => Promise.all([material, getOrgLecturePageResolve({
44
+ materialId: material.id
45
+ }, {
46
+ signal: signal
47
+ }).then(resLecturePageResolve => getOrgLecturePageGet({
48
+ lecturePageId: resLecturePageResolve.lecturePageId
49
+ }, {
50
+ signal: signal
51
+ })).then(resLecturePageGet => resLecturePageGet.lecturePage)])).then(([material, materialLecturePage]) => {
52
+ setMatFetchRes({
53
+ [materialKey]: material,
54
+ materialLecturePage
55
+ });
56
+ setMatFetchStatus('resolved');
57
+ }).catch(err => {
58
+ if (err.name !== 'AbortError') {
59
+ setMatFetchRes(_createEmptyFetchRes);
60
+ setMatFetchStatus('rejected');
61
+ }
62
+ });
63
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ [materialKey, materialFetchFn]); //
65
+ // emit `fetch` when `isReady` is changed
66
+ //
67
+
68
+ useEffect(() => {
69
+ if (!isReady) {
70
+ return;
71
+ }
72
+
73
+ const abortCtrl = new AbortController();
74
+ fetch(abortCtrl.signal).catch(() => void 0);
75
+ return () => {
76
+ abortCtrl.abort();
77
+ };
78
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
79
+ [isReady, fetch]); //
80
+ //
81
+ //
82
+
83
+ _return.current[materialKey] = matFetchRes[materialKey];
84
+ _return.current.materialLecturePage = matFetchRes.materialLecturePage;
85
+ _return.current.status = matFetchStatus;
86
+ _return.current.refetch = fetch;
87
+ return _return.current;
88
+ };
89
+
90
+ export { useMaterialFetchRaw };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-shared-utils",
3
- "version": "1.230208.0-style.1",
3
+ "version": "1.230217.0-sepmatlec.0",
4
4
  "description": "Shared typings for elice material projects",
5
5
  "repository": "https://git.elicer.io/elice/frontend/library/elice-material",
6
6
  "license": "UNLICENSED",
@@ -29,7 +29,7 @@
29
29
  "clean": "del-cli \"es/*\" \"cjs/*\" \"dist/*\""
30
30
  },
31
31
  "peerDependencies": {
32
- "@elice/api-client": "1.221217.0",
32
+ "@elice/api-client": "1.230126.0-sepmatlec.3",
33
33
  "@elice/material-shared-types": "22.7.2-1",
34
34
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
35
35
  "react-use": "^17.0.0",
@@ -39,11 +39,11 @@
39
39
  "tslib": "^2.3.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@elice/api-client": "1.221217.0",
43
- "@elice/material-shared-types": "1.230208.0-style.1",
44
- "@elice/types": "1.221217.0",
42
+ "@elice/api-client": "1.230126.0-sepmatlec.3",
43
+ "@elice/material-shared-types": "1.230217.0-sepmatlec.0",
44
+ "@elice/types": "1.230126.0-sepmatlec.3",
45
45
  "@types/react": "~17.0.9",
46
46
  "react-use": "^17.2.4"
47
47
  },
48
- "gitHead": "a135b24e33eb1674ee0712b25c0fb0eda595d84f"
48
+ "gitHead": "6b2a7a2aa54b21685ea99f8bb5f240cdfd1b343a"
49
49
  }
@@ -1,22 +0,0 @@
1
- import type { EliceApiClientConfigs, EliceApiResponse } from '@elice/api-client';
2
- import type { APIStatus } from '@elice/material-shared-types';
3
- declare type ApiInitFn = (config: EliceApiClientConfigs) => void;
4
- declare type FetchFn<R> = (signal: AbortSignal) => Promise<EliceApiResponse<R>>;
5
- /**
6
- * Init api client and fetch material for contaner.
7
- *
8
- * @param init Init api client.
9
- * @param fn API client wrapped with `React.useCallback` to fetch material.
10
- *
11
- * @example
12
- * const [materialPdf, materialPdfStatus] =
13
- * useMaterialInitFetch<GetOrgMaterialPdfGetResponses>(
14
- * eliceApiClientConfigs.init,
15
- * React.useCallback(
16
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
17
- * [materialPdfId]
18
- * ),
19
- * );
20
- */
21
- export declare const useMaterialInitFetch: <R = any>(init: ApiInitFn, fn: FetchFn<R>) => [R | null, APIStatus];
22
- export {};
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- require('../material-config/MaterialConfigContext.js');
7
- var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
8
-
9
- /**
10
- * Init api client and fetch material for contaner.
11
- *
12
- * @param init Init api client.
13
- * @param fn API client wrapped with `React.useCallback` to fetch material.
14
- *
15
- * @example
16
- * const [materialPdf, materialPdfStatus] =
17
- * useMaterialInitFetch<GetOrgMaterialPdfGetResponses>(
18
- * eliceApiClientConfigs.init,
19
- * React.useCallback(
20
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
21
- * [materialPdfId]
22
- * ),
23
- * );
24
- */
25
-
26
- const useMaterialInitFetch = (init, fn) => {
27
- const [material, setMaterial] = React.useState(null);
28
- const [materialStatus, setMaterialStatus] = React.useState('idle');
29
- const isReady = useMaterialConfigApiClientUpdate.useMaterialConfigApiClientUpdate(init);
30
- React.useEffect(() => {
31
- if (!isReady) {
32
- return;
33
- }
34
-
35
- setMaterial(null);
36
- setMaterialStatus('pending');
37
- const abortCtrl = new AbortController();
38
- fn(abortCtrl.signal).then(res => {
39
- setMaterial(res);
40
- setMaterialStatus('resolved');
41
- }).catch(err => {
42
- if (err.name !== 'AbortError') {
43
- setMaterial(null);
44
- setMaterialStatus('rejected');
45
- }
46
- });
47
- return () => {
48
- abortCtrl.abort();
49
- };
50
- }, [isReady, fn]);
51
- return [material, materialStatus];
52
- };
53
-
54
- exports.useMaterialInitFetch = useMaterialInitFetch;
@@ -1,22 +0,0 @@
1
- import type { EliceApiClientConfigs, EliceApiResponse } from '@elice/api-client';
2
- import type { APIStatus } from '@elice/material-shared-types';
3
- declare type ApiInitFn = (config: EliceApiClientConfigs) => void;
4
- declare type FetchFn<R> = (signal: AbortSignal) => Promise<EliceApiResponse<R>>;
5
- /**
6
- * Init api client and fetch material for contaner.
7
- *
8
- * @param init Init api client.
9
- * @param fn API client wrapped with `React.useCallback` to fetch material.
10
- *
11
- * @example
12
- * const [materialPdf, materialPdfStatus] =
13
- * useMaterialInitFetch<GetOrgMaterialPdfGetResponses>(
14
- * eliceApiClientConfigs.init,
15
- * React.useCallback(
16
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
17
- * [materialPdfId]
18
- * ),
19
- * );
20
- */
21
- export declare const useMaterialInitFetch: <R = any>(init: ApiInitFn, fn: FetchFn<R>) => [R | null, APIStatus];
22
- export {};
@@ -1,50 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import '../material-config/MaterialConfigContext.js';
3
- import { useMaterialConfigApiClientUpdate } from '../material-config/useMaterialConfigApiClientUpdate.js';
4
-
5
- /**
6
- * Init api client and fetch material for contaner.
7
- *
8
- * @param init Init api client.
9
- * @param fn API client wrapped with `React.useCallback` to fetch material.
10
- *
11
- * @example
12
- * const [materialPdf, materialPdfStatus] =
13
- * useMaterialInitFetch<GetOrgMaterialPdfGetResponses>(
14
- * eliceApiClientConfigs.init,
15
- * React.useCallback(
16
- * signal => getOrgMaterialPdfGet({ materialPdfId }, { signal }),
17
- * [materialPdfId]
18
- * ),
19
- * );
20
- */
21
-
22
- const useMaterialInitFetch = (init, fn) => {
23
- const [material, setMaterial] = useState(null);
24
- const [materialStatus, setMaterialStatus] = useState('idle');
25
- const isReady = useMaterialConfigApiClientUpdate(init);
26
- useEffect(() => {
27
- if (!isReady) {
28
- return;
29
- }
30
-
31
- setMaterial(null);
32
- setMaterialStatus('pending');
33
- const abortCtrl = new AbortController();
34
- fn(abortCtrl.signal).then(res => {
35
- setMaterial(res);
36
- setMaterialStatus('resolved');
37
- }).catch(err => {
38
- if (err.name !== 'AbortError') {
39
- setMaterial(null);
40
- setMaterialStatus('rejected');
41
- }
42
- });
43
- return () => {
44
- abortCtrl.abort();
45
- };
46
- }, [isReady, fn]);
47
- return [material, materialStatus];
48
- };
49
-
50
- export { useMaterialInitFetch };