@elice/material-survey 1.240718.0-trasncript.2 → 1.240718.2

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.
Files changed (67) hide show
  1. package/cjs/components/markdown-editor/index.d.ts +2 -1
  2. package/cjs/components/markdown-editor/index.js +10 -19
  3. package/cjs/components/material-survey/MaterialSurvey.js +57 -82
  4. package/cjs/components/material-survey/MaterialSurveyInfo.js +59 -69
  5. package/cjs/components/material-survey/MaterialSurveySelectMultiple.js +90 -131
  6. package/cjs/components/material-survey/MaterialSurveySelectOne.js +86 -125
  7. package/cjs/components/material-survey/MaterialSurveyShimmer.js +40 -47
  8. package/cjs/components/material-survey/MaterialSurveyText.js +75 -114
  9. package/cjs/components/material-survey/SurveyResultBadge.js +10 -17
  10. package/cjs/components/material-survey/SurveySubmitStatusText.js +16 -21
  11. package/cjs/components/material-survey/context/MaterialSurveyContext.d.ts +1 -1
  12. package/cjs/components/material-survey/context/MaterialSurveyContext.js +74 -115
  13. package/cjs/components/material-survey-edit/MaterialSurveyEdit.js +36 -49
  14. package/cjs/components/material-survey-edit/MaterialSurveyEditContent.js +91 -113
  15. package/cjs/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +87 -100
  16. package/cjs/components/material-survey-edit/context.js +2 -8
  17. package/cjs/components/material-survey-edit/utils/editValue.js +11 -17
  18. package/cjs/components/shared/StyledMarkdown.js +1 -5
  19. package/cjs/components/shared/SurveyContentBox.js +74 -85
  20. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -13
  21. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  22. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -24
  23. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +89 -66
  24. package/cjs/components/shared/question-radio/QuestionRadio.js +7 -13
  25. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  26. package/cjs/components/shared/question-radio/QuestionRadioContext.js +17 -24
  27. package/cjs/components/shared/question-radio/QuestionRadioOption.js +80 -59
  28. package/es/components/markdown-editor/index.d.ts +2 -1
  29. package/es/components/markdown-editor/index.js +10 -15
  30. package/es/components/material-survey/MaterialSurvey.js +57 -77
  31. package/es/components/material-survey/MaterialSurveyInfo.js +59 -65
  32. package/es/components/material-survey/MaterialSurveySelectMultiple.js +90 -127
  33. package/es/components/material-survey/MaterialSurveySelectOne.js +86 -121
  34. package/es/components/material-survey/MaterialSurveyShimmer.js +40 -43
  35. package/es/components/material-survey/MaterialSurveyText.js +75 -109
  36. package/es/components/material-survey/SurveyResultBadge.js +10 -13
  37. package/es/components/material-survey/SurveySubmitStatusText.js +16 -17
  38. package/es/components/material-survey/context/MaterialSurveyContext.d.ts +1 -1
  39. package/es/components/material-survey/context/MaterialSurveyContext.js +75 -112
  40. package/es/components/material-survey-edit/MaterialSurveyEdit.js +36 -45
  41. package/es/components/material-survey-edit/MaterialSurveyEditContent.js +90 -107
  42. package/es/components/material-survey-edit/MaterialSurveyEditOptionSelect.js +87 -96
  43. package/es/components/material-survey-edit/context.js +2 -4
  44. package/es/components/material-survey-edit/utils/editValue.js +11 -17
  45. package/es/components/shared/StyledMarkdown.js +1 -1
  46. package/es/components/shared/SurveyContentBox.js +74 -81
  47. package/es/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
  48. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  49. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -20
  50. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +89 -61
  51. package/es/components/shared/question-radio/QuestionRadio.js +7 -9
  52. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  53. package/es/components/shared/question-radio/QuestionRadioContext.js +17 -20
  54. package/es/components/shared/question-radio/QuestionRadioOption.js +80 -54
  55. package/package.json +12 -9
  56. package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -399
  57. package/cjs/components/material-survey/index.js +0 -9
  58. package/cjs/components/material-survey/locales/index.js +0 -13
  59. package/cjs/components/material-survey-edit/index.js +0 -7
  60. package/cjs/components/material-survey-edit/locales/index.js +0 -13
  61. package/cjs/components/shared/index.js +0 -13
  62. package/es/_virtual/_rollupPluginBabelHelpers.js +0 -386
  63. package/es/components/material-survey/index.js +0 -2
  64. package/es/components/material-survey/locales/index.js +0 -4
  65. package/es/components/material-survey-edit/index.js +0 -1
  66. package/es/components/material-survey-edit/locales/index.js +0 -4
  67. package/es/components/shared/index.js +0 -4
@@ -1,5 +1,3 @@
1
- import { slicedToArray as _slicedToArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
- import { jsx } from 'react/jsx-runtime';
3
1
  import React from 'react';
4
2
  import { getOrgMaterialSurveyResponseGet, getOrgMaterialSurveyResponseList, postOrgMaterialSurveyResponseAdd } from '@elice/api-client';
5
3
  import { base } from '@elice/design-tokens';
@@ -11,61 +9,55 @@ import { useMaterialSurveyState, useMaterialSurveyDispatch } from './context/Mat
11
9
  import SurveyResultBadge from './SurveyResultBadge.js';
12
10
  import SurveySubmitStatusText from './SurveySubmitStatusText.js';
13
11
 
14
- var StyledTextarea = styled.textarea.withConfig({
12
+ const StyledTextarea = styled.textarea.withConfig({
15
13
  componentId: "sc-16tkulg-0"
16
- })(["min-height:12rem;width:100%;padding:1rem 1.375rem;font-size:1rem;color:", ";border-radius:4px;resize:vertical;line-height:1.5rem;outline:none;background-color:", ";&::placeholder{color:", ";}&:hover{cursor:", ";}"], base.color.navy2, base.color.navy5, base.color.navy2, function (_ref) {
17
- var disabled = _ref.disabled;
18
- return disabled ? 'not-allowed' : 'text';
19
- });
20
- var MaterialSurveyText = function MaterialSurveyText() {
14
+ })(["min-height:12rem;width:100%;padding:1rem 1.375rem;font-size:1rem;color:", ";border-radius:4px;resize:vertical;line-height:1.5rem;outline:none;background-color:", ";&::placeholder{color:", ";}&:hover{cursor:", ";}"], base.color.navy2, base.color.navy5, base.color.navy2, ({
15
+ disabled
16
+ }) => disabled ? 'not-allowed' : 'text');
17
+ const MaterialSurveyText = () => {
21
18
  // context
22
- var _useMaterialSurveySta = useMaterialSurveyState(),
23
- lecture = _useMaterialSurveySta.lecture,
24
- materialSurvey = _useMaterialSurveySta.materialSurvey,
25
- userId = _useMaterialSurveySta.userId;
26
- var _useMaterialSurveyDis = useMaterialSurveyDispatch(),
27
- onSubmit = _useMaterialSurveyDis.onSubmit,
28
- onNext = _useMaterialSurveyDis.onNext,
29
- refreshOrgMaterialSurvey = _useMaterialSurveyDis.refreshOrgMaterialSurvey;
19
+ const {
20
+ lecture,
21
+ materialSurvey,
22
+ userId
23
+ } = useMaterialSurveyState();
24
+ const {
25
+ onSubmit,
26
+ onNext,
27
+ refreshOrgMaterialSurvey
28
+ } = useMaterialSurveyDispatch();
30
29
  // state
31
- var intl = useRawEliceIntl();
32
- var _React$useState = React.useState(),
33
- _React$useState2 = _slicedToArray(_React$useState, 2),
34
- materialSurveyResponse = _React$useState2[0],
35
- setMaterialSurveyResponse = _React$useState2[1];
36
- var _React$useState3 = React.useState('idle'),
37
- _React$useState4 = _slicedToArray(_React$useState3, 2),
38
- submitStatus = _React$useState4[0],
39
- setSubmitStatus = _React$useState4[1];
40
- var _React$useState5 = React.useState(''),
41
- _React$useState6 = _slicedToArray(_React$useState5, 2),
42
- answer = _React$useState6[0],
43
- setAnswer = _React$useState6[1];
30
+ const intl = useRawEliceIntl();
31
+ const [materialSurveyResponse, setMaterialSurveyResponse] = React.useState();
32
+ const [submitStatus, setSubmitStatus] = React.useState('idle');
33
+ const [answer, setAnswer] = React.useState('');
44
34
  // survey response fetcher
45
- React.useEffect(function () {
35
+ React.useEffect(() => {
46
36
  if (!userId && (materialSurvey === null || materialSurvey === void 0 ? void 0 : materialSurvey.lastSurveyResponseId)) {
47
- var controller = new AbortController();
48
- var signal = controller.signal;
37
+ const controller = new AbortController();
38
+ const {
39
+ signal
40
+ } = controller;
49
41
  getOrgMaterialSurveyResponseGet({
50
42
  surveyResponseId: materialSurvey.lastSurveyResponseId
51
43
  }, {
52
- signal: signal
53
- }).then(function (response) {
44
+ signal
45
+ }).then(response => {
54
46
  setMaterialSurveyResponse(response.surveyResponse);
55
47
  setAnswer(response.surveyResponse.answers[0]);
56
- }).catch(function (error) {
48
+ }).catch(error => {
57
49
  console.error(error);
58
50
  });
59
- return function () {
60
- return controller.abort();
61
- };
51
+ return () => controller.abort();
62
52
  }
63
53
  }, [materialSurvey, userId]);
64
54
  // survey response fetcher
65
- React.useEffect(function () {
55
+ React.useEffect(() => {
66
56
  if (userId && materialSurvey) {
67
- var controller = new AbortController();
68
- var signal = controller.signal;
57
+ const controller = new AbortController();
58
+ const {
59
+ signal
60
+ } = controller;
69
61
  getOrgMaterialSurveyResponseList({
70
62
  materialSurveyId: materialSurvey.id,
71
63
  filterUserIds: [userId],
@@ -74,72 +66,47 @@ var MaterialSurveyText = function MaterialSurveyText() {
74
66
  offset: 0,
75
67
  count: 1
76
68
  }, {
77
- signal: signal
78
- }).then(function (response) {
79
- var surveyResponse = response.surveyResponses[0];
69
+ signal
70
+ }).then(response => {
71
+ const surveyResponse = response.surveyResponses[0];
80
72
  setMaterialSurveyResponse(surveyResponse);
81
73
  setAnswer(typeof (surveyResponse === null || surveyResponse === void 0 ? void 0 : surveyResponse.answers[0]) === 'string' ? surveyResponse.answers[0] : '');
82
- }).catch(function (error) {
74
+ }).catch(error => {
83
75
  console.error(error);
84
76
  });
85
- return function () {
86
- return controller.abort();
87
- };
77
+ return () => controller.abort();
88
78
  }
89
79
  }, [materialSurvey, userId]);
90
80
  // submit handler
91
- var handleSubmit = /*#__PURE__*/function () {
92
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
93
- var _yield$postOrgMateria, surveyResponseId, _yield$getOrgMaterial, surveyResponse;
94
- return _regeneratorRuntime().wrap(function _callee$(_context) {
95
- while (1) switch (_context.prev = _context.next) {
96
- case 0:
97
- if (materialSurvey) {
98
- _context.next = 2;
99
- break;
100
- }
101
- return _context.abrupt("return");
102
- case 2:
103
- setSubmitStatus('pending');
104
- _context.prev = 3;
105
- _context.next = 6;
106
- return postOrgMaterialSurveyResponseAdd({
107
- materialSurveyId: materialSurvey.id,
108
- answers: [answer] // FIXME: Type mismatch
109
- });
110
- case 6:
111
- _yield$postOrgMateria = _context.sent;
112
- surveyResponseId = _yield$postOrgMateria.surveyResponseId;
113
- _context.next = 10;
114
- return getOrgMaterialSurveyResponseGet({
115
- surveyResponseId: surveyResponseId
116
- });
117
- case 10:
118
- _yield$getOrgMaterial = _context.sent;
119
- surveyResponse = _yield$getOrgMaterial.surveyResponse;
120
- setMaterialSurveyResponse(surveyResponse);
121
- void refreshOrgMaterialSurvey();
122
- onSubmit(true);
123
- setSubmitStatus('resolved');
124
- _context.next = 23;
125
- break;
126
- case 18:
127
- _context.prev = 18;
128
- _context.t0 = _context["catch"](3);
129
- console.error(_context.t0);
130
- onSubmit(false);
131
- setSubmitStatus('rejected');
132
- case 23:
133
- case "end":
134
- return _context.stop();
135
- }
136
- }, _callee, null, [[3, 18]]);
137
- }));
138
- return function handleSubmit() {
139
- return _ref2.apply(this, arguments);
140
- };
141
- }();
142
- var commonProps = {
81
+ const handleSubmit = async () => {
82
+ if (!materialSurvey) {
83
+ return;
84
+ }
85
+ setSubmitStatus('pending');
86
+ try {
87
+ const {
88
+ surveyResponseId
89
+ } = await postOrgMaterialSurveyResponseAdd({
90
+ materialSurveyId: materialSurvey.id,
91
+ answers: [answer] // FIXME: Type mismatch
92
+ });
93
+
94
+ const {
95
+ surveyResponse
96
+ } = await getOrgMaterialSurveyResponseGet({
97
+ surveyResponseId
98
+ });
99
+ setMaterialSurveyResponse(surveyResponse);
100
+ void refreshOrgMaterialSurvey();
101
+ onSubmit(true);
102
+ setSubmitStatus('resolved');
103
+ } catch (error) {
104
+ console.error(error);
105
+ onSubmit(false);
106
+ setSubmitStatus('rejected');
107
+ }
108
+ };
109
+ const commonProps = {
143
110
  type: 'text',
144
111
  autoFocus: answer.length === 0,
145
112
  disabled: submitStatus === 'pending' || checkUserLectureTestEnded(lecture) || !!userId,
@@ -147,19 +114,19 @@ var MaterialSurveyText = function MaterialSurveyText() {
147
114
  id: 'materialSurvey.text.placeholder'
148
115
  }),
149
116
  value: answer,
150
- onChange: function onChange(e) {
117
+ onChange: e => {
151
118
  setAnswer(e.target.value);
152
119
  }
153
120
  };
154
- return jsx(SurveyContentBox, {
121
+ return React.createElement(SurveyContentBox, {
155
122
  title: intl.formatMessage({
156
123
  id: 'materialSurvey.myAnswer'
157
124
  }),
158
125
  onNext: onNext,
159
- submitResult: jsx(SurveyResultBadge, {
126
+ submitResult: React.createElement(SurveyResultBadge, {
160
127
  materialSurveyResponse: materialSurveyResponse
161
128
  }),
162
- submitStatus: jsx(SurveySubmitStatusText, {
129
+ submitStatus: React.createElement(SurveySubmitStatusText, {
163
130
  status: submitStatus
164
131
  }),
165
132
  footerActions: [{
@@ -173,11 +140,10 @@ var MaterialSurveyText = function MaterialSurveyText() {
173
140
  transparent: false,
174
141
  role: 'primary',
175
142
  onClick: handleSubmit
176
- }],
177
- children: jsx(StyledTextarea, Object.assign({
178
- id: "survey-text-answer"
179
- }, commonProps))
180
- });
143
+ }]
144
+ }, React.createElement(StyledTextarea, Object.assign({
145
+ id: "survey-text-answer"
146
+ }, commonProps)));
181
147
  };
182
148
 
183
149
  export { MaterialSurveyText as default };
@@ -1,24 +1,21 @@
1
- import { jsx } from 'react/jsx-runtime';
2
1
  import React from 'react';
3
2
  import { BadgeNext } from '@elice/blocks';
4
3
  import { useRawEliceIntl } from '@elice/intl';
5
4
  import { getSurveyResultStatus, SurveyResultStatus } from '../../helpers/index.js';
6
5
 
7
- var SurveyResultBadge = function SurveyResultBadge(_ref) {
8
- var materialSurveyResponse = _ref.materialSurveyResponse;
9
- var intl = useRawEliceIntl();
10
- var status = React.useMemo(function () {
11
- return getSurveyResultStatus(materialSurveyResponse);
12
- }, [materialSurveyResponse]);
6
+ const SurveyResultBadge = ({
7
+ materialSurveyResponse
8
+ }) => {
9
+ const intl = useRawEliceIntl();
10
+ const status = React.useMemo(() => getSurveyResultStatus(materialSurveyResponse), [materialSurveyResponse]);
13
11
  switch (status) {
14
12
  case SurveyResultStatus.Submitted:
15
- return jsx(BadgeNext, {
13
+ return React.createElement(BadgeNext, {
16
14
  type: "quiet",
17
- role: "primary",
18
- children: intl.formatMessage({
19
- id: 'materialSurvey.resultStatus.submitted'
20
- })
21
- });
15
+ role: "primary"
16
+ }, intl.formatMessage({
17
+ id: 'materialSurvey.resultStatus.submitted'
18
+ }));
22
19
  default:
23
20
  return null;
24
21
  }
@@ -1,32 +1,31 @@
1
- import { jsx } from 'react/jsx-runtime';
1
+ import React from 'react';
2
2
  import { StatusText } from '@elice/blocks';
3
3
  import { useRawEliceIntl } from '@elice/intl';
4
4
  import { colors } from '@elice/mui-system';
5
5
  import styled from 'styled-components';
6
6
 
7
- var StyledSuccessStatusText = styled(StatusText).withConfig({
7
+ const StyledSuccessStatusText = styled(StatusText).withConfig({
8
8
  componentId: "sc-szxa5m-0"
9
9
  })(["color:", ";"], colors.green[400]);
10
- var SurveySubmitStatusText = function SurveySubmitStatusText(_ref) {
11
- var status = _ref.status;
12
- var intl = useRawEliceIntl();
10
+ const SurveySubmitStatusText = ({
11
+ status
12
+ }) => {
13
+ const intl = useRawEliceIntl();
13
14
  switch (status) {
14
15
  case 'resolved':
15
- return jsx(StyledSuccessStatusText, {
16
+ return React.createElement(StyledSuccessStatusText, {
16
17
  role: "success",
17
- size: "small",
18
- children: intl.formatMessage({
19
- id: 'materialSurvey.submitStatus.success'
20
- })
21
- });
18
+ size: "small"
19
+ }, intl.formatMessage({
20
+ id: 'materialSurvey.submitStatus.success'
21
+ }));
22
22
  case 'rejected':
23
- return jsx(StatusText, {
23
+ return React.createElement(StatusText, {
24
24
  role: "danger",
25
- size: "small",
26
- children: intl.formatMessage({
27
- id: 'materialSurvey.submitStatus.failure'
28
- })
29
- });
25
+ size: "small"
26
+ }, intl.formatMessage({
27
+ id: 'materialSurvey.submitStatus.failure'
28
+ }));
30
29
  default:
31
30
  return null;
32
31
  }
@@ -25,7 +25,7 @@ interface DispatchContextType {
25
25
  setVertical: React.Dispatch<React.SetStateAction<boolean>>;
26
26
  onNext?: () => void;
27
27
  }
28
- declare function MaterialSurveyProvider({ materialSurveyId, userId, onSubmit, onNext, children, }: MaterialSurveyProviderProps): JSX.Element;
28
+ declare function MaterialSurveyProvider({ materialSurveyId, userId, onSubmit, onNext, children, }: MaterialSurveyProviderProps): React.JSX.Element;
29
29
  declare function useMaterialSurveyState(): State;
30
30
  declare function useMaterialSurveyDispatch(): DispatchContextType;
31
31
  export { MaterialSurveyProvider, useMaterialSurveyState, useMaterialSurveyDispatch, };
@@ -1,137 +1,100 @@
1
- import { slicedToArray as _slicedToArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
- import { jsx } from 'react/jsx-runtime';
3
1
  import React from 'react';
4
- import { config, getOrgMaterialSurveyGet, getOrgLectureGet, getOrgCourseGet } from '@elice/api-client';
2
+ import { config, getOrgMaterialSurveyGet, getOrgCourseGet, getOrgLectureGet } from '@elice/api-client';
5
3
  import { useMaterialConfigApiClientUpdate, useMaterialFetchRaw } from '@elice/material-shared-utils';
6
4
  import { enums } from '@elice/types';
7
5
 
8
- var StateContext = React.createContext(undefined);
9
- var DispatchContext = React.createContext(undefined);
6
+ const StateContext = React.createContext(undefined);
7
+ const DispatchContext = React.createContext(undefined);
10
8
  StateContext.displayName = 'MaterialSurveyStateContext';
11
9
  DispatchContext.displayName = 'MaterialSurveyDispatchContext';
12
- function MaterialSurveyProvider(_ref) {
13
- var materialSurveyId = _ref.materialSurveyId,
14
- userId = _ref.userId,
15
- _ref$onSubmit = _ref.onSubmit,
16
- onSubmit = _ref$onSubmit === void 0 ? function () {
17
- return void 0;
18
- } : _ref$onSubmit,
19
- onNext = _ref.onNext,
20
- children = _ref.children;
21
- var _React$useState = React.useState(),
22
- _React$useState2 = _slicedToArray(_React$useState, 2),
23
- course = _React$useState2[0],
24
- setCourse = _React$useState2[1];
25
- var _React$useState3 = React.useState(),
26
- _React$useState4 = _slicedToArray(_React$useState3, 2),
27
- lecture = _React$useState4[0],
28
- setLecture = _React$useState4[1];
29
- var _React$useState5 = React.useState('idle'),
30
- _React$useState6 = _slicedToArray(_React$useState5, 2),
31
- initStatus = _React$useState6[0],
32
- setInitStatus = _React$useState6[1];
33
- var _React$useState7 = React.useState(false),
34
- _React$useState8 = _slicedToArray(_React$useState7, 2),
35
- vertical = _React$useState8[0],
36
- setVertical = _React$useState8[1];
37
- var canInit = useMaterialConfigApiClientUpdate(config.init);
38
- var _useMaterialFetchRaw = useMaterialFetchRaw(enums.LectureMaterialType.Survey, React.useCallback(function (signal) {
39
- return getOrgMaterialSurveyGet({
40
- materialSurveyId: materialSurveyId
10
+ function MaterialSurveyProvider({
11
+ materialSurveyId,
12
+ userId,
13
+ onSubmit = () => void 0,
14
+ onNext,
15
+ children
16
+ }) {
17
+ const [course, setCourse] = React.useState();
18
+ const [lecture, setLecture] = React.useState();
19
+ const [initStatus, setInitStatus] = React.useState('idle');
20
+ const [vertical, setVertical] = React.useState(false);
21
+ const canInit = useMaterialConfigApiClientUpdate(config.init);
22
+ const {
23
+ materialSurvey,
24
+ materialLecturePage,
25
+ refetch: refreshOrgMaterialSurvey
26
+ } = useMaterialFetchRaw(enums.LectureMaterialType.Survey, React.useCallback(signal => getOrgMaterialSurveyGet({
27
+ materialSurveyId
28
+ }, {
29
+ signal
30
+ }), [materialSurveyId]), canInit);
31
+ const doInitilize = React.useCallback(async () => {
32
+ const controller = new AbortController();
33
+ const {
34
+ signal
35
+ } = controller;
36
+ try {
37
+ setInitStatus('pending');
38
+ if (!materialLecturePage) {
39
+ throw new Error('materialSurvey is not ready');
40
+ }
41
+ // fetch course
42
+ const {
43
+ course
44
+ } = await getOrgCourseGet({
45
+ courseId: materialLecturePage.courseId
41
46
  }, {
42
- signal: signal
47
+ signal
43
48
  });
44
- }, [materialSurveyId]), canInit),
45
- materialSurvey = _useMaterialFetchRaw.materialSurvey,
46
- materialLecturePage = _useMaterialFetchRaw.materialLecturePage,
47
- refreshOrgMaterialSurvey = _useMaterialFetchRaw.refetch;
48
- var doInitilize = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
49
- var controller, signal, _yield$getOrgCourseGe, _course, _yield$getOrgLectureG, _lecture;
50
- return _regeneratorRuntime().wrap(function _callee$(_context) {
51
- while (1) switch (_context.prev = _context.next) {
52
- case 0:
53
- controller = new AbortController();
54
- signal = controller.signal;
55
- _context.prev = 2;
56
- setInitStatus('pending');
57
- if (materialLecturePage) {
58
- _context.next = 6;
59
- break;
60
- }
61
- throw new Error('materialSurvey is not ready');
62
- case 6:
63
- _context.next = 8;
64
- return getOrgCourseGet({
65
- courseId: materialLecturePage.courseId
66
- }, {
67
- signal: signal
68
- });
69
- case 8:
70
- _yield$getOrgCourseGe = _context.sent;
71
- _course = _yield$getOrgCourseGe.course;
72
- _context.next = 12;
73
- return getOrgLectureGet({
74
- lectureId: materialLecturePage.lectureId
75
- }, {
76
- signal: signal
77
- });
78
- case 12:
79
- _yield$getOrgLectureG = _context.sent;
80
- _lecture = _yield$getOrgLectureG.lecture;
81
- setCourse(_course);
82
- setLecture(_lecture);
83
- setInitStatus('resolved');
84
- _context.next = 23;
85
- break;
86
- case 19:
87
- _context.prev = 19;
88
- _context.t0 = _context["catch"](2);
89
- console.error(_context.t0);
90
- setInitStatus('rejected');
91
- case 23:
92
- return _context.abrupt("return", function () {
93
- return controller.abort();
94
- });
95
- case 24:
96
- case "end":
97
- return _context.stop();
98
- }
99
- }, _callee, null, [[2, 19]]);
100
- })), [materialLecturePage]);
101
- React.useEffect(function () {
49
+ // fetch lecture
50
+ const {
51
+ lecture
52
+ } = await getOrgLectureGet({
53
+ lectureId: materialLecturePage.lectureId
54
+ }, {
55
+ signal
56
+ });
57
+ setCourse(course);
58
+ setLecture(lecture);
59
+ setInitStatus('resolved');
60
+ } catch (error) {
61
+ console.error(error);
62
+ setInitStatus('rejected');
63
+ }
64
+ return () => controller.abort();
65
+ }, [materialLecturePage]);
66
+ React.useEffect(() => {
102
67
  if (canInit && materialLecturePage) {
103
68
  void doInitilize();
104
69
  }
105
70
  }, [canInit, materialLecturePage, doInitilize]);
106
- return jsx(StateContext.Provider, {
71
+ return React.createElement(StateContext.Provider, {
107
72
  value: {
108
- course: course,
109
- lecture: lecture,
73
+ course,
74
+ lecture,
110
75
  materialSurvey: materialSurvey !== null && materialSurvey !== void 0 ? materialSurvey : undefined,
111
- userId: userId,
112
- vertical: vertical,
113
- initStatus: initStatus
114
- },
115
- children: jsx(DispatchContext.Provider, {
116
- value: {
117
- onSubmit: onSubmit,
118
- onNext: onNext,
119
- refreshOrgMaterialSurvey: refreshOrgMaterialSurvey,
120
- setVertical: setVertical
121
- },
122
- children: children
123
- })
124
- });
76
+ userId,
77
+ vertical,
78
+ initStatus
79
+ }
80
+ }, React.createElement(DispatchContext.Provider, {
81
+ value: {
82
+ onSubmit,
83
+ onNext,
84
+ refreshOrgMaterialSurvey,
85
+ setVertical
86
+ }
87
+ }, children));
125
88
  }
126
89
  function useMaterialSurveyState() {
127
- var context = React.useContext(StateContext);
90
+ const context = React.useContext(StateContext);
128
91
  if (context === undefined) {
129
92
  throw new Error('useMaterialSurveyState must be used within a MaterialSurveyProvider');
130
93
  }
131
94
  return context;
132
95
  }
133
96
  function useMaterialSurveyDispatch() {
134
- var context = React.useContext(DispatchContext);
97
+ const context = React.useContext(DispatchContext);
135
98
  if (context === undefined) {
136
99
  throw new Error('useMaterialSurveyDispatch must be used within a MaterialSurveyProvider');
137
100
  }