@coorpacademy/app-review 0.1.7 → 0.1.8
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 +10 -0
- package/es/actions/api/fetch-skills.js +8 -0
- package/es/actions/api/fetch-slide.d.ts +10 -0
- package/es/actions/api/fetch-slide.js +8 -0
- package/es/actions/api/post-progression.d.ts +10 -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.js +38 -19
- 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 +10 -0
- package/lib/actions/api/fetch-skills.js +13 -0
- package/lib/actions/api/fetch-slide.d.ts +10 -0
- package/lib/actions/api/fetch-slide.js +13 -0
- package/lib/actions/api/post-progression.d.ts +10 -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.js +38 -63
- 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 -3
- package/src/actions/api/fetch-skills.ts +20 -0
- package/src/actions/api/fetch-slide.ts +20 -0
- package/src/actions/api/post-progression.ts +26 -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 +43 -19
- 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 -0
- 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
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
|
@@ -4,19 +4,24 @@ import {connect, Provider} from 'react-redux';
|
|
|
4
4
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
5
5
|
import {TemplateContext} from '@coorpacademy/components/es/template/app-review/template-context';
|
|
6
6
|
|
|
7
|
-
import configureStore
|
|
7
|
+
import configureStore from './configure-store';
|
|
8
8
|
import {congratsProps, correctionPopinProps} from './fixtures/temp-fixture';
|
|
9
9
|
|
|
10
10
|
import type {AppOptions} from './types/common';
|
|
11
|
+
import type {StoreState} from './reducers';
|
|
11
12
|
import {SkillsProps} from './types/views/skills';
|
|
12
13
|
import type {SlidesViewStaticProps} from './types/views/slides';
|
|
13
14
|
|
|
14
15
|
import {Dispatchers} from './actions';
|
|
15
16
|
import {updateSlidesOnNext, updateSlidesOnValidation, validateSlide} from './actions/data/slides';
|
|
16
|
-
import {navigateTo, navigateBack,
|
|
17
|
+
import {navigateTo, navigateBack, ViewPath} from './actions/ui/navigation';
|
|
18
|
+
import {storeToken} from './actions/data/token';
|
|
17
19
|
import {updateFinishedSlides} from './actions/ui/finished-slides';
|
|
18
20
|
import {updateReviewStatus} from './actions/ui/review-status';
|
|
19
21
|
import {updateStepItemsOnValidation, updateStepItemsOnNext} from './actions/ui/step-items';
|
|
22
|
+
import {fetchSkills} from './actions/api/fetch-skills';
|
|
23
|
+
import {postProgression} from './actions/api/post-progression';
|
|
24
|
+
import {VIEWS} from './common';
|
|
20
25
|
|
|
21
26
|
// -----------------------------------------------------------------------------
|
|
22
27
|
|
|
@@ -105,11 +110,13 @@ const mapStateToSlidesProps = (state: StoreState): SlidesViewStaticProps | null
|
|
|
105
110
|
|
|
106
111
|
// -----------------------------------------------------------------------------
|
|
107
112
|
|
|
108
|
-
const mapStateToProps = (state: StoreState): StaticProps =>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
const mapStateToProps = (state: StoreState): StaticProps => {
|
|
114
|
+
return {
|
|
115
|
+
viewName: getCurrentViewName(state),
|
|
116
|
+
slides: mapStateToSlidesProps(state),
|
|
117
|
+
skills: mapStateToSkillsProps(state)
|
|
118
|
+
};
|
|
119
|
+
};
|
|
113
120
|
|
|
114
121
|
// Props = StaticProps && Dispatchers
|
|
115
122
|
|
|
@@ -119,22 +126,39 @@ const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewTemplate);
|
|
|
119
126
|
|
|
120
127
|
const AppReview = ({options}: {options: AppOptions}): JSX.Element | null => {
|
|
121
128
|
const [store, setStore] = useState<Store<StoreState, AnyAction> | null>(null);
|
|
122
|
-
const [appStarted, setAppStarted] = useState<boolean>(false);
|
|
123
129
|
|
|
124
130
|
useEffect(() => {
|
|
125
|
-
if (store)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
131
|
+
if (store) return;
|
|
132
|
+
|
|
133
|
+
const newStore = configureStore(options);
|
|
134
|
+
setStore(newStore);
|
|
135
|
+
}, [options, store]);
|
|
136
|
+
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (store === null) return;
|
|
139
|
+
|
|
140
|
+
const {skillRef} = options;
|
|
141
|
+
const initialView: ViewPath = skillRef ? VIEWS.slides : VIEWS.skills;
|
|
142
|
+
store.dispatch(navigateTo(initialView));
|
|
143
|
+
}, [options, store]);
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (store === null) return;
|
|
147
|
+
|
|
148
|
+
const {token} = options;
|
|
149
|
+
store.dispatch(storeToken(token));
|
|
150
|
+
}, [options, store]);
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (store === null) return;
|
|
154
|
+
|
|
155
|
+
const {skillRef, token} = options;
|
|
156
|
+
skillRef
|
|
157
|
+
? store.dispatch(postProgression(skillRef, token))
|
|
158
|
+
: store.dispatch(fetchSkills(token));
|
|
135
159
|
}, [options, store]);
|
|
136
160
|
|
|
137
|
-
if (!store
|
|
161
|
+
if (!store) return null;
|
|
138
162
|
|
|
139
163
|
const {templateContext: values} = options;
|
|
140
164
|
|
|
@@ -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,
|
|
@@ -5,16 +5,11 @@ import {
|
|
|
5
5
|
NAVIGATE_TO
|
|
6
6
|
} from '../../actions/ui/navigation';
|
|
7
7
|
|
|
8
|
-
// -----------------------------------------------------------------------------
|
|
9
|
-
|
|
10
8
|
export type NavigationState = Array<'skills' | 'onboarding' | 'slides'>;
|
|
11
|
-
export const initialState: NavigationState = [];
|
|
12
|
-
|
|
13
|
-
// -----------------------------------------------------------------------------
|
|
14
9
|
|
|
15
10
|
const reducer = (
|
|
16
11
|
// eslint-disable-next-line default-param-last
|
|
17
|
-
state: NavigationState =
|
|
12
|
+
state: NavigationState = [],
|
|
18
13
|
action: NavigateTo | NavigateBack
|
|
19
14
|
): NavigationState => {
|
|
20
15
|
switch (action.type) {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import {UpdateReviewStatus, UPDATE_REVIEW_STATUS} from '../../actions/ui/review-status';
|
|
2
2
|
|
|
3
|
-
// -----------------------------------------------------------------------------
|
|
4
|
-
|
|
5
3
|
export type ReviewStatusState = 'finished' | 'ongoing';
|
|
6
|
-
export const initialState: ReviewStatusState = 'ongoing';
|
|
7
|
-
|
|
8
|
-
// -----------------------------------------------------------------------------
|
|
9
4
|
|
|
10
5
|
const reducer = (
|
|
11
6
|
// eslint-disable-next-line default-param-last
|
|
12
|
-
state: ReviewStatusState =
|
|
7
|
+
state: ReviewStatusState = 'ongoing',
|
|
13
8
|
action: UpdateReviewStatus
|
|
14
9
|
): ReviewStatusState => {
|
|
15
10
|
switch (action.type) {
|
|
@@ -21,6 +16,4 @@ const reducer = (
|
|
|
21
16
|
}
|
|
22
17
|
};
|
|
23
18
|
|
|
24
|
-
// -----------------------------------------------------------------------------
|
|
25
|
-
|
|
26
19
|
export default reducer;
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
import get from 'lodash/fp/get';
|
|
2
2
|
import has from 'lodash/fp/has';
|
|
3
3
|
import map from 'lodash/fp/map';
|
|
4
|
+
import {IconValue, FinishedSlides} from '../../types/common';
|
|
4
5
|
import {
|
|
5
|
-
IconValue,
|
|
6
6
|
StepItemsAction,
|
|
7
7
|
UPDATE_STEP_ITEMS_ON_NEXT,
|
|
8
8
|
UPDATE_STEP_ITEMS_ON_VALIDATION
|
|
9
9
|
} from '../../actions/ui/step-items';
|
|
10
10
|
import {HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK} from '../../common';
|
|
11
|
-
import {FinishedSlidesState} from './finished-slides';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type StepItem = {
|
|
12
|
+
export type StepItem = {
|
|
16
13
|
current: boolean;
|
|
17
14
|
icon: IconValue;
|
|
18
15
|
value: string;
|
|
19
16
|
};
|
|
20
17
|
|
|
21
|
-
export type
|
|
18
|
+
export type StepItemsState = {
|
|
22
19
|
slideNumbers: number[];
|
|
23
20
|
[key: number]: StepItem;
|
|
24
21
|
};
|
|
25
22
|
|
|
26
|
-
// -----------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
export type StepItemsState = StepItems;
|
|
29
|
-
|
|
30
|
-
// -----------------------------------------------------------------------------
|
|
31
|
-
|
|
32
23
|
const getInitialState = (): StepItemsState => {
|
|
33
|
-
const state:
|
|
24
|
+
const state: StepItemsState = {
|
|
34
25
|
slideNumbers
|
|
35
26
|
};
|
|
36
27
|
|
|
@@ -55,7 +46,7 @@ const getNextIndex = (currentIndex: number): number =>
|
|
|
55
46
|
// they have to be skipped)
|
|
56
47
|
const calculateNextStepIndex = (
|
|
57
48
|
currentStepNumber: number,
|
|
58
|
-
finishedSlides:
|
|
49
|
+
finishedSlides: FinishedSlides,
|
|
59
50
|
lastVisitedIndex = -1
|
|
60
51
|
): number => {
|
|
61
52
|
// only one slide remaining, the step should stay on the same number
|
|
@@ -1,39 +1,14 @@
|
|
|
1
1
|
import crossFetch from 'cross-fetch';
|
|
2
2
|
import decode from 'jwt-decode';
|
|
3
3
|
|
|
4
|
-
import {JWT} from '../types/common';
|
|
5
|
-
import {Skills} from '../types/skills';
|
|
4
|
+
import {JWT, Skill} from '../types/common';
|
|
6
5
|
import {toJSON} from './tools/fetch-responses';
|
|
7
|
-
import mockFetchSkills from './fetch-skills.mock';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type FetchSkills = (token: string) => Promise<Skills>;
|
|
12
|
-
type CreateFetchSkills = (fetch: typeof crossFetch) => FetchSkills;
|
|
13
|
-
type CreateDefaultFetchSkills = () => FetchSkills;
|
|
14
|
-
|
|
15
|
-
// -----------------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
const fetchSkills: CreateFetchSkills = fetch => async token => {
|
|
7
|
+
export const fetchSkills = async (token: string): Promise<Skill[]> => {
|
|
18
8
|
const {user: userId, host}: JWT = decode(token);
|
|
19
|
-
const response = await
|
|
9
|
+
const response = await crossFetch(`${host}/api/v2/skills/review/user/${userId}`, {
|
|
20
10
|
headers: {authorization: token}
|
|
21
11
|
});
|
|
22
12
|
|
|
23
|
-
return toJSON<
|
|
13
|
+
return toJSON<Skill[]>(response);
|
|
24
14
|
};
|
|
25
|
-
|
|
26
|
-
// -----------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
const createFetchSkills: CreateDefaultFetchSkills = () => {
|
|
29
|
-
if (process.env.SERVICES !== 'mocks') {
|
|
30
|
-
return fetchSkills(crossFetch);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return fetchSkills(mockFetchSkills);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// -----------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
export {fetchSkills};
|
|
39
|
-
export default createFetchSkills();
|
|
@@ -1,43 +1,15 @@
|
|
|
1
1
|
import crossFetch from 'cross-fetch';
|
|
2
|
-
|
|
2
|
+
import decode from 'jwt-decode';
|
|
3
3
|
|
|
4
|
-
import {SlideFromAPI} from '../
|
|
5
|
-
|
|
6
|
-
// import {toJSON} from './tools/fetch-responses';
|
|
7
|
-
import {okJSONResponse} from './tools/fetch.mocks';
|
|
4
|
+
import {JWT, SlideFromAPI} from '../types/common';
|
|
5
|
+
import {toJSON} from './tools/fetch-responses';
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
export const fetchSlide = async (slideRef: string, token: string): Promise<SlideFromAPI | void> => {
|
|
8
|
+
const {host}: JWT = decode(token);
|
|
9
|
+
const response = await crossFetch(`${host}/api/v2/slide/${slideRef}`, {
|
|
10
|
+
headers: {authorization: token}
|
|
11
|
+
});
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type DefaultFetchSlideBuilder = () => FetchSlide;
|
|
14
|
-
|
|
15
|
-
// -----------------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unicorn/consistent-function-scoping, require-await
|
|
18
|
-
const fetchSlide: FetchSlideBuilder = fetch => async (slideRef: string, token: string) => {
|
|
19
|
-
// const {host}: JWT = decode(token);
|
|
20
|
-
// const response = await fetch(`${host}/api/v2/slide/${slideRef}`, {
|
|
21
|
-
// headers: {authorization: token}
|
|
22
|
-
// });
|
|
23
|
-
|
|
24
|
-
// const slide = (await toJSON(response)) as SlideFromAPI;
|
|
25
|
-
// return slide;
|
|
26
|
-
return {} as SlideFromAPI;
|
|
13
|
+
const slide = (await toJSON(response)) as SlideFromAPI;
|
|
14
|
+
return slide;
|
|
27
15
|
};
|
|
28
|
-
|
|
29
|
-
// -----------------------------------------------------------------------------
|
|
30
|
-
|
|
31
|
-
const createFetchSlide: DefaultFetchSlideBuilder = () => {
|
|
32
|
-
if (process.env.SERVICES !== 'mocks') {
|
|
33
|
-
return fetchSlide(crossFetch);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// TODO: use an appropriate mock
|
|
37
|
-
return fetchSlide(okJSONResponse({}));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// -----------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
export {fetchSlide};
|
|
43
|
-
export default createFetchSlide();
|