@coorpacademy/app-review 0.8.6 → 0.8.7-alpha.3

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.
@@ -152,7 +152,7 @@ export declare type ConnectedOptions = {
152
152
  export declare type AppOptions = ConnectedOptions & {
153
153
  token: string;
154
154
  skillRef?: string;
155
- services: Services;
155
+ services?: Services;
156
156
  callbackOnViewChanged?: (viewName: ViewName) => void;
157
157
  };
158
158
  export declare type ThunkOptions = {
@@ -85,7 +85,7 @@ const buildStackSlides = (state, dispatch, options) => {
85
85
  if (!slideFromAPI)
86
86
  return set(index, { ...uiSlide, position }, acc);
87
87
  const answers = getOr([], ['ui', 'answers', slideRef], state);
88
- const { questionText, answerUI } = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
88
+ const { questionText, answerUI } = mapApiSlideToUi(dispatch, translate)(slideFromAPI, answers);
89
89
  const { title: parentContentTitle, type: parentContentType } = slideFromAPI.parentContentTitle;
90
90
  const isCurrentSlideRef = currentSlideRef === slideRef;
91
91
  const slideUI = get(['ui', 'slide', slideRef], state);
@@ -2,7 +2,7 @@ import { Dispatch } from 'redux';
2
2
  import { AnswerUI } from '../../types/slides';
3
3
  import { Question, SlideFromAPI } from '../../types/common';
4
4
  export declare const getQuestionType: (question: Question) => Question['type'];
5
- export declare const mapApiSlideToUi: (dispatch: Dispatch) => (slide: SlideFromAPI, answers: string[]) => {
5
+ export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: (key: string, data?: unknown) => string) => (slide: SlideFromAPI, answers: string[]) => {
6
6
  questionText: string;
7
7
  answerUI: AnswerUI;
8
8
  };
@@ -54,11 +54,11 @@ const updateTemplateAnswer = (text, _answers, index, max) => {
54
54
  const answers = isEmpty(_answers) ? times(constant(undefined), max) : _answers;
55
55
  return map(a => (isNil(a) ? '' : a), set(index, text, answers));
56
56
  };
57
- const templateTextProps = (dispatch, answers, choice, index, maxLength) => {
57
+ const templateTextProps = (dispatch, translate, answers, choice, index, maxLength) => {
58
58
  return {
59
59
  type: 'text',
60
60
  name: getOr('', 'name', choice),
61
- placeholder: 'Type here',
61
+ placeholder: translate('Type here'),
62
62
  value: get(index, answers),
63
63
  onChange: (text) => {
64
64
  const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
@@ -66,10 +66,10 @@ const templateTextProps = (dispatch, answers, choice, index, maxLength) => {
66
66
  }
67
67
  };
68
68
  };
69
- const templateSelectProps = (dispatch, answers, choice, index, maxLength) => {
69
+ const templateSelectProps = (dispatch, translate, answers, choice, index, maxLength) => {
70
70
  const answer = get(index, answers);
71
71
  const temporaryOption = {
72
- name: 'Select an answer',
72
+ name: translate('Select an answer'),
73
73
  value: '',
74
74
  validOption: false,
75
75
  selected: true
@@ -93,15 +93,15 @@ const templateSelectProps = (dispatch, answers, choice, index, maxLength) => {
93
93
  options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
94
94
  };
95
95
  };
96
- const templateProps = (dispatch) => (answers, question) => {
96
+ const templateProps = (dispatch, translate) => (answers, question) => {
97
97
  const choices = question.content.choices;
98
98
  const maxLength = size(choices);
99
99
  return {
100
100
  type: 'template',
101
101
  template: get('content.template', question),
102
102
  answers: choices.map((choice, index) => choice.type === 'text'
103
- ? templateTextProps(dispatch, answers, choice, index, maxLength)
104
- : templateSelectProps(dispatch, answers, choice, index, maxLength))
103
+ ? templateTextProps(dispatch, translate, answers, choice, index, maxLength)
104
+ : templateSelectProps(dispatch, translate, answers, choice, index, maxLength))
105
105
  };
106
106
  };
107
107
  const basicProps = (dispatch) => (answers, question) => {
@@ -144,7 +144,7 @@ const sliderProps = (dispatch) => (answers, question) => {
144
144
  };
145
145
  export const getQuestionType = (question) => question.type;
146
146
  const getHelp = (slide) => get('question.explanation', slide);
147
- const getAnswerUIModel = (question, answers, dispatch) => {
147
+ const getAnswerUIModel = (question, answers, dispatch, translate) => {
148
148
  const type = getQuestionType(question);
149
149
  switch (type) {
150
150
  case 'qcm':
@@ -156,17 +156,20 @@ const getAnswerUIModel = (question, answers, dispatch) => {
156
156
  case 'basic':
157
157
  return basicProps(dispatch)(answers, question);
158
158
  case 'template':
159
- return templateProps(dispatch)(answers, question);
159
+ return templateProps(dispatch, translate)(answers, question);
160
160
  case 'slider':
161
161
  return sliderProps(dispatch)(answers, question);
162
162
  default:
163
163
  throw new Error(`${type} is not an handled question.type`);
164
164
  }
165
165
  };
166
- export const mapApiSlideToUi = (dispatch) => (slide, answers) => {
166
+ export const mapApiSlideToUi = (dispatch, translate) => (slide, answers) => {
167
167
  const questionText = getOr('', 'question.header', slide);
168
168
  return {
169
169
  questionText,
170
- answerUI: { model: getAnswerUIModel(slide.question, answers, dispatch), help: getHelp(slide) }
170
+ answerUI: {
171
+ model: getAnswerUIModel(slide.question, answers, dispatch, translate),
172
+ help: getHelp(slide)
173
+ }
171
174
  };
172
175
  };
@@ -152,7 +152,7 @@ export declare type ConnectedOptions = {
152
152
  export declare type AppOptions = ConnectedOptions & {
153
153
  token: string;
154
154
  skillRef?: string;
155
- services: Services;
155
+ services?: Services;
156
156
  callbackOnViewChanged?: (viewName: ViewName) => void;
157
157
  };
158
158
  export declare type ThunkOptions = {
@@ -91,7 +91,7 @@ const buildStackSlides = (state, dispatch, options) => {
91
91
  if (!slideFromAPI)
92
92
  return (0, set_1.default)(index, { ...uiSlide, position }, acc);
93
93
  const answers = (0, getOr_1.default)([], ['ui', 'answers', slideRef], state);
94
- const { questionText, answerUI } = (0, map_api_slide_to_ui_1.mapApiSlideToUi)(dispatch)(slideFromAPI, answers);
94
+ const { questionText, answerUI } = (0, map_api_slide_to_ui_1.mapApiSlideToUi)(dispatch, translate)(slideFromAPI, answers);
95
95
  const { title: parentContentTitle, type: parentContentType } = slideFromAPI.parentContentTitle;
96
96
  const isCurrentSlideRef = currentSlideRef === slideRef;
97
97
  const slideUI = (0, get_1.default)(['ui', 'slide', slideRef], state);
@@ -2,7 +2,7 @@ import { Dispatch } from 'redux';
2
2
  import { AnswerUI } from '../../types/slides';
3
3
  import { Question, SlideFromAPI } from '../../types/common';
4
4
  export declare const getQuestionType: (question: Question) => Question['type'];
5
- export declare const mapApiSlideToUi: (dispatch: Dispatch) => (slide: SlideFromAPI, answers: string[]) => {
5
+ export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: (key: string, data?: unknown) => string) => (slide: SlideFromAPI, answers: string[]) => {
6
6
  questionText: string;
7
7
  answerUI: AnswerUI;
8
8
  };
@@ -57,11 +57,11 @@ const updateTemplateAnswer = (text, _answers, index, max) => {
57
57
  const answers = (0, fp_1.isEmpty)(_answers) ? (0, fp_1.times)((0, fp_1.constant)(undefined), max) : _answers;
58
58
  return (0, fp_1.map)(a => ((0, fp_1.isNil)(a) ? '' : a), (0, fp_1.set)(index, text, answers));
59
59
  };
60
- const templateTextProps = (dispatch, answers, choice, index, maxLength) => {
60
+ const templateTextProps = (dispatch, translate, answers, choice, index, maxLength) => {
61
61
  return {
62
62
  type: 'text',
63
63
  name: (0, fp_1.getOr)('', 'name', choice),
64
- placeholder: 'Type here',
64
+ placeholder: translate('Type here'),
65
65
  value: (0, fp_1.get)(index, answers),
66
66
  onChange: (text) => {
67
67
  const newAnswers = updateTemplateAnswer(text, answers, index, maxLength);
@@ -69,10 +69,10 @@ const templateTextProps = (dispatch, answers, choice, index, maxLength) => {
69
69
  }
70
70
  };
71
71
  };
72
- const templateSelectProps = (dispatch, answers, choice, index, maxLength) => {
72
+ const templateSelectProps = (dispatch, translate, answers, choice, index, maxLength) => {
73
73
  const answer = (0, fp_1.get)(index, answers);
74
74
  const temporaryOption = {
75
- name: 'Select an answer',
75
+ name: translate('Select an answer'),
76
76
  value: '',
77
77
  validOption: false,
78
78
  selected: true
@@ -96,15 +96,15 @@ const templateSelectProps = (dispatch, answers, choice, index, maxLength) => {
96
96
  options: (0, fp_1.isEmpty)(answer) ? (0, fp_1.concat)([temporaryOption], selectOptions) : selectOptions
97
97
  };
98
98
  };
99
- const templateProps = (dispatch) => (answers, question) => {
99
+ const templateProps = (dispatch, translate) => (answers, question) => {
100
100
  const choices = question.content.choices;
101
101
  const maxLength = (0, fp_1.size)(choices);
102
102
  return {
103
103
  type: 'template',
104
104
  template: (0, fp_1.get)('content.template', question),
105
105
  answers: choices.map((choice, index) => choice.type === 'text'
106
- ? templateTextProps(dispatch, answers, choice, index, maxLength)
107
- : templateSelectProps(dispatch, answers, choice, index, maxLength))
106
+ ? templateTextProps(dispatch, translate, answers, choice, index, maxLength)
107
+ : templateSelectProps(dispatch, translate, answers, choice, index, maxLength))
108
108
  };
109
109
  };
110
110
  const basicProps = (dispatch) => (answers, question) => {
@@ -148,7 +148,7 @@ const sliderProps = (dispatch) => (answers, question) => {
148
148
  const getQuestionType = (question) => question.type;
149
149
  exports.getQuestionType = getQuestionType;
150
150
  const getHelp = (slide) => (0, fp_1.get)('question.explanation', slide);
151
- const getAnswerUIModel = (question, answers, dispatch) => {
151
+ const getAnswerUIModel = (question, answers, dispatch, translate) => {
152
152
  const type = (0, exports.getQuestionType)(question);
153
153
  switch (type) {
154
154
  case 'qcm':
@@ -160,18 +160,21 @@ const getAnswerUIModel = (question, answers, dispatch) => {
160
160
  case 'basic':
161
161
  return basicProps(dispatch)(answers, question);
162
162
  case 'template':
163
- return templateProps(dispatch)(answers, question);
163
+ return templateProps(dispatch, translate)(answers, question);
164
164
  case 'slider':
165
165
  return sliderProps(dispatch)(answers, question);
166
166
  default:
167
167
  throw new Error(`${type} is not an handled question.type`);
168
168
  }
169
169
  };
170
- const mapApiSlideToUi = (dispatch) => (slide, answers) => {
170
+ const mapApiSlideToUi = (dispatch, translate) => (slide, answers) => {
171
171
  const questionText = (0, fp_1.getOr)('', 'question.header', slide);
172
172
  return {
173
173
  questionText,
174
- answerUI: { model: getAnswerUIModel(slide.question, answers, dispatch), help: getHelp(slide) }
174
+ answerUI: {
175
+ model: getAnswerUIModel(slide.question, answers, dispatch, translate),
176
+ help: getHelp(slide)
177
+ }
175
178
  };
176
179
  };
177
180
  exports.mapApiSlideToUi = mapApiSlideToUi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.8.6",
3
+ "version": "0.8.7-alpha.3+0559c5b9a",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@coorpacademy/components": "10.28.5",
39
39
  "@coorpacademy/redux-task": "1.1.6",
40
- "@coorpacademy/translate": "^6.1.5",
40
+ "@coorpacademy/translate": "6.1.5",
41
41
  "cross-fetch": "^3.1.5",
42
42
  "jwt-decode": "^3.1.2",
43
43
  "react-redux": "^7.2.9",
@@ -70,5 +70,6 @@
70
70
  "webpack": "^5.74.0",
71
71
  "webpack-cli": "^4.10.0",
72
72
  "webpack-dev-server": "^4.11.1"
73
- }
73
+ },
74
+ "gitHead": "0559c5b9a50e972f2b6fff74f01bef296025f601"
74
75
  }