@elice/material-survey 1.230220.2 → 1.230306.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.
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var apiClient = require('@elice/api-client');
7
7
  var materialSharedUtils = require('@elice/material-shared-utils');
8
+ var types = require('@elice/types');
8
9
 
9
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
11
 
@@ -24,10 +25,18 @@ function MaterialSurveyProvider({
24
25
  }) {
25
26
  const [course, setCourse] = React__default["default"].useState();
26
27
  const [lecture, setLecture] = React__default["default"].useState();
27
- const [materialSurvey, setMaterialSurvey] = React__default["default"].useState();
28
28
  const [initStatus, setInitStatus] = React__default["default"].useState('idle');
29
29
  const [vertical, setVertical] = React__default["default"].useState(false);
30
30
  const canInit = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
31
+ const {
32
+ materialSurvey,
33
+ materialLecturePage,
34
+ refetch: refreshOrgMaterialSurvey
35
+ } = materialSharedUtils.useMaterialFetchRaw(types.enums.LectureMaterialType.Survey, React__default["default"].useCallback(signal => apiClient.getOrgMaterialSurveyGet({
36
+ materialSurveyId
37
+ }, {
38
+ signal
39
+ }), [materialSurveyId]), canInit);
31
40
  const doInitilize = React__default["default"].useCallback(async () => {
32
41
  const controller = new AbortController();
33
42
  const {
@@ -35,20 +44,17 @@ function MaterialSurveyProvider({
35
44
  } = controller;
36
45
 
37
46
  try {
38
- setInitStatus('pending'); // fetch materialSurvey
47
+ setInitStatus('pending');
48
+
49
+ if (!materialLecturePage) {
50
+ throw new Error('materialSurvey is not ready');
51
+ } // fetch course
39
52
 
40
- const {
41
- materialSurvey
42
- } = await apiClient.getOrgMaterialSurveyGet({
43
- materialSurveyId
44
- }, {
45
- signal
46
- }); // fetch course
47
53
 
48
54
  const {
49
55
  course
50
56
  } = await apiClient.getOrgCourseGet({
51
- courseId: materialSurvey.courseId
57
+ courseId: materialLecturePage.courseId
52
58
  }, {
53
59
  signal
54
60
  }); // fetch lecture
@@ -56,11 +62,10 @@ function MaterialSurveyProvider({
56
62
  const {
57
63
  lecture
58
64
  } = await apiClient.getOrgLectureGet({
59
- lectureId: materialSurvey.lectureId
65
+ lectureId: materialLecturePage.lectureId
60
66
  }, {
61
67
  signal
62
68
  });
63
- setMaterialSurvey(materialSurvey);
64
69
  setCourse(course);
65
70
  setLecture(lecture);
66
71
  setInitStatus('resolved');
@@ -70,31 +75,17 @@ function MaterialSurveyProvider({
70
75
  }
71
76
 
72
77
  return () => controller.abort();
73
- }, [materialSurveyId]);
78
+ }, [materialLecturePage]);
74
79
  React__default["default"].useEffect(() => {
75
- if (canInit) {
80
+ if (canInit && materialLecturePage) {
76
81
  void doInitilize();
77
82
  }
78
- }, [canInit, doInitilize]); //
79
- //
80
- // materialSurvey refresher
81
-
82
- const refreshOrgMaterialSurvey = React__default["default"].useCallback(signal => {
83
- return apiClient.getOrgMaterialSurveyGet({
84
- materialSurveyId
85
- }, {
86
- signal
87
- }).then(response => {
88
- setMaterialSurvey(response.materialSurvey);
89
- }).catch(error => {
90
- console.error(error);
91
- });
92
- }, [materialSurveyId]);
83
+ }, [canInit, materialLecturePage, doInitilize]);
93
84
  return React__default["default"].createElement(StateContext.Provider, {
94
85
  value: {
95
86
  course,
96
87
  lecture,
97
- materialSurvey,
88
+ materialSurvey: materialSurvey !== null && materialSurvey !== void 0 ? materialSurvey : undefined,
98
89
  userId,
99
90
  vertical,
100
91
  initStatus
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { config, getOrgMaterialSurveyGet, getOrgCourseGet, getOrgLectureGet } from '@elice/api-client';
3
- import { useMaterialConfigApiClientUpdate } from '@elice/material-shared-utils';
3
+ import { useMaterialConfigApiClientUpdate, useMaterialFetchRaw } from '@elice/material-shared-utils';
4
+ import { enums } from '@elice/types';
4
5
 
5
6
  const StateContext = React.createContext(undefined);
6
7
  const DispatchContext = React.createContext(undefined);
@@ -16,10 +17,18 @@ function MaterialSurveyProvider({
16
17
  }) {
17
18
  const [course, setCourse] = React.useState();
18
19
  const [lecture, setLecture] = React.useState();
19
- const [materialSurvey, setMaterialSurvey] = React.useState();
20
20
  const [initStatus, setInitStatus] = React.useState('idle');
21
21
  const [vertical, setVertical] = React.useState(false);
22
22
  const canInit = useMaterialConfigApiClientUpdate(config.init);
23
+ const {
24
+ materialSurvey,
25
+ materialLecturePage,
26
+ refetch: refreshOrgMaterialSurvey
27
+ } = useMaterialFetchRaw(enums.LectureMaterialType.Survey, React.useCallback(signal => getOrgMaterialSurveyGet({
28
+ materialSurveyId
29
+ }, {
30
+ signal
31
+ }), [materialSurveyId]), canInit);
23
32
  const doInitilize = React.useCallback(async () => {
24
33
  const controller = new AbortController();
25
34
  const {
@@ -27,20 +36,17 @@ function MaterialSurveyProvider({
27
36
  } = controller;
28
37
 
29
38
  try {
30
- setInitStatus('pending'); // fetch materialSurvey
39
+ setInitStatus('pending');
40
+
41
+ if (!materialLecturePage) {
42
+ throw new Error('materialSurvey is not ready');
43
+ } // fetch course
31
44
 
32
- const {
33
- materialSurvey
34
- } = await getOrgMaterialSurveyGet({
35
- materialSurveyId
36
- }, {
37
- signal
38
- }); // fetch course
39
45
 
40
46
  const {
41
47
  course
42
48
  } = await getOrgCourseGet({
43
- courseId: materialSurvey.courseId
49
+ courseId: materialLecturePage.courseId
44
50
  }, {
45
51
  signal
46
52
  }); // fetch lecture
@@ -48,11 +54,10 @@ function MaterialSurveyProvider({
48
54
  const {
49
55
  lecture
50
56
  } = await getOrgLectureGet({
51
- lectureId: materialSurvey.lectureId
57
+ lectureId: materialLecturePage.lectureId
52
58
  }, {
53
59
  signal
54
60
  });
55
- setMaterialSurvey(materialSurvey);
56
61
  setCourse(course);
57
62
  setLecture(lecture);
58
63
  setInitStatus('resolved');
@@ -62,31 +67,17 @@ function MaterialSurveyProvider({
62
67
  }
63
68
 
64
69
  return () => controller.abort();
65
- }, [materialSurveyId]);
70
+ }, [materialLecturePage]);
66
71
  React.useEffect(() => {
67
- if (canInit) {
72
+ if (canInit && materialLecturePage) {
68
73
  void doInitilize();
69
74
  }
70
- }, [canInit, doInitilize]); //
71
- //
72
- // materialSurvey refresher
73
-
74
- const refreshOrgMaterialSurvey = React.useCallback(signal => {
75
- return getOrgMaterialSurveyGet({
76
- materialSurveyId
77
- }, {
78
- signal
79
- }).then(response => {
80
- setMaterialSurvey(response.materialSurvey);
81
- }).catch(error => {
82
- console.error(error);
83
- });
84
- }, [materialSurveyId]);
75
+ }, [canInit, materialLecturePage, doInitilize]);
85
76
  return React.createElement(StateContext.Provider, {
86
77
  value: {
87
78
  course,
88
79
  lecture,
89
- materialSurvey,
80
+ materialSurvey: materialSurvey !== null && materialSurvey !== void 0 ? materialSurvey : undefined,
90
81
  userId,
91
82
  vertical,
92
83
  initStatus
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-survey",
3
- "version": "1.230220.2",
3
+ "version": "1.230306.0",
4
4
  "description": "User view and editing components of Elice material survey",
5
5
  "repository": "https://git.elicer.io/elice/frontend/library/elice-material",
6
6
  "license": "UNLICENSED",
@@ -29,14 +29,14 @@
29
29
  "clean": "del-cli \"es/*\" \"cjs/*\" \"dist/*\""
30
30
  },
31
31
  "peerDependencies": {
32
- "@elice/api-client": "1.230215.1",
32
+ "@elice/api-client": "^1.230306.0",
33
33
  "@elice/blocks": "^1.220803.0",
34
34
  "@elice/design-tokens": "^1.220803.0",
35
35
  "@elice/icons": "^1.220803.0",
36
36
  "@elice/markdown": "^1.220803.0",
37
37
  "@elice/material-shared-types": "*",
38
38
  "@elice/material-shared-utils": "*",
39
- "@elice/types": "1.230215.1",
39
+ "@elice/types": "^1.230306.0",
40
40
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
41
41
  "react-intl": "^5.0.0",
42
42
  "react-use": "^17.0.0",
@@ -49,15 +49,15 @@
49
49
  "tslib": "^2.3.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@elice/api-client": "1.230215.1",
52
+ "@elice/api-client": "^1.230306.0",
53
53
  "@elice/blocks": "^1.220803.0",
54
54
  "@elice/design-tokens": "^1.220803.0",
55
55
  "@elice/icons": "^1.220803.0",
56
56
  "@elice/icons-legacy": "npm:@elice/icons@0.220803.1",
57
57
  "@elice/markdown": "^1.220803.0",
58
- "@elice/material-shared-types": "1.230220.2",
59
- "@elice/material-shared-utils": "1.230220.2",
60
- "@elice/types": "1.230215.1",
58
+ "@elice/material-shared-types": "1.230306.0",
59
+ "@elice/material-shared-utils": "1.230306.0",
60
+ "@elice/types": "^1.230306.0",
61
61
  "@types/classnames": "^2.3.1",
62
62
  "@types/react": "~17.0.9",
63
63
  "@types/react-transition-group": "^4.4.4",
@@ -67,5 +67,5 @@
67
67
  "react-use": "^17.2.4",
68
68
  "styled-components": "^5.3.0"
69
69
  },
70
- "gitHead": "f49499e86ce2ccbea6a1b83e070649a3167f8074"
70
+ "gitHead": "2ba30b7324d9fd782970a0343a6573827159b737"
71
71
  }