@coorpacademy/app-review 0.0.21-alpha.4 → 0.1.1

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 (260) hide show
  1. package/es/actions/courses.d.ts +2 -3
  2. package/es/actions/data/is-fetching.d.ts +5 -0
  3. package/es/actions/data/is-fetching.js +4 -0
  4. package/es/actions/data/validate-slide.d.ts +5 -0
  5. package/es/actions/data/validate-slide.js +6 -0
  6. package/es/actions/finished-slides.d.ts +7 -0
  7. package/es/actions/finished-slides.js +7 -0
  8. package/es/actions/index.d.ts +2 -5
  9. package/es/actions/index.js +1 -3
  10. package/es/actions/navigation.d.ts +5 -6
  11. package/es/actions/review-status.d.ts +7 -0
  12. package/es/actions/review-status.js +7 -0
  13. package/es/actions/slides.d.ts +20 -0
  14. package/es/actions/slides.js +17 -0
  15. package/es/actions/step-items.d.ts +14 -0
  16. package/es/actions/step-items.js +12 -0
  17. package/es/actions/token.d.ts +0 -1
  18. package/es/common/index.d.ts +8 -0
  19. package/es/common/index.js +8 -0
  20. package/es/configure-store.d.ts +3 -12
  21. package/es/configure-store.js +5 -7
  22. package/es/fixtures/qcm-slide.d.ts +2 -0
  23. package/es/fixtures/qcm-slide.js +29 -0
  24. package/es/fixtures/temp-fixture.d.ts +3 -0
  25. package/es/fixtures/temp-fixture.js +84 -0
  26. package/es/helpers/css-register.d.ts +1 -0
  27. package/es/helpers/css-register.js +2 -0
  28. package/es/index.d.ts +5 -12
  29. package/es/index.js +62 -14
  30. package/es/index.test.d.ts +1 -0
  31. package/es/index.test.js +52 -0
  32. package/es/middlewares/on-start-app.d.ts +1 -2
  33. package/es/middlewares/on-start-app.js +20 -9
  34. package/es/reducers/courses.d.ts +2 -3
  35. package/es/reducers/courses.js +2 -1
  36. package/es/reducers/data.d.ts +7 -0
  37. package/es/reducers/data.js +76 -0
  38. package/es/reducers/finished-slides.d.ts +6 -0
  39. package/es/reducers/finished-slides.js +32 -0
  40. package/es/reducers/index.d.ts +11 -6
  41. package/es/reducers/index.js +14 -4
  42. package/es/reducers/navigation.d.ts +4 -3
  43. package/es/reducers/navigation.js +4 -1
  44. package/es/reducers/review-status.d.ts +5 -0
  45. package/es/reducers/review-status.js +15 -0
  46. package/es/reducers/slides.d.ts +6 -0
  47. package/es/reducers/slides.js +112 -0
  48. package/es/reducers/step-items.d.ts +6 -0
  49. package/es/reducers/step-items.js +75 -0
  50. package/es/reducers/token.d.ts +5 -7
  51. package/es/reducers/token.js +4 -12
  52. package/es/services/fetch-demo.d.ts +0 -1
  53. package/es/services/fetch-demo.test.d.ts +0 -1
  54. package/es/services/fetch-responses.d.ts +6 -7
  55. package/es/services/fetch-responses.js +2 -2
  56. package/es/services/fetch.mocks.d.ts +3 -4
  57. package/es/services/fetch.mocks.js +3 -3
  58. package/es/types/common.d.ts +7 -0
  59. package/es/types/common.js +1 -0
  60. package/es/types/data/index.d.ts +14 -0
  61. package/es/types/data/index.js +1 -0
  62. package/es/types/dispatchers.d.ts +17 -0
  63. package/es/types/dispatchers.js +1 -0
  64. package/es/types/finished-slides.d.ts +9 -0
  65. package/es/types/finished-slides.js +1 -0
  66. package/es/types/review-status.d.ts +1 -0
  67. package/es/types/review-status.js +1 -0
  68. package/es/types/slides.d.ts +87 -0
  69. package/es/types/slides.js +1 -0
  70. package/es/types/states.d.ts +6 -0
  71. package/es/types/states.js +1 -0
  72. package/es/types/step-items.d.ts +26 -0
  73. package/es/types/step-items.js +5 -0
  74. package/es/types/store-state.d.ts +12 -0
  75. package/es/types/store-state.js +1 -0
  76. package/es/types/utils.d.ts +3 -0
  77. package/es/types/utils.js +1 -0
  78. package/es/types/views.d.ts +64 -0
  79. package/es/types/views.js +1 -0
  80. package/lib/actions/courses.d.ts +2 -3
  81. package/lib/actions/data/is-fetching.d.ts +5 -0
  82. package/lib/actions/data/is-fetching.js +4 -0
  83. package/lib/actions/data/validate-slide.d.ts +5 -0
  84. package/lib/actions/data/validate-slide.js +6 -0
  85. package/lib/actions/finished-slides.d.ts +7 -0
  86. package/lib/actions/finished-slides.js +7 -0
  87. package/lib/actions/index.d.ts +2 -5
  88. package/lib/actions/index.js +1 -3
  89. package/lib/actions/navigation.d.ts +5 -6
  90. package/lib/actions/review-status.d.ts +7 -0
  91. package/lib/actions/review-status.js +7 -0
  92. package/lib/actions/slides.d.ts +20 -0
  93. package/lib/actions/slides.js +17 -0
  94. package/lib/actions/step-items.d.ts +14 -0
  95. package/lib/actions/step-items.js +12 -0
  96. package/lib/actions/token.d.ts +0 -1
  97. package/lib/common/index.d.ts +8 -0
  98. package/lib/common/index.js +8 -0
  99. package/lib/configure-store.d.ts +3 -12
  100. package/lib/configure-store.js +10 -59
  101. package/lib/fixtures/qcm-slide.d.ts +2 -0
  102. package/lib/fixtures/qcm-slide.js +29 -0
  103. package/lib/fixtures/temp-fixture.d.ts +3 -0
  104. package/lib/fixtures/temp-fixture.js +84 -0
  105. package/lib/helpers/css-register.d.ts +1 -0
  106. package/lib/helpers/css-register.js +2 -0
  107. package/lib/index.d.ts +5 -12
  108. package/lib/index.js +71 -34
  109. package/lib/index.test.d.ts +1 -0
  110. package/lib/index.test.js +160 -0
  111. package/lib/middlewares/on-start-app.d.ts +1 -2
  112. package/lib/middlewares/on-start-app.js +29 -16
  113. package/lib/reducers/courses.d.ts +2 -3
  114. package/lib/reducers/courses.js +2 -1
  115. package/lib/reducers/data.d.ts +7 -0
  116. package/lib/reducers/data.js +77 -0
  117. package/lib/reducers/finished-slides.d.ts +6 -0
  118. package/lib/reducers/finished-slides.js +44 -0
  119. package/lib/reducers/index.d.ts +11 -6
  120. package/lib/reducers/index.js +14 -4
  121. package/lib/reducers/navigation.d.ts +4 -3
  122. package/lib/reducers/navigation.js +6 -1
  123. package/lib/reducers/review-status.d.ts +5 -0
  124. package/lib/reducers/review-status.js +16 -0
  125. package/lib/reducers/slides.d.ts +6 -0
  126. package/lib/reducers/slides.js +119 -0
  127. package/lib/reducers/step-items.d.ts +6 -0
  128. package/lib/reducers/step-items.js +87 -0
  129. package/lib/reducers/token.d.ts +5 -7
  130. package/lib/reducers/token.js +4 -13
  131. package/lib/services/fetch-demo.d.ts +0 -1
  132. package/lib/services/fetch-demo.js +25 -23
  133. package/lib/services/fetch-demo.test.d.ts +0 -1
  134. package/lib/services/fetch-responses.d.ts +6 -7
  135. package/lib/services/fetch-responses.js +2 -2
  136. package/lib/services/fetch.mocks.d.ts +3 -4
  137. package/lib/services/fetch.mocks.js +28 -16
  138. package/lib/types/common.d.ts +7 -0
  139. package/lib/types/common.js +1 -0
  140. package/lib/types/data/index.d.ts +14 -0
  141. package/lib/types/data/index.js +1 -0
  142. package/lib/types/dispatchers.d.ts +17 -0
  143. package/lib/types/dispatchers.js +1 -0
  144. package/lib/types/finished-slides.d.ts +9 -0
  145. package/lib/types/finished-slides.js +1 -0
  146. package/lib/types/review-status.d.ts +1 -0
  147. package/lib/types/review-status.js +1 -0
  148. package/lib/types/slides.d.ts +87 -0
  149. package/lib/types/slides.js +1 -0
  150. package/lib/types/states.d.ts +6 -0
  151. package/lib/types/states.js +1 -0
  152. package/lib/types/step-items.d.ts +26 -0
  153. package/lib/types/step-items.js +5 -0
  154. package/lib/types/store-state.d.ts +12 -0
  155. package/lib/types/store-state.js +1 -0
  156. package/lib/types/utils.d.ts +3 -0
  157. package/lib/types/utils.js +1 -0
  158. package/lib/types/views.d.ts +64 -0
  159. package/lib/types/views.js +1 -0
  160. package/package.json +21 -7
  161. package/src/actions/courses.ts +2 -2
  162. package/src/actions/data/is-fetching.ts +12 -0
  163. package/src/actions/data/validate-slide.ts +15 -0
  164. package/src/actions/finished-slides.ts +21 -0
  165. package/src/actions/index.ts +8 -5
  166. package/src/actions/navigation.ts +6 -5
  167. package/src/actions/review-status.ts +19 -0
  168. package/src/actions/slides.ts +45 -0
  169. package/src/actions/step-items.ts +39 -0
  170. package/src/common/index.ts +14 -0
  171. package/src/configure-store.ts +14 -22
  172. package/src/fixtures/qcm-slide.ts +31 -0
  173. package/src/fixtures/temp-fixture.ts +94 -0
  174. package/src/helpers/css-modules-require-hook.d.ts +4 -0
  175. package/src/helpers/css-register.ts +3 -0
  176. package/src/index.test.tsx +82 -0
  177. package/src/index.tsx +75 -22
  178. package/src/middlewares/on-start-app.ts +35 -20
  179. package/src/reducers/courses.ts +3 -2
  180. package/src/reducers/data.ts +88 -0
  181. package/src/reducers/finished-slides.ts +48 -0
  182. package/src/reducers/index.ts +14 -4
  183. package/src/reducers/navigation.ts +7 -3
  184. package/src/reducers/review-status.ts +23 -0
  185. package/src/reducers/slides.ts +136 -0
  186. package/src/reducers/step-items.ts +112 -0
  187. package/src/reducers/token.ts +6 -15
  188. package/src/services/fetch-demo.ts +17 -15
  189. package/src/services/fetch-responses.ts +7 -7
  190. package/src/services/fetch.mocks.ts +29 -14
  191. package/src/types/common.ts +8 -0
  192. package/src/types/data/index.ts +16 -0
  193. package/src/types/dispatchers.ts +18 -0
  194. package/src/types/finished-slides.ts +9 -0
  195. package/src/types/globals.d.ts +6 -0
  196. package/src/types/review-status.ts +1 -0
  197. package/src/types/slides.ts +107 -0
  198. package/src/types/states.ts +6 -0
  199. package/src/types/step-items.ts +31 -0
  200. package/src/types/store-state.ts +20 -0
  201. package/src/types/utils.ts +4 -0
  202. package/src/types/views.tsx +69 -0
  203. package/es/actions/courses.d.ts.map +0 -1
  204. package/es/actions/index.d.ts.map +0 -1
  205. package/es/actions/navigation.d.ts.map +0 -1
  206. package/es/actions/token.d.ts.map +0 -1
  207. package/es/components/__tmp-backup-vues-mobile/revision-home.d.ts +0 -10
  208. package/es/components/__tmp-backup-vues-mobile/revision-home.d.ts.map +0 -1
  209. package/es/components/__tmp-backup-vues-mobile/revision-home.js +0 -83
  210. package/es/components/__tmp-backup-vues-mobile/revision-home.stories.d.ts +0 -1
  211. package/es/components/__tmp-backup-vues-mobile/revision-home.stories.d.ts.map +0 -1
  212. package/es/components/__tmp-backup-vues-mobile/revision-home.stories.js +0 -14
  213. package/es/components/__tmp-backup-vues-mobile/revision-onboarding.d.ts +0 -4
  214. package/es/components/__tmp-backup-vues-mobile/revision-onboarding.d.ts.map +0 -1
  215. package/es/components/__tmp-backup-vues-mobile/revision-onboarding.js +0 -57
  216. package/es/components/__tmp-backup-vues-mobile/revision-quizzer.d.ts +0 -19
  217. package/es/components/__tmp-backup-vues-mobile/revision-quizzer.d.ts.map +0 -1
  218. package/es/components/__tmp-backup-vues-mobile/revision-quizzer.js +0 -120
  219. package/es/configure-store.d.ts.map +0 -1
  220. package/es/index.d.ts.map +0 -1
  221. package/es/middlewares/on-start-app.d.ts.map +0 -1
  222. package/es/reducers/courses.d.ts.map +0 -1
  223. package/es/reducers/index.d.ts.map +0 -1
  224. package/es/reducers/navigation.d.ts.map +0 -1
  225. package/es/reducers/token.d.ts.map +0 -1
  226. package/es/services/fetch-demo.d.ts.map +0 -1
  227. package/es/services/fetch-demo.test.d.ts.map +0 -1
  228. package/es/services/fetch-responses.d.ts.map +0 -1
  229. package/es/services/fetch.mocks.d.ts.map +0 -1
  230. package/lib/actions/courses.d.ts.map +0 -1
  231. package/lib/actions/index.d.ts.map +0 -1
  232. package/lib/actions/navigation.d.ts.map +0 -1
  233. package/lib/actions/token.d.ts.map +0 -1
  234. package/lib/components/__tmp-backup-vues-mobile/revision-home.d.ts +0 -10
  235. package/lib/components/__tmp-backup-vues-mobile/revision-home.d.ts.map +0 -1
  236. package/lib/components/__tmp-backup-vues-mobile/revision-home.js +0 -98
  237. package/lib/components/__tmp-backup-vues-mobile/revision-home.stories.d.ts +0 -1
  238. package/lib/components/__tmp-backup-vues-mobile/revision-home.stories.d.ts.map +0 -1
  239. package/lib/components/__tmp-backup-vues-mobile/revision-home.stories.js +0 -14
  240. package/lib/components/__tmp-backup-vues-mobile/revision-onboarding.d.ts +0 -4
  241. package/lib/components/__tmp-backup-vues-mobile/revision-onboarding.d.ts.map +0 -1
  242. package/lib/components/__tmp-backup-vues-mobile/revision-onboarding.js +0 -60
  243. package/lib/components/__tmp-backup-vues-mobile/revision-quizzer.d.ts +0 -19
  244. package/lib/components/__tmp-backup-vues-mobile/revision-quizzer.d.ts.map +0 -1
  245. package/lib/components/__tmp-backup-vues-mobile/revision-quizzer.js +0 -128
  246. package/lib/configure-store.d.ts.map +0 -1
  247. package/lib/index.d.ts.map +0 -1
  248. package/lib/middlewares/on-start-app.d.ts.map +0 -1
  249. package/lib/reducers/courses.d.ts.map +0 -1
  250. package/lib/reducers/index.d.ts.map +0 -1
  251. package/lib/reducers/navigation.d.ts.map +0 -1
  252. package/lib/reducers/token.d.ts.map +0 -1
  253. package/lib/services/fetch-demo.d.ts.map +0 -1
  254. package/lib/services/fetch-demo.test.d.ts.map +0 -1
  255. package/lib/services/fetch-responses.d.ts.map +0 -1
  256. package/lib/services/fetch.mocks.d.ts.map +0 -1
  257. package/src/components/__tmp-backup-vues-mobile/revision-home.stories.tsx +0 -16
  258. package/src/components/__tmp-backup-vues-mobile/revision-home.tsx +0 -125
  259. package/src/components/__tmp-backup-vues-mobile/revision-onboarding.tsx +0 -84
  260. package/src/components/__tmp-backup-vues-mobile/revision-quizzer.tsx +0 -176
@@ -0,0 +1,76 @@
1
+ import getOr from 'lodash/fp/getOr';
2
+ import noop from 'lodash/fp/noop';
3
+ import set from 'lodash/fp/set';
4
+ import { STORE_TOKEN } from '../actions/token';
5
+ import { IS_FETCHING_TRUE } from '../actions/data/is-fetching';
6
+ import { VALIDATE_SLIDE } from '../actions/data/validate-slide';
7
+ import { setToken } from './token';
8
+ const defaultState = {
9
+ isFetching: true,
10
+ slideValidationResult: null,
11
+ token: null
12
+ };
13
+ // eslint-disable-next-line default-param-last
14
+ const data = (state = defaultState, action) => {
15
+ switch (action.type) {
16
+ case STORE_TOKEN: {
17
+ return setToken(action.payload, state);
18
+ }
19
+ case VALIDATE_SLIDE: {
20
+ const previousSlideNumber = getOr(-1, 'slideValidationResult.slideNumber', state);
21
+ // hard coded for now
22
+ return set('slideValidationResult', {
23
+ slideNumber: previousSlideNumber + 1,
24
+ result: 'success',
25
+ // exitNode
26
+ nextSlide: {
27
+ questionText: 'Test',
28
+ answerUI: {
29
+ model: {
30
+ answers: [
31
+ {
32
+ title: 'There is no need for a password',
33
+ onClick: noop,
34
+ selected: false
35
+ },
36
+ {
37
+ title: 'Lorem ipsum',
38
+ onClick: noop,
39
+ selected: false
40
+ },
41
+ {
42
+ title: 'Lorem',
43
+ onClick: noop,
44
+ selected: true,
45
+ order: 1
46
+ },
47
+ {
48
+ title: 'You need to have a password',
49
+ onClick: noop,
50
+ selected: false
51
+ },
52
+ {
53
+ title: 'Pouet',
54
+ onClick: noop,
55
+ selected: true,
56
+ order: 0
57
+ }
58
+ ],
59
+ type: 'qcmDrag'
60
+ },
61
+ help: 'Help text will appear here'
62
+ }
63
+ }
64
+ }, state);
65
+ }
66
+ case IS_FETCHING_TRUE: {
67
+ return set('isFetching', true, state);
68
+ }
69
+ // case VALIDATE_SLIDE_FAILURE: {
70
+ // return set('entities.isFetching', false, state);
71
+ // }
72
+ default:
73
+ return state;
74
+ }
75
+ };
76
+ export default data;
@@ -0,0 +1,6 @@
1
+ import { UpdateFinishedSlides } from '../actions/finished-slides';
2
+ import { FinishedSlides } from '../types/finished-slides';
3
+ export declare type State = FinishedSlides;
4
+ export declare const initialState: State;
5
+ declare const reducer: (state: State, action: UpdateFinishedSlides) => State;
6
+ export default reducer;
@@ -0,0 +1,32 @@
1
+ import forEach from 'lodash/fp/forEach';
2
+ import { UPDATE_FINISHED_SLIDES } from '../actions/finished-slides';
3
+ import { slideNumbers } from '../common';
4
+ const _forEach = forEach.convert({
5
+ cap: false
6
+ });
7
+ export const initialState = {
8
+ slideNumbers
9
+ };
10
+ // -----------------------------------------------------------------------------
11
+ // eslint-disable-next-line default-param-last
12
+ const reducer = (state = initialState, action) => {
13
+ switch (action.type) {
14
+ case UPDATE_FINISHED_SLIDES: {
15
+ const { slideNumbers: _slideNumbers, ...rest } = state;
16
+ const { slideNumber, value } = action.payload;
17
+ const _state = {
18
+ slideNumbers: _slideNumbers
19
+ };
20
+ _forEach((finishedSlide, index) => {
21
+ const previousValue = finishedSlide;
22
+ _state[index] = previousValue;
23
+ }, rest);
24
+ _state[slideNumber] = value;
25
+ return _state;
26
+ }
27
+ default:
28
+ return state;
29
+ }
30
+ };
31
+ // -----------------------------------------------------------------------------
32
+ export default reducer;
@@ -1,7 +1,12 @@
1
- declare const rootReducer: import("redux").Reducer<import("redux").CombinedState<{
2
- courses: import("./courses").State;
3
- navigation: import("./navigation").State;
4
- token: string;
1
+ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
2
+ ui: import("redux").CombinedState<{
3
+ courses: import("./courses").State;
4
+ finishedSlides: import("../types/finished-slides").FinishedSlides;
5
+ navigation: import("../types/states").NavigationState;
6
+ reviewStatus: import("./review-status").State;
7
+ slides: import("../types/slides").Slides;
8
+ stepItems: import("../types/step-items").StepItems;
9
+ }>;
10
+ data: import("../types/data").DataState;
5
11
  }>, import("redux").AnyAction>;
6
- export default rootReducer;
7
- //# sourceMappingURL=index.d.ts.map
12
+ export default _default;
@@ -1,10 +1,20 @@
1
1
  import { combineReducers } from 'redux';
2
+ import data from './data';
2
3
  import courses from './courses';
4
+ import finishedSlides from './finished-slides';
3
5
  import navigation from './navigation';
4
- import token from './token';
5
- const rootReducer = combineReducers({
6
+ import reviewStatus from './review-status';
7
+ import slides from './slides';
8
+ import stepItems from './step-items';
9
+ const ui = combineReducers({
6
10
  courses,
11
+ finishedSlides,
7
12
  navigation,
8
- token
13
+ reviewStatus,
14
+ slides,
15
+ stepItems
16
+ });
17
+ export default combineReducers({
18
+ ui,
19
+ data
9
20
  });
10
- export default rootReducer;
@@ -1,7 +1,8 @@
1
+ import { ViewPath } from '../actions/navigation';
1
2
  import type { NavigateTo, NavigateBack } from '../actions/navigation';
2
- export declare type State = Array<string>;
3
+ import { StoreState } from '../types/store-state';
4
+ import { NavigationState as State } from '../types/states';
3
5
  export declare const initialState: State;
4
6
  declare const reducer: (state: State, action: NavigateTo | NavigateBack) => State;
5
- export declare const getCurrentViewName: (appState: any) => any;
7
+ export declare const getCurrentViewName: (appState: StoreState) => ViewPath;
6
8
  export default reducer;
7
- //# sourceMappingURL=navigation.d.ts.map
@@ -1,6 +1,9 @@
1
1
  import { NAVIGATE_BACK, NAVIGATE_TO } from '../actions/navigation';
2
+ // -----------------------------------------------------------------------------
3
+ // export type State = Array<string>;
2
4
  export const initialState = ['home'];
3
5
  // -----------------------------------------------------------------------------
6
+ // eslint-disable-next-line default-param-last
4
7
  const reducer = (state = initialState, action) => {
5
8
  switch (action.type) {
6
9
  case NAVIGATE_TO: {
@@ -16,6 +19,6 @@ const reducer = (state = initialState, action) => {
16
19
  }
17
20
  };
18
21
  // -----------------------------------------------------------------------------
19
- export const getCurrentViewName = appState => appState.navigation[appState.navigation.length - 1];
22
+ export const getCurrentViewName = (appState) => appState.ui.navigation[appState.ui.navigation.length - 1];
20
23
  // -----------------------------------------------------------------------------
21
24
  export default reducer;
@@ -0,0 +1,5 @@
1
+ import { UpdateReviewStatus } from '../actions/review-status';
2
+ export declare type State = 'finished' | 'ongoing';
3
+ export declare const initialState: State;
4
+ declare const reducer: (state: State, action: UpdateReviewStatus) => State;
5
+ export default reducer;
@@ -0,0 +1,15 @@
1
+ import { UPDATE_REVIEW_STATUS } from '../actions/review-status';
2
+ export const initialState = 'ongoing';
3
+ // -----------------------------------------------------------------------------
4
+ // eslint-disable-next-line default-param-last
5
+ const reducer = (state = initialState, action) => {
6
+ switch (action.type) {
7
+ case UPDATE_REVIEW_STATUS: {
8
+ return action.payload;
9
+ }
10
+ default:
11
+ return state;
12
+ }
13
+ };
14
+ // -----------------------------------------------------------------------------
15
+ export default reducer;
@@ -0,0 +1,6 @@
1
+ import { SlidesAction } from '../actions/slides';
2
+ import { Slides } from '../types/slides';
3
+ export declare type State = Slides;
4
+ export declare const initialState: State;
5
+ declare const reducer: (state: State, action: SlidesAction) => State;
6
+ export default reducer;
@@ -0,0 +1,112 @@
1
+ import map from 'lodash/fp/map';
2
+ import { STORE_FIRST_SLIDE, UPDATE_SLIDES_ON_NEXT, UPDATE_SLIDES_ON_VALIDATION } from '../actions/slides';
3
+ import { HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK } from '../common';
4
+ const getInitialState = () => {
5
+ const state = {
6
+ slideNumbers
7
+ };
8
+ // eslint-disable-next-line fp/no-loops
9
+ for (let index = 0; index < TOTAL_SLIDES_STACK; index++) {
10
+ state[index] = { hidden: false, position: index };
11
+ }
12
+ return state;
13
+ };
14
+ export const initialState = getInitialState();
15
+ // -----------------------------------------------------------------------------
16
+ const setFirstSlide = (state, slide) => {
17
+ const _state = {
18
+ slideNumbers
19
+ };
20
+ // eslint-disable-next-line lodash-fp/no-unused-result
21
+ map(index => {
22
+ const previousValue = state[index];
23
+ // Only update the 1st one
24
+ const content = index === 0 ? { ...previousValue, ...slide } : { ...previousValue };
25
+ _state[index] = { ...content };
26
+ }, state.slideNumbers);
27
+ return _state;
28
+ };
29
+ // ||-------> Handles the updates of a given slide on validation,
30
+ // & then updates de remaining slides if this given change should impact their content
31
+ const stateUpdateOnValidation = (state, payload) => {
32
+ const { slideNumber, newSlideContent, numberOfFinishedSlides, nextSlide } = payload;
33
+ const _state = {
34
+ slideNumbers
35
+ };
36
+ // eslint-disable-next-line lodash-fp/no-unused-result
37
+ map(index => {
38
+ const previousValue = state[index];
39
+ // the current slide
40
+ if (index === slideNumber) {
41
+ // only one slide remaining, presets the next value
42
+ if (numberOfFinishedSlides === HIGHEST_INDEX) {
43
+ _state[index] = {
44
+ ...previousValue,
45
+ nextSlide,
46
+ position: newSlideContent.position,
47
+ validationResult: newSlideContent.validationResult
48
+ };
49
+ }
50
+ else
51
+ _state[slideNumber] = { ...previousValue, ...newSlideContent };
52
+ }
53
+ else {
54
+ // updates the rest of the slides here
55
+ const { hidden, position } = previousValue;
56
+ _state[index] = { ...nextSlide, endReview: newSlideContent.endReview, hidden, position };
57
+ }
58
+ }, state.slideNumbers);
59
+ return _state;
60
+ };
61
+ // ||-------> Handles the updates of a given slide on correction popin's next click,
62
+ // & then updates de remaining slides (updates position to trigger animations)
63
+ const stateUpdateOnNext = (state, payload) => {
64
+ const { slideNumber, newSlideContent, numberOfFinishedSlides } = payload;
65
+ const _state = {
66
+ slideNumbers
67
+ };
68
+ // eslint-disable-next-line lodash-fp/no-unused-result
69
+ map(index => {
70
+ const previousValue = state[index];
71
+ // the current slide
72
+ if (index === slideNumber) {
73
+ // when there is only one slide remaining, updates the slide value
74
+ if (numberOfFinishedSlides === HIGHEST_INDEX && previousValue.nextSlide) {
75
+ _state[index] = { ...previousValue.nextSlide, position: previousValue.position };
76
+ }
77
+ else
78
+ _state[slideNumber] = newSlideContent;
79
+ }
80
+ else {
81
+ // updates the rest of the slides here
82
+ const { hidden, position, answerUI, questionText } = previousValue;
83
+ _state[index] = {
84
+ hidden,
85
+ position: position - 1,
86
+ answerUI,
87
+ questionText,
88
+ endReview: newSlideContent.endReview
89
+ };
90
+ }
91
+ }, state.slideNumbers);
92
+ return _state;
93
+ };
94
+ // -----------------------------------------------------------------------------
95
+ // eslint-disable-next-line default-param-last
96
+ const reducer = (state = initialState, action) => {
97
+ switch (action.type) {
98
+ case STORE_FIRST_SLIDE: {
99
+ return setFirstSlide(state, action.payload);
100
+ }
101
+ case UPDATE_SLIDES_ON_VALIDATION: {
102
+ return stateUpdateOnValidation(state, action.payload);
103
+ }
104
+ case UPDATE_SLIDES_ON_NEXT: {
105
+ return stateUpdateOnNext(state, action.payload);
106
+ }
107
+ default:
108
+ return state;
109
+ }
110
+ };
111
+ // -----------------------------------------------------------------------------
112
+ export default reducer;
@@ -0,0 +1,6 @@
1
+ import { StepItemsAction } from '../actions/step-items';
2
+ import { StepItems } from '../types/step-items';
3
+ export declare type State = StepItems;
4
+ export declare const initialState: State;
5
+ declare const reducer: (state: State, action: StepItemsAction) => State;
6
+ export default reducer;
@@ -0,0 +1,75 @@
1
+ import isNil from 'lodash/fp/isNil';
2
+ import get from 'lodash/fp/get';
3
+ import has from 'lodash/fp/has';
4
+ import map from 'lodash/fp/map';
5
+ import { UPDATE_STEP_ITEMS_ON_NEXT, UPDATE_STEP_ITEMS_ON_VALIDATION } from '../actions/step-items';
6
+ import { HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK } from '../common';
7
+ const getInitialState = () => {
8
+ const state = {
9
+ slideNumbers
10
+ };
11
+ // eslint-disable-next-line fp/no-loops
12
+ for (let index = 0; index < TOTAL_SLIDES_STACK; index++) {
13
+ const current = index === 0;
14
+ state[index] = { current, value: `${index + 1}`, icon: null };
15
+ }
16
+ return state;
17
+ };
18
+ export const initialState = getInitialState();
19
+ // -----------------------------------------------------------------------------
20
+ // ||-------> aux function, finds the next consecutive index
21
+ // to loop from 0 to HIGHEST_INDEX (4) & again to 0
22
+ const getNextIndex = (currentIndex) => currentIndex === HIGHEST_INDEX ? 0 : currentIndex + 1;
23
+ // ||-------> calculates which should be the next step to visit (as there can be already answered slides &&
24
+ // they have to be skipped)
25
+ const calculateNextStepIndex = (currentStepNumber, finishedSlides, lastVisitedIndex = null) => {
26
+ // only one slide remaining, the step should stay on the same number
27
+ if (lastVisitedIndex === currentStepNumber) {
28
+ return currentStepNumber;
29
+ }
30
+ const indexToVisit = getNextIndex(isNil(lastVisitedIndex) ? currentStepNumber : lastVisitedIndex);
31
+ // if the index is already included in the correctly answered (finished) slides, then we proceed to check for the next one
32
+ return has(indexToVisit, finishedSlides)
33
+ ? calculateNextStepIndex(currentStepNumber, finishedSlides, indexToVisit)
34
+ : indexToVisit;
35
+ };
36
+ const recalculateStepItemsState = (state, stepNumber, stepItemToUpdateProps) => {
37
+ const nextIndex = get('nextIndex', stepItemToUpdateProps);
38
+ const _state = {
39
+ slideNumbers
40
+ };
41
+ // eslint-disable-next-line lodash-fp/no-unused-result
42
+ map(index => {
43
+ const previousValue = state[index];
44
+ if (stepNumber === index)
45
+ _state[stepNumber] = {
46
+ ...previousValue,
47
+ ...stepItemToUpdateProps
48
+ };
49
+ /* only for UPDATE_STEP_ITEMS_ON_NEXT -> */ else if (nextIndex === index) {
50
+ _state[index] = { ...previousValue, current: true };
51
+ }
52
+ else
53
+ _state[index] = previousValue;
54
+ }, state.slideNumbers);
55
+ return _state;
56
+ };
57
+ // -----------------------------------------------------------------------------
58
+ // eslint-disable-next-line default-param-last
59
+ const reducer = (state = initialState, action) => {
60
+ switch (action.type) {
61
+ case UPDATE_STEP_ITEMS_ON_VALIDATION: {
62
+ const { stepNumber, icon } = action.payload;
63
+ return recalculateStepItemsState(state, stepNumber, { icon });
64
+ }
65
+ case UPDATE_STEP_ITEMS_ON_NEXT: {
66
+ const { stepNumber, finishedSlides, current } = action.payload;
67
+ const nextIndex = !current ? calculateNextStepIndex(stepNumber, finishedSlides) : null;
68
+ return recalculateStepItemsState(state, stepNumber, { current, nextIndex });
69
+ }
70
+ default:
71
+ return state;
72
+ }
73
+ };
74
+ // -----------------------------------------------------------------------------
75
+ export default reducer;
@@ -1,7 +1,5 @@
1
- import { StoreToken } from '../actions';
2
- export declare type State = string;
3
- export declare const initialState: State;
4
- declare const reducer: (state: State, action: StoreToken) => State;
5
- export declare const getToken: (appState: any) => any;
6
- export default reducer;
7
- //# sourceMappingURL=token.d.ts.map
1
+ import { StoreState } from '../types/store-state';
2
+ import { DataState } from '../types/data';
3
+ export declare const initialState: DataState['token'];
4
+ export declare const setToken: (token: string, state: DataState) => DataState;
5
+ export declare const getToken: (appState: StoreState) => StoreState['data']['token'];
@@ -1,16 +1,8 @@
1
- import { STORE_TOKEN } from '../actions';
1
+ import set from 'lodash/fp/set';
2
+ // -----------------------------------------------------------------------------
2
3
  export const initialState = null;
3
4
  // -----------------------------------------------------------------------------
4
- const reducer = (state = initialState, action) => {
5
- switch (action.type) {
6
- case STORE_TOKEN: {
7
- return action.payload;
8
- }
9
- default:
10
- return state;
11
- }
12
- };
5
+ export const setToken = (token, state) => set('token', token, state);
13
6
  // -----------------------------------------------------------------------------
14
- export const getToken = appState => appState.token;
7
+ export const getToken = (appState) => appState.data.token;
15
8
  // -----------------------------------------------------------------------------
16
- export default reducer;
@@ -9,4 +9,3 @@ export declare type CatalogHits = {
9
9
  export { fetchCourse };
10
10
  declare const _default: (token: any, language: any, universalRef: any) => Promise<Course>;
11
11
  export default _default;
12
- //# sourceMappingURL=fetch-demo.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=fetch-demo.test.d.ts.map
@@ -1,4 +1,4 @@
1
- export declare type Response = {
1
+ export declare type _Response = {
2
2
  ok: boolean;
3
3
  status: number;
4
4
  statusText: string;
@@ -9,12 +9,11 @@ export declare type Fetch = (url?: string, options?: {
9
9
  headers: {
10
10
  authorization: string;
11
11
  };
12
- }) => Promise<Response>;
12
+ }) => Promise<_Response>;
13
13
  export declare class ResponseError extends Error {
14
14
  statusCode: number;
15
- constructor(status: number, statusText: string, body?: string);
15
+ constructor(statusCode: number, statusText: string, body?: string);
16
16
  }
17
- export declare const toJSON: (response: Response) => Promise<unknown>;
18
- export declare const toText: (response: Response) => Promise<string>;
19
- export declare const toVoid: (response: Response) => Promise<void>;
20
- //# sourceMappingURL=fetch-responses.d.ts.map
17
+ export declare const toJSON: (response: _Response) => Promise<unknown>;
18
+ export declare const toText: (response: _Response) => Promise<string>;
19
+ export declare const toVoid: (response: _Response) => Promise<void>;
@@ -1,8 +1,8 @@
1
1
  export class ResponseError extends Error {
2
- constructor(status, statusText, body = '') {
2
+ constructor(statusCode, statusText, body = '') {
3
3
  super(`${statusText} ${body}`.trim());
4
4
  this.name = 'ResponseError';
5
- this.statusCode = status;
5
+ this.statusCode = statusCode;
6
6
  }
7
7
  }
8
8
  export const toJSON = async (response) => {
@@ -1,10 +1,9 @@
1
- import { Response } from './fetch-responses';
2
- export declare const toResponse: (status: number, statusText: string, body: string) => Promise<Response>;
3
- declare type FetchFunction = () => Promise<Response>;
1
+ import { _Response } from './fetch-responses';
2
+ export declare const toResponse: (statusCode: number, statusText: string, body: string) => Promise<_Response>;
3
+ declare type FetchFunction = () => Promise<_Response>;
4
4
  export declare const okJSONResponse: (body: unknown) => FetchFunction;
5
5
  export declare const internalServerErrorJSONResponse: (body: unknown) => FetchFunction;
6
6
  export declare const notFoundJSONResponse: (body: unknown) => FetchFunction;
7
7
  export declare const okTextResponse: (body: string) => FetchFunction;
8
8
  export declare const internalServerErrorTextResponse: (body: string) => FetchFunction;
9
9
  export {};
10
- //# sourceMappingURL=fetch.mocks.d.ts.map
@@ -1,6 +1,6 @@
1
- export const toResponse = (status, statusText, body) => Promise.resolve({
2
- ok: status < 400,
3
- status,
1
+ export const toResponse = (statusCode, statusText, body) => Promise.resolve({
2
+ ok: statusCode < 400,
3
+ status: statusCode,
4
4
  statusText,
5
5
  json: () => Promise.resolve(body).then(JSON.parse),
6
6
  text: () => Promise.resolve(body)
@@ -0,0 +1,7 @@
1
+ import { Slide } from './slides';
2
+ export declare type AppOptions = {
3
+ token: string;
4
+ theme?: unknown;
5
+ translations?: unknown;
6
+ slide?: Slide;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { AnswerUI } from '../slides';
2
+ export declare type DataState = {
3
+ isFetching?: boolean;
4
+ slideValidationResult?: {
5
+ slideNumber: number;
6
+ result: 'success' | 'failure';
7
+ exitNode?: 'successExitNode' | 'failExitNode';
8
+ nextSlide: {
9
+ questionText?: string;
10
+ answerUI?: AnswerUI;
11
+ };
12
+ };
13
+ token?: string;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { validateSlide } from '../actions/data/validate-slide';
2
+ import { updateFinishedSlides } from '../actions/finished-slides';
3
+ import { navigateBack, navigateTo } from '../actions/navigation';
4
+ import { updateReviewStatus } from '../actions/review-status';
5
+ import { updateSlidesOnValidation, updateSlidesOnNext } from '../actions/slides';
6
+ import { updateStepItemsOnValidation, updateStepItemsOnNext } from '../actions/step-items';
7
+ export declare type Dispatchers = {
8
+ navigateTo: typeof navigateTo;
9
+ navigateBack: typeof navigateBack;
10
+ validateSlide: typeof validateSlide;
11
+ updateSlidesOnValidation: typeof updateSlidesOnValidation;
12
+ updateSlidesOnNext: typeof updateSlidesOnNext;
13
+ updateReviewStatus: typeof updateReviewStatus;
14
+ updateStepItemsOnValidation: typeof updateStepItemsOnValidation;
15
+ updateStepItemsOnNext: typeof updateStepItemsOnNext;
16
+ updateFinishedSlides: typeof updateFinishedSlides;
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SlideNumber } from './slides';
2
+ export declare type FinishedSlides = {
3
+ slideNumbers: SlideNumber[];
4
+ [key: SlideNumber]: true;
5
+ };
6
+ export declare type UpdateFinishedSlidesPayload = {
7
+ slideNumber: SlideNumber;
8
+ value: true;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare type UpdateReviewStatusPayload = 'finished';
@@ -0,0 +1 @@
1
+ export {};