@coorpacademy/app-review 0.1.7 → 0.1.9
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/es/actions/api/fetch-skills.d.ts +13 -0
- package/es/actions/api/fetch-skills.js +8 -0
- package/es/actions/api/fetch-slide.d.ts +13 -0
- package/es/actions/api/fetch-slide.js +8 -0
- package/es/actions/api/post-progression.d.ts +13 -0
- package/es/actions/api/post-progression.js +15 -0
- package/es/actions/data/slides.d.ts +3 -24
- package/es/actions/data/slides.js +0 -11
- package/es/actions/index.d.ts +5 -4
- package/es/actions/ui/navigation.d.ts +0 -1
- package/es/actions/ui/navigation.js +0 -4
- package/es/actions/ui/step-items.d.ts +2 -8
- package/es/actions/ui/step-items.js +0 -6
- package/es/configure-store.d.ts +3 -26
- package/es/configure-store.js +4 -5
- package/es/fixtures/qcm-slide.d.ts +2 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +40 -26
- package/es/reducers/data/index.d.ts +16 -5
- package/es/reducers/data/progression.d.ts +1 -2
- package/es/reducers/data/progression.js +4 -7
- package/es/reducers/data/skills.d.ts +4 -5
- package/es/reducers/data/skills.js +3 -6
- package/es/reducers/data/slides.d.ts +2 -1
- package/es/reducers/data/slides.js +3 -3
- package/es/reducers/data/token.d.ts +0 -1
- package/es/reducers/data/token.js +1 -5
- package/es/reducers/index.d.ts +9 -3
- package/es/reducers/ui/finished-slides.d.ts +0 -1
- package/es/reducers/ui/finished-slides.js +1 -3
- package/es/reducers/ui/index.d.ts +14 -4
- package/es/reducers/ui/navigation.d.ts +0 -1
- package/es/reducers/ui/navigation.js +1 -3
- package/es/reducers/ui/review-status.d.ts +0 -1
- package/es/reducers/ui/review-status.js +1 -4
- package/es/reducers/ui/step-items.d.ts +5 -5
- package/es/reducers/ui/step-items.js +0 -1
- package/es/services/fetch-skills.d.ts +2 -8
- package/es/services/fetch-skills.js +2 -14
- package/es/services/fetch-slide.d.ts +2 -8
- package/es/services/fetch-slide.js +9 -24
- package/es/services/index.d.ts +2 -0
- package/es/services/index.js +8 -0
- package/es/services/post-progression.d.ts +2 -8
- package/es/services/post-progression.js +2 -14
- package/es/services/test/fetch-skills.test.js +29 -0
- package/es/services/test/post-progression.test.js +35 -0
- package/es/{index.test.js → test/index.test.js} +15 -4
- package/es/test/util/services.mock.d.ts +2 -0
- package/es/test/util/services.mock.js +68 -0
- package/es/types/common.d.ts +58 -0
- package/es/types/common.js +5 -0
- package/es/types/slides.d.ts +1 -1
- package/es/types/views/slides.d.ts +1 -1
- package/lib/actions/api/fetch-skills.d.ts +13 -0
- package/lib/actions/api/fetch-skills.js +13 -0
- package/lib/actions/api/fetch-slide.d.ts +13 -0
- package/lib/actions/api/fetch-slide.js +13 -0
- package/lib/actions/api/post-progression.d.ts +13 -0
- package/lib/actions/api/post-progression.js +18 -0
- package/lib/actions/data/slides.d.ts +3 -24
- package/lib/actions/data/slides.js +0 -11
- package/lib/actions/index.d.ts +5 -4
- package/lib/actions/ui/navigation.d.ts +0 -1
- package/lib/actions/ui/navigation.js +0 -4
- package/lib/actions/ui/step-items.d.ts +2 -8
- package/lib/actions/ui/step-items.js +0 -6
- package/lib/configure-store.d.ts +3 -26
- package/lib/configure-store.js +4 -5
- package/lib/fixtures/qcm-slide.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +40 -70
- package/lib/reducers/data/index.d.ts +16 -5
- package/lib/reducers/data/progression.d.ts +1 -2
- package/lib/reducers/data/progression.js +4 -7
- package/lib/reducers/data/skills.d.ts +4 -5
- package/lib/reducers/data/skills.js +3 -6
- package/lib/reducers/data/slides.d.ts +2 -1
- package/lib/reducers/data/slides.js +3 -3
- package/lib/reducers/data/token.d.ts +0 -1
- package/lib/reducers/data/token.js +1 -5
- package/lib/reducers/index.d.ts +9 -3
- package/lib/reducers/ui/finished-slides.d.ts +0 -1
- package/lib/reducers/ui/finished-slides.js +1 -3
- package/lib/reducers/ui/index.d.ts +14 -4
- package/lib/reducers/ui/navigation.d.ts +0 -1
- package/lib/reducers/ui/navigation.js +1 -3
- package/lib/reducers/ui/review-status.d.ts +0 -1
- package/lib/reducers/ui/review-status.js +1 -4
- package/lib/reducers/ui/step-items.d.ts +5 -5
- package/lib/reducers/ui/step-items.js +0 -1
- package/lib/services/fetch-skills.d.ts +2 -8
- package/lib/services/fetch-skills.js +3 -15
- package/lib/services/fetch-slide.d.ts +2 -8
- package/lib/services/fetch-slide.js +18 -25
- package/lib/services/index.d.ts +2 -0
- package/lib/services/index.js +8 -0
- package/lib/services/post-progression.d.ts +2 -8
- package/lib/services/post-progression.js +3 -15
- package/lib/services/{fetch-skills.test.js → test/fetch-skills.test.js} +23 -16
- package/lib/services/{post-progression.test.js → test/post-progression.test.js} +28 -23
- package/lib/{index.test.js → test/index.test.js} +20 -10
- package/lib/test/util/services.mock.d.ts +2 -0
- package/lib/test/util/services.mock.js +68 -0
- package/lib/types/common.d.ts +58 -0
- package/lib/types/common.js +5 -0
- package/lib/types/slides.d.ts +1 -1
- package/lib/types/views/slides.d.ts +1 -1
- package/package.json +5 -4
- package/src/actions/api/fetch-skills.ts +24 -0
- package/src/actions/api/fetch-slide.ts +24 -0
- package/src/actions/api/post-progression.ts +36 -0
- package/src/actions/data/slides.ts +3 -35
- package/src/actions/index.ts +5 -11
- package/src/actions/ui/navigation.ts +0 -5
- package/src/actions/ui/step-items.ts +2 -14
- package/src/configure-store.ts +6 -37
- package/src/fixtures/qcm-slide.ts +2 -2
- package/src/index.tsx +47 -38
- package/src/reducers/data/index.ts +12 -4
- package/src/reducers/data/progression.ts +5 -15
- package/src/reducers/data/skills.ts +5 -10
- package/src/reducers/data/slides.ts +4 -8
- package/src/reducers/data/token.ts +1 -11
- package/src/reducers/index.ts +7 -2
- package/src/reducers/ui/finished-slides.ts +1 -7
- package/src/reducers/ui/index.ts +11 -4
- package/src/reducers/ui/navigation.ts +1 -6
- package/src/reducers/ui/review-status.ts +1 -8
- package/src/reducers/ui/step-items.ts +5 -14
- package/src/services/fetch-skills.ts +4 -29
- package/src/services/fetch-slide.ts +10 -38
- package/src/services/index.ts +10 -0
- package/src/services/post-progression.ts +6 -28
- package/src/services/test/fetch-skills.test.ts +39 -0
- package/src/services/test/post-progression.test.ts +45 -0
- package/src/{index.test.tsx → test/index.test.tsx} +13 -5
- package/src/test/util/services.mock.ts +70 -0
- package/src/types/common.ts +70 -0
- package/src/types/globals.d.ts +1 -5
- package/src/types/slides.ts +1 -1
- package/src/types/views/slides.ts +1 -1
- package/es/actions/data/progression.d.ts +0 -30
- package/es/actions/data/progression.js +0 -12
- package/es/actions/data/skills.d.ts +0 -13
- package/es/actions/data/skills.js +0 -10
- package/es/middlewares/on-receive-progression.d.ts +0 -6
- package/es/middlewares/on-receive-progression.js +0 -22
- package/es/middlewares/on-receive-progression.test.d.ts +0 -1
- package/es/middlewares/on-receive-progression.test.js +0 -43
- package/es/middlewares/on-start-app.d.ts +0 -5
- package/es/middlewares/on-start-app.js +0 -37
- package/es/middlewares/on-start-app.test.d.ts +0 -1
- package/es/middlewares/on-start-app.test.js +0 -53
- package/es/services/fetch-skills.mock.d.ts +0 -3
- package/es/services/fetch-skills.mock.js +0 -17
- package/es/services/fetch-skills.test.js +0 -22
- package/es/services/post-progression.mock.d.ts +0 -5
- package/es/services/post-progression.mock.js +0 -31
- package/es/services/post-progression.test.js +0 -30
- package/es/services/tools/fetch.mocks.d.ts +0 -8
- package/es/services/tools/fetch.mocks.js +0 -13
- package/es/types/skills.d.ts +0 -7
- package/es/types/skills.js +0 -1
- package/lib/actions/data/progression.d.ts +0 -30
- package/lib/actions/data/progression.js +0 -12
- package/lib/actions/data/skills.d.ts +0 -13
- package/lib/actions/data/skills.js +0 -10
- package/lib/middlewares/on-receive-progression.d.ts +0 -6
- package/lib/middlewares/on-receive-progression.js +0 -27
- package/lib/middlewares/on-receive-progression.test.d.ts +0 -1
- package/lib/middlewares/on-receive-progression.test.js +0 -88
- package/lib/middlewares/on-start-app.d.ts +0 -5
- package/lib/middlewares/on-start-app.js +0 -42
- package/lib/middlewares/on-start-app.test.d.ts +0 -1
- package/lib/middlewares/on-start-app.test.js +0 -98
- package/lib/services/fetch-skills.mock.d.ts +0 -3
- package/lib/services/fetch-skills.mock.js +0 -17
- package/lib/services/post-progression.mock.d.ts +0 -5
- package/lib/services/post-progression.mock.js +0 -31
- package/lib/services/tools/fetch.mocks.d.ts +0 -8
- package/lib/services/tools/fetch.mocks.js +0 -35
- package/lib/types/skills.d.ts +0 -7
- package/lib/types/skills.js +0 -1
- package/src/actions/data/progression.ts +0 -50
- package/src/actions/data/skills.ts +0 -24
- package/src/middlewares/on-receive-progression.test.ts +0 -60
- package/src/middlewares/on-receive-progression.ts +0 -42
- package/src/middlewares/on-start-app.test.ts +0 -68
- package/src/middlewares/on-start-app.ts +0 -50
- package/src/services/fetch-skills.mock.ts +0 -21
- package/src/services/fetch-skills.test.ts +0 -32
- package/src/services/post-progression.mock.ts +0 -35
- package/src/services/post-progression.test.ts +0 -41
- package/src/services/tools/fetch.mocks.ts +0 -41
- package/src/types/skills.ts +0 -8
- /package/es/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
- /package/es/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
- /package/es/{index.test.d.ts → test/index.test.d.ts} +0 -0
- /package/lib/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
- /package/lib/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
- /package/lib/{index.test.d.ts → test/index.test.d.ts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {AnyAction} from 'redux';
|
|
2
|
+
import type {ThunkAction, ThunkDispatch} from 'redux-thunk';
|
|
3
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
4
|
+
import type {StoreState} from '../../reducers';
|
|
5
|
+
import {Options, SlideFromAPI} from '../../types/common';
|
|
6
|
+
|
|
7
|
+
export const SLIDE_FETCH_REQUEST = '@@slides/FETCH_REQUEST' as const;
|
|
8
|
+
export const SLIDE_FETCH_SUCCESS = '@@slides/FETCH_SUCCESS' as const;
|
|
9
|
+
export const SLIDE_FETCH_FAILURE = '@@slides/FETCH_FAILURE' as const;
|
|
10
|
+
|
|
11
|
+
export interface ReceivedSlide extends AnyAction {
|
|
12
|
+
type: typeof SLIDE_FETCH_SUCCESS;
|
|
13
|
+
payload: SlideFromAPI;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type FetchSlideAction = ThunkAction<Promise<void>, StoreState, Options, AnyAction>;
|
|
17
|
+
type Dispatch = ThunkDispatch<StoreState, Options, AnyAction>;
|
|
18
|
+
|
|
19
|
+
export const fetchSlide = (slideRef: string, token: string): FetchSlideAction =>
|
|
20
|
+
buildTask({
|
|
21
|
+
types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
|
|
22
|
+
task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) =>
|
|
23
|
+
services.fetchSlide(slideRef, token)
|
|
24
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {AnyAction} from 'redux';
|
|
2
|
+
import type {ThunkAction, ThunkDispatch} from 'redux-thunk';
|
|
3
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
4
|
+
import {Options, ProgressionFromAPI} from '../../types/common';
|
|
5
|
+
import type {StoreState} from '../../reducers';
|
|
6
|
+
import {fetchSlide} from './fetch-slide';
|
|
7
|
+
|
|
8
|
+
export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST' as const;
|
|
9
|
+
export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS' as const;
|
|
10
|
+
export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE' as const;
|
|
11
|
+
|
|
12
|
+
export interface ReceiveProgression extends AnyAction {
|
|
13
|
+
type: typeof POST_PROGRESSION_SUCCESS;
|
|
14
|
+
payload: ProgressionFromAPI;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PostProgressionAction = ThunkAction<
|
|
18
|
+
Promise<ProgressionFromAPI>,
|
|
19
|
+
StoreState,
|
|
20
|
+
Options,
|
|
21
|
+
AnyAction
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
type Dispatch = ThunkDispatch<StoreState, Options, AnyAction>;
|
|
25
|
+
|
|
26
|
+
export const postProgression = (skillRef: string, token: string): PostProgressionAction =>
|
|
27
|
+
buildTask({
|
|
28
|
+
types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
|
|
29
|
+
task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) => {
|
|
30
|
+
return services.postProgression(skillRef, token).then((progression: ProgressionFromAPI) => {
|
|
31
|
+
const {ref} = progression.state.nextContent;
|
|
32
|
+
dispatch(fetchSlide(ref, token));
|
|
33
|
+
return progression;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {UISlide} from '../../types/slides';
|
|
2
|
+
import {ReceivedSlide} from '../api/fetch-slide';
|
|
2
3
|
|
|
3
4
|
// -----------------------------------------------------------------------------
|
|
4
5
|
|
|
5
|
-
export const STORE_FIRST_SLIDE = '@@slide/STORE_FIRST_SLIDE';
|
|
6
6
|
export const UPDATE_SLIDES_ON_VALIDATION = '@@slide/UPDATE_SLIDES_ON_VALIDATION';
|
|
7
7
|
export const UPDATE_SLIDES_ON_NEXT = '@@slide/UPDATE_SLIDES_ON_NEXT';
|
|
8
8
|
export const VALIDATE_SLIDE = '@@slide/VALIDATE';
|
|
9
|
-
export const FETCH_NEXT_CONTENT = '@@slide/FETCH_NEXT_CONTENT';
|
|
10
|
-
export const ERROR_FETCHING_SLIDE = '@@data/slide/ERROR_FETCHING_SLIDE';
|
|
11
9
|
|
|
12
10
|
// -----------------------------------------------------------------------------
|
|
13
11
|
|
|
@@ -23,16 +21,6 @@ export type Slide = UISlide & {
|
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
// TODO: complete or modify typing as needed on Fetch Slide ticket
|
|
26
|
-
export type SlideFromAPI = {
|
|
27
|
-
question: {
|
|
28
|
-
content: {
|
|
29
|
-
choices: Record<string, unknown>[];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
klf: string;
|
|
33
|
-
universalRef: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
24
|
export type ValidationPayload = {
|
|
37
25
|
slideNumber: number;
|
|
38
26
|
newSlideContent: Slide;
|
|
@@ -44,11 +32,6 @@ export type OnNextPayload = Omit<ValidationPayload, 'nextContent'>;
|
|
|
44
32
|
|
|
45
33
|
// -----------------------------------------------------------------------------
|
|
46
34
|
|
|
47
|
-
export type StoreFirstSlide = {
|
|
48
|
-
type: typeof STORE_FIRST_SLIDE;
|
|
49
|
-
payload: SlideFromAPI;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
35
|
export type UpdateSlidesOnValidation = {
|
|
53
36
|
type: typeof UPDATE_SLIDES_ON_VALIDATION;
|
|
54
37
|
payload: ValidationPayload;
|
|
@@ -63,20 +46,10 @@ export type ValidateSlide = {
|
|
|
63
46
|
type: typeof VALIDATE_SLIDE;
|
|
64
47
|
};
|
|
65
48
|
|
|
66
|
-
export type
|
|
67
|
-
type: typeof ERROR_FETCHING_SLIDE;
|
|
68
|
-
payload: Error;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export type SlidesAction = StoreFirstSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
|
|
49
|
+
export type SlidesAction = ReceivedSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
|
|
72
50
|
|
|
73
51
|
// -----------------------------------------------------------------------------
|
|
74
52
|
|
|
75
|
-
export const storeFirstSlide = (slide: SlideFromAPI): StoreFirstSlide => ({
|
|
76
|
-
type: STORE_FIRST_SLIDE,
|
|
77
|
-
payload: slide
|
|
78
|
-
});
|
|
79
|
-
|
|
80
53
|
export const updateSlidesOnValidation = (payload: ValidationPayload): UpdateSlidesOnValidation => ({
|
|
81
54
|
type: UPDATE_SLIDES_ON_VALIDATION,
|
|
82
55
|
payload
|
|
@@ -90,8 +63,3 @@ export const updateSlidesOnNext = (payload: OnNextPayload): UpdateSlidesOnNext =
|
|
|
90
63
|
export const validateSlide = (): ValidateSlide => ({
|
|
91
64
|
type: VALIDATE_SLIDE
|
|
92
65
|
});
|
|
93
|
-
|
|
94
|
-
export const errorFetchingSlide = (error: Error): ErrorFetchingSlide => ({
|
|
95
|
-
type: ERROR_FETCHING_SLIDE,
|
|
96
|
-
payload: error
|
|
97
|
-
});
|
package/src/actions/index.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
StoreFirstSlide,
|
|
3
|
-
updateSlidesOnValidation,
|
|
4
|
-
updateSlidesOnNext,
|
|
5
|
-
validateSlide
|
|
6
|
-
} from './data/slides';
|
|
7
|
-
import {ErrorFetchingSkills, ReceivedSkills} from './data/skills';
|
|
1
|
+
import {updateSlidesOnValidation, updateSlidesOnNext, validateSlide} from './data/slides';
|
|
8
2
|
import {StoreToken} from './data/token';
|
|
9
3
|
|
|
10
4
|
import {updateFinishedSlides} from './ui/finished-slides';
|
|
11
5
|
import {navigateBack, navigateTo, NavigateBack, NavigateTo, StartApp} from './ui/navigation';
|
|
12
6
|
import {updateReviewStatus} from './ui/review-status';
|
|
13
7
|
import {updateStepItemsOnValidation, updateStepItemsOnNext} from './ui/step-items';
|
|
14
|
-
import {
|
|
8
|
+
import {ReceivedSlide} from './api/fetch-slide';
|
|
9
|
+
import {ReceiveProgression} from './api/post-progression';
|
|
10
|
+
import {ReceivedSkills} from './api/fetch-skills';
|
|
15
11
|
|
|
16
12
|
export type Action =
|
|
17
13
|
| NavigateBack
|
|
18
14
|
| NavigateTo
|
|
19
15
|
| ReceivedSkills
|
|
20
|
-
| ErrorFetchingSkills
|
|
21
16
|
| StartApp
|
|
22
|
-
|
|
|
17
|
+
| ReceivedSlide
|
|
23
18
|
| StoreToken
|
|
24
|
-
| ErrorCreatingProgression
|
|
25
19
|
| ReceiveProgression;
|
|
26
20
|
|
|
27
21
|
export type Dispatchers = {
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
// -----------------------------------------------------------------------------
|
|
1
|
+
import {FinishedSlides, IconValue} from '../../types/common';
|
|
4
2
|
|
|
5
3
|
export const UPDATE_STEP_ITEMS_ON_VALIDATION = '@@step-items/UPDATE_STEP_ITEMS_ON_VALIDATION';
|
|
6
4
|
export const UPDATE_STEP_ITEMS_ON_NEXT = '@@step-items/UPDATE_STEP_ITEMS_ON_NEXT';
|
|
7
5
|
|
|
8
|
-
const ICON_VALUES = {
|
|
9
|
-
right: 'right',
|
|
10
|
-
wrong: 'wrong',
|
|
11
|
-
'no-answer': 'no-answer'
|
|
12
|
-
} as const;
|
|
13
|
-
|
|
14
|
-
// -----------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
export type IconValue = keyof typeof ICON_VALUES;
|
|
17
|
-
|
|
18
6
|
type UpdateStepItemsOnValidationClickPayload = {
|
|
19
7
|
stepNumber: number;
|
|
20
8
|
icon: IconValue;
|
|
@@ -22,7 +10,7 @@ type UpdateStepItemsOnValidationClickPayload = {
|
|
|
22
10
|
|
|
23
11
|
type UpdateStepItemsOnNextClickPayload = {
|
|
24
12
|
stepNumber: number;
|
|
25
|
-
finishedSlides:
|
|
13
|
+
finishedSlides: FinishedSlides;
|
|
26
14
|
current: boolean;
|
|
27
15
|
};
|
|
28
16
|
|
package/src/configure-store.ts
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
import {AnyAction, applyMiddleware, compose, createStore, Store} from 'redux';
|
|
2
2
|
import thunk from 'redux-thunk';
|
|
3
|
+
import rootReducer, {StoreState} from './reducers';
|
|
4
|
+
import {getServices} from './services';
|
|
3
5
|
|
|
4
|
-
import
|
|
5
|
-
import onStartApp from './middlewares/on-start-app';
|
|
6
|
-
import onReceiveProgression from './middlewares/on-receive-progression';
|
|
6
|
+
import {AppOptions} from './types/common';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import {SlidesState} from './reducers/data/slides';
|
|
10
|
-
import {TokenState} from './reducers/data/token';
|
|
11
|
-
import {NavigationState} from './reducers/ui/navigation';
|
|
12
|
-
import {ReviewStatusState} from './reducers/ui/review-status';
|
|
13
|
-
import {StepItemsState} from './reducers/ui/step-items';
|
|
14
|
-
import {FinishedSlidesState} from './reducers/ui/finished-slides';
|
|
15
|
-
import {ProgressionState} from './reducers/data/progression';
|
|
16
|
-
|
|
17
|
-
// -----------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
type DataState = {
|
|
20
|
-
isFetching?: boolean;
|
|
21
|
-
progression?: ProgressionState;
|
|
22
|
-
skills: SkillsState;
|
|
23
|
-
slides: SlidesState;
|
|
24
|
-
token?: TokenState;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type StoreState = {
|
|
28
|
-
ui: {
|
|
29
|
-
navigation: NavigationState;
|
|
30
|
-
stepItems: StepItemsState;
|
|
31
|
-
finishedSlides: FinishedSlidesState;
|
|
32
|
-
reviewStatus: ReviewStatusState;
|
|
33
|
-
// progression: UiProgression;
|
|
34
|
-
};
|
|
35
|
-
data: DataState;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// -----------------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
export default function configureStore(): Store<StoreState, AnyAction> {
|
|
8
|
+
export default function configureStore(options: AppOptions): Store<StoreState, AnyAction> {
|
|
41
9
|
const _compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
|
42
10
|
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
|
|
43
11
|
name: 'app-review',
|
|
@@ -46,7 +14,8 @@ export default function configureStore(): Store<StoreState, AnyAction> {
|
|
|
46
14
|
})
|
|
47
15
|
: compose;
|
|
48
16
|
|
|
49
|
-
const
|
|
17
|
+
const thunkMiddleware = thunk.withExtraArgument({services: options.services || getServices()});
|
|
18
|
+
const enhancer = _compose(applyMiddleware(thunkMiddleware));
|
|
50
19
|
const store = createStore(rootReducer, undefined, enhancer);
|
|
51
20
|
|
|
52
21
|
return store;
|
package/src/index.tsx
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import React, {useEffect, useState} from 'react';
|
|
2
|
+
import type {} from 'redux-thunk/extend-redux'; // https://github.com/reduxjs/redux-thunk/issues/333
|
|
2
3
|
import {AnyAction, Store} from 'redux';
|
|
3
4
|
import {connect, Provider} from 'react-redux';
|
|
4
5
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
5
6
|
import {TemplateContext} from '@coorpacademy/components/es/template/app-review/template-context';
|
|
6
7
|
|
|
7
|
-
import configureStore
|
|
8
|
+
import configureStore from './configure-store';
|
|
8
9
|
import {congratsProps, correctionPopinProps} from './fixtures/temp-fixture';
|
|
9
10
|
|
|
10
11
|
import type {AppOptions} from './types/common';
|
|
12
|
+
import type {StoreState} from './reducers';
|
|
11
13
|
import {SkillsProps} from './types/views/skills';
|
|
12
14
|
import type {SlidesViewStaticProps} from './types/views/slides';
|
|
13
15
|
|
|
14
16
|
import {Dispatchers} from './actions';
|
|
15
17
|
import {updateSlidesOnNext, updateSlidesOnValidation, validateSlide} from './actions/data/slides';
|
|
16
|
-
import {navigateTo, navigateBack,
|
|
18
|
+
import {navigateTo, navigateBack, ViewPath} from './actions/ui/navigation';
|
|
19
|
+
import {storeToken} from './actions/data/token';
|
|
17
20
|
import {updateFinishedSlides} from './actions/ui/finished-slides';
|
|
18
21
|
import {updateReviewStatus} from './actions/ui/review-status';
|
|
19
22
|
import {updateStepItemsOnValidation, updateStepItemsOnNext} from './actions/ui/step-items';
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
import {fetchSkills} from './actions/api/fetch-skills';
|
|
24
|
+
import {postProgression} from './actions/api/post-progression';
|
|
25
|
+
import {VIEWS} from './common';
|
|
22
26
|
|
|
23
27
|
type StaticProps = {
|
|
24
28
|
viewName: 'skills' | 'onboarding' | 'slides';
|
|
@@ -26,8 +30,6 @@ type StaticProps = {
|
|
|
26
30
|
skills: SkillsProps | null;
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
// -----------------------------------------------------------------------------
|
|
30
|
-
|
|
31
33
|
const mapDispatchToProps: Dispatchers = {
|
|
32
34
|
navigateTo,
|
|
33
35
|
navigateBack,
|
|
@@ -43,8 +45,6 @@ const mapDispatchToProps: Dispatchers = {
|
|
|
43
45
|
const getCurrentViewName = (storeState: StoreState): ViewPath =>
|
|
44
46
|
storeState.ui.navigation[storeState.ui.navigation.length - 1];
|
|
45
47
|
|
|
46
|
-
// -----------------------------------------------------------------------------
|
|
47
|
-
|
|
48
48
|
const mapStateToSkillsProps = (state: StoreState): SkillsProps | null => {
|
|
49
49
|
if (!state.data.skills) {
|
|
50
50
|
return null;
|
|
@@ -72,8 +72,6 @@ const mapStateToSkillsProps = (state: StoreState): SkillsProps | null => {
|
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
// -----------------------------------------------------------------------------
|
|
76
|
-
|
|
77
75
|
const mapStateToSlidesProps = (state: StoreState): SlidesViewStaticProps | null => {
|
|
78
76
|
if (!state.data.slides) {
|
|
79
77
|
return null;
|
|
@@ -103,38 +101,53 @@ const mapStateToSlidesProps = (state: StoreState): SlidesViewStaticProps | null
|
|
|
103
101
|
};
|
|
104
102
|
};
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Props = StaticProps && Dispatchers
|
|
104
|
+
const mapStateToProps = (state: StoreState): StaticProps => {
|
|
105
|
+
return {
|
|
106
|
+
viewName: getCurrentViewName(state),
|
|
107
|
+
slides: mapStateToSlidesProps(state),
|
|
108
|
+
skills: mapStateToSkillsProps(state)
|
|
109
|
+
};
|
|
110
|
+
};
|
|
115
111
|
|
|
116
112
|
const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
|
|
117
113
|
|
|
118
|
-
// -----------------------------------------------------------------------------
|
|
119
|
-
|
|
120
114
|
const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
|
|
121
115
|
const [store, setStore] = useState<Store<StoreState, AnyAction> | null>(null);
|
|
122
|
-
const [appStarted, setAppStarted] = useState<boolean>(false);
|
|
123
116
|
|
|
124
117
|
useEffect(() => {
|
|
125
|
-
if (store)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
118
|
+
if (store) return;
|
|
119
|
+
|
|
120
|
+
const newStore = configureStore(options);
|
|
121
|
+
setStore(newStore);
|
|
122
|
+
}, [options, store]);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (store === null) return;
|
|
126
|
+
|
|
127
|
+
const {skillRef} = options;
|
|
128
|
+
const initialView: ViewPath = skillRef ? VIEWS.slides : VIEWS.skills;
|
|
129
|
+
store.dispatch(navigateTo(initialView));
|
|
130
|
+
}, [options, store]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (store === null) return;
|
|
134
|
+
|
|
135
|
+
const {token} = options;
|
|
136
|
+
store.dispatch(storeToken(token));
|
|
137
|
+
}, [options, store]);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
if (store === null) return;
|
|
141
|
+
|
|
142
|
+
const {skillRef, token} = options;
|
|
143
|
+
// ThunkAction is not assignable to parameter of type 'AnyAction'
|
|
144
|
+
// ts problem describre here = https://github.com/reduxjs/redux-thunk/issues/333
|
|
145
|
+
skillRef
|
|
146
|
+
? store.dispatch(postProgression(skillRef, token))
|
|
147
|
+
: store.dispatch(fetchSkills(token));
|
|
135
148
|
}, [options, store]);
|
|
136
149
|
|
|
137
|
-
if (!store
|
|
150
|
+
if (!store) return null;
|
|
138
151
|
|
|
139
152
|
const {templateContext: values} = options;
|
|
140
153
|
|
|
@@ -147,15 +160,11 @@ const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
|
|
|
147
160
|
);
|
|
148
161
|
};
|
|
149
162
|
|
|
150
|
-
// -----------------------------------------------------------------------------
|
|
151
|
-
|
|
152
163
|
declare global {
|
|
153
164
|
// eslint-disable-next-line no-shadow
|
|
154
165
|
interface Window {
|
|
155
|
-
|
|
166
|
+
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
|
|
156
167
|
}
|
|
157
168
|
}
|
|
158
169
|
|
|
159
|
-
// -----------------------------------------------------------------------------
|
|
160
|
-
|
|
161
170
|
export default AppReview;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import {combineReducers} from 'redux';
|
|
2
2
|
|
|
3
|
-
import progression from './progression';
|
|
4
|
-
import skills from './skills';
|
|
5
|
-
import slides from './slides';
|
|
6
|
-
import token from './token';
|
|
3
|
+
import progression, {ProgressionState} from './progression';
|
|
4
|
+
import skills, {SkillsState} from './skills';
|
|
5
|
+
import slides, {SlidesState} from './slides';
|
|
6
|
+
import token, {TokenState} from './token';
|
|
7
|
+
|
|
8
|
+
export type DataState = {
|
|
9
|
+
isFetching?: boolean;
|
|
10
|
+
progression?: ProgressionState;
|
|
11
|
+
skills: SkillsState;
|
|
12
|
+
slides: SlidesState;
|
|
13
|
+
token?: TokenState;
|
|
14
|
+
};
|
|
7
15
|
|
|
8
16
|
export default combineReducers({
|
|
9
17
|
progression,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import {getOr} from 'lodash/fp';
|
|
2
|
-
import {ReceiveProgression, RECEIVE_PROGRESSION} from '../../actions/data/progression';
|
|
3
2
|
import {ValidateSlide, VALIDATE_SLIDE} from '../../actions/data/slides';
|
|
3
|
+
import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../actions/api/post-progression';
|
|
4
4
|
|
|
5
|
-
// -----------------------------------------------------------------------------
|
|
6
|
-
|
|
7
|
-
// TODO: transform this into UI data / fix on components' repo when
|
|
8
|
-
// fetch slide is addressed
|
|
9
5
|
export type ProgressionState = {
|
|
10
6
|
_id?: string;
|
|
11
7
|
state: {
|
|
@@ -22,17 +18,11 @@ export type ProgressionState = {
|
|
|
22
18
|
// TO refactor: (slideNumber)
|
|
23
19
|
// virtual field
|
|
24
20
|
slideNumber?: number;
|
|
25
|
-
} | null;
|
|
26
|
-
|
|
27
|
-
// -----------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
export const initialState: ProgressionState = null;
|
|
30
|
-
|
|
31
|
-
// -----------------------------------------------------------------------------
|
|
21
|
+
} | null; // TODO: ça ressemble beaucoup à ProgressionFromAPI et ça devrait l'être
|
|
32
22
|
|
|
33
23
|
const reducer = (
|
|
34
24
|
// eslint-disable-next-line default-param-last
|
|
35
|
-
state: ProgressionState =
|
|
25
|
+
state: ProgressionState = null,
|
|
36
26
|
action: ValidateSlide | ReceiveProgression
|
|
37
27
|
): ProgressionState => {
|
|
38
28
|
switch (action.type) {
|
|
@@ -57,8 +47,8 @@ const reducer = (
|
|
|
57
47
|
}
|
|
58
48
|
};
|
|
59
49
|
}
|
|
60
|
-
case
|
|
61
|
-
const
|
|
50
|
+
case POST_PROGRESSION_SUCCESS: {
|
|
51
|
+
const progression = action.payload;
|
|
62
52
|
return progression;
|
|
63
53
|
}
|
|
64
54
|
default:
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {Skill} from '../../types/common';
|
|
2
|
+
import {ReceivedSkills, SKILLS_FETCH_SUCCESS} from '../../actions/api/fetch-skills';
|
|
3
3
|
|
|
4
|
-
export type SkillsState =
|
|
5
|
-
export const initialState: SkillsState = [];
|
|
6
|
-
|
|
7
|
-
// -----------------------------------------------------------------------------
|
|
4
|
+
export type SkillsState = Skill[];
|
|
8
5
|
|
|
9
6
|
// eslint-disable-next-line default-param-last
|
|
10
|
-
const reducer = (state: SkillsState =
|
|
7
|
+
const reducer = (state: SkillsState = [], action: ReceivedSkills): SkillsState => {
|
|
11
8
|
switch (action.type) {
|
|
12
|
-
case
|
|
9
|
+
case SKILLS_FETCH_SUCCESS:
|
|
13
10
|
return action.payload;
|
|
14
11
|
default:
|
|
15
12
|
return state;
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
15
|
|
|
19
|
-
// -----------------------------------------------------------------------------
|
|
20
|
-
|
|
21
16
|
export default reducer;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import map from 'lodash/fp/map';
|
|
2
2
|
import {
|
|
3
3
|
OnNextPayload,
|
|
4
|
-
Slide,
|
|
5
4
|
SlidesAction,
|
|
6
|
-
STORE_FIRST_SLIDE,
|
|
7
5
|
UPDATE_SLIDES_ON_NEXT,
|
|
8
6
|
UPDATE_SLIDES_ON_VALIDATION,
|
|
9
7
|
ValidationPayload
|
|
10
8
|
} from '../../actions/data/slides';
|
|
11
|
-
import {
|
|
9
|
+
import {UISlide} from '../../types/slides';
|
|
12
10
|
import {HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK} from '../../common';
|
|
13
11
|
import {slide as qcmSlide} from '../../fixtures/qcm-slide';
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import {SLIDE_FETCH_SUCCESS} from '../../actions/api/fetch-slide';
|
|
13
|
+
import {Slide} from '../../types/common';
|
|
16
14
|
|
|
17
15
|
export type SlidesState = {
|
|
18
16
|
slideNumbers: number[];
|
|
19
17
|
[key: number]: Slide;
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
// -----------------------------------------------------------------------------
|
|
23
|
-
|
|
24
20
|
const getInitialState = (): SlidesState => {
|
|
25
21
|
const state: SlidesState = {
|
|
26
22
|
slideNumbers
|
|
@@ -121,7 +117,7 @@ const stateUpdateOnNext = (state: SlidesState, payload: OnNextPayload): SlidesSt
|
|
|
121
117
|
// eslint-disable-next-line default-param-last
|
|
122
118
|
const reducer = (state: SlidesState = initialState, action: SlidesAction): SlidesState => {
|
|
123
119
|
switch (action.type) {
|
|
124
|
-
case
|
|
120
|
+
case SLIDE_FETCH_SUCCESS: {
|
|
125
121
|
// TODO: An intermediate slide transform is needed here (or in fetchSlide)
|
|
126
122
|
// const apiSlide = action.payload;
|
|
127
123
|
// apiSlide adapt to uiSlide
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import {StoreToken, STORE_TOKEN} from '../../actions/data/token';
|
|
2
2
|
|
|
3
|
-
// -----------------------------------------------------------------------------
|
|
4
|
-
|
|
5
3
|
export type TokenState = string | null;
|
|
6
4
|
|
|
7
|
-
// -----------------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
export const initialState: TokenState = null;
|
|
10
|
-
|
|
11
|
-
// -----------------------------------------------------------------------------
|
|
12
|
-
|
|
13
5
|
// eslint-disable-next-line default-param-last
|
|
14
|
-
const reducer = (state: TokenState =
|
|
6
|
+
const reducer = (state: TokenState = null, action: StoreToken): TokenState => {
|
|
15
7
|
switch (action.type) {
|
|
16
8
|
case STORE_TOKEN:
|
|
17
9
|
return action.payload;
|
|
@@ -20,6 +12,4 @@ const reducer = (state: TokenState = initialState, action: StoreToken): TokenSta
|
|
|
20
12
|
}
|
|
21
13
|
};
|
|
22
14
|
|
|
23
|
-
// -----------------------------------------------------------------------------
|
|
24
|
-
|
|
25
15
|
export default reducer;
|
package/src/reducers/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {combineReducers} from 'redux';
|
|
2
2
|
|
|
3
|
-
import data from './data';
|
|
4
|
-
import ui from './ui';
|
|
3
|
+
import data, {DataState} from './data';
|
|
4
|
+
import ui, {UIState} from './ui';
|
|
5
|
+
|
|
6
|
+
export type StoreState = {
|
|
7
|
+
ui: UIState;
|
|
8
|
+
data: DataState;
|
|
9
|
+
};
|
|
5
10
|
|
|
6
11
|
export default combineReducers({
|
|
7
12
|
data,
|
|
@@ -2,21 +2,15 @@ import forEach from 'lodash/fp/forEach';
|
|
|
2
2
|
import {UpdateFinishedSlides, UPDATE_FINISHED_SLIDES} from '../../actions/ui/finished-slides';
|
|
3
3
|
import {slideNumbers} from '../../common';
|
|
4
4
|
|
|
5
|
-
// -----------------------------------------------------------------------------
|
|
6
|
-
// Stores only successful slides
|
|
7
5
|
export type FinishedSlidesState = {
|
|
8
6
|
slideNumbers: number[];
|
|
9
7
|
[key: number]: true;
|
|
10
8
|
};
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const initialState: FinishedSlidesState = {
|
|
10
|
+
const initialState: FinishedSlidesState = {
|
|
15
11
|
slideNumbers
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
// -----------------------------------------------------------------------------
|
|
19
|
-
|
|
20
14
|
const _forEach: <T>(
|
|
21
15
|
iteratee: (value: T[keyof T], index: number) => void,
|
|
22
16
|
collection: T
|
package/src/reducers/ui/index.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import {combineReducers} from 'redux';
|
|
2
2
|
|
|
3
|
-
import finishedSlides from './finished-slides';
|
|
4
|
-
import navigation from './navigation';
|
|
5
|
-
import reviewStatus from './review-status';
|
|
6
|
-
import stepItems from './step-items';
|
|
3
|
+
import finishedSlides, {FinishedSlidesState} from './finished-slides';
|
|
4
|
+
import navigation, {NavigationState} from './navigation';
|
|
5
|
+
import reviewStatus, {ReviewStatusState} from './review-status';
|
|
6
|
+
import stepItems, {StepItemsState} from './step-items';
|
|
7
|
+
|
|
8
|
+
export type UIState = {
|
|
9
|
+
navigation: NavigationState;
|
|
10
|
+
stepItems: StepItemsState;
|
|
11
|
+
finishedSlides: FinishedSlidesState;
|
|
12
|
+
reviewStatus: ReviewStatusState;
|
|
13
|
+
};
|
|
7
14
|
|
|
8
15
|
export default combineReducers({
|
|
9
16
|
finishedSlides,
|