@coorpacademy/app-review 0.18.2-test-latest.2 → 0.19.0

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.
@@ -0,0 +1,22 @@
1
+ import type { Dispatch } from 'redux';
2
+ import type { ThunkOptions, VideoPropsForPlayer } from '../../types/common';
3
+ import type { StoreState } from '../../reducers';
4
+ export declare const SET_VIDEO_PROPS: "@@slide/SET_VIDEO_PROPS";
5
+ export declare const SHOW_VIDEO: "@@slide/SHOW_VIDEO";
6
+ export declare type VideoPropsPayload = {
7
+ slideId: string;
8
+ props: VideoPropsForPlayer;
9
+ };
10
+ export declare type SetVideoPropsAction = {
11
+ type: typeof SET_VIDEO_PROPS;
12
+ payload: VideoPropsPayload;
13
+ };
14
+ export declare const setVideoProps: (payload: VideoPropsPayload) => SetVideoPropsAction;
15
+ export declare type ShowVideoAction = {
16
+ type: typeof SHOW_VIDEO;
17
+ payload: {
18
+ slideId: string;
19
+ };
20
+ };
21
+ export declare const showVideo: (slideId: string) => ShowVideoAction;
22
+ export declare const fetchPropsVideo: (slideId: string) => (dispatch: Dispatch, getState: () => StoreState, { appendVideoOptions }: ThunkOptions) => Promise<void>;
@@ -0,0 +1,34 @@
1
+ import get from 'lodash/fp/get';
2
+ export const SET_VIDEO_PROPS = '@@slide/SET_VIDEO_PROPS';
3
+ export const SHOW_VIDEO = '@@slide/SHOW_VIDEO';
4
+ export const setVideoProps = (payload) => ({
5
+ type: SET_VIDEO_PROPS,
6
+ payload
7
+ });
8
+ export const showVideo = (slideId) => ({
9
+ type: SHOW_VIDEO,
10
+ payload: { slideId }
11
+ });
12
+ export const fetchPropsVideo = (slideId) => async (dispatch, getState, { appendVideoOptions }) => {
13
+ const state = getState();
14
+ const slideFromAPI = get(['data', 'slides', slideId], state);
15
+ if (!slideFromAPI) {
16
+ return;
17
+ }
18
+ const slideMedia = get(['question', 'medias', '0'], slideFromAPI);
19
+ if (slideMedia && slideMedia.type === 'video') {
20
+ const videoProps = get(['data', 'videos', slideId], state);
21
+ if (videoProps) {
22
+ dispatch(showVideo(slideId));
23
+ return;
24
+ }
25
+ const props = await appendVideoOptions(slideMedia);
26
+ props.src[0].loading = false; // set to false to not show it until the next slide is unstack
27
+ props.src[0].type = 'video';
28
+ dispatch(setVideoProps({
29
+ slideId,
30
+ props
31
+ }));
32
+ }
33
+ return;
34
+ };
@@ -12,5 +12,5 @@ export declare type NextSlideAction = {
12
12
  type: typeof NEXT_SLIDE;
13
13
  payload: NextSlidePayload;
14
14
  };
15
- export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => Promise<NextSlideAction>;
15
+ export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => Promise<void>;
16
16
  export {};
@@ -2,6 +2,7 @@ import filter from 'lodash/fp/filter';
2
2
  import get from 'lodash/fp/get';
3
3
  import { fetchEndRank } from '../api/fetch-rank';
4
4
  import { fetchSlidesToReviewBySkillRef } from '../api/fetch-slides-to-review-by-skill-ref';
5
+ import { fetchPropsVideo } from '../api/fetch-video-props';
5
6
  export const NEXT_SLIDE = '@@slide/NEXT_SLIDE';
6
7
  export const nextSlide = async (dispatch, getState) => {
7
8
  const state = getState();
@@ -23,6 +24,10 @@ export const nextSlide = async (dispatch, getState) => {
23
24
  if (nextSlideRef === 'successExitNode') {
24
25
  await dispatch(fetchEndRank);
25
26
  await dispatch(fetchSlidesToReviewBySkillRef);
27
+ dispatch(action);
28
+ }
29
+ else {
30
+ dispatch(action);
31
+ await dispatch(fetchPropsVideo(payload.nextSlideRef));
26
32
  }
27
- return dispatch(action);
28
33
  };
@@ -1,3 +1,4 @@
1
+ import type { Dispatch } from 'redux';
1
2
  import type { SlideFromAPI } from '@coorpacademy/review-services';
2
3
  import { AnswerUI } from '../../types/slides';
3
4
  declare type SlideUIAnimations = 'unstack' | 'restack';
@@ -16,5 +17,5 @@ export declare type SetCurrentSlideAction = {
16
17
  type: typeof SET_CURRENT_SLIDE;
17
18
  payload: SlideFromAPI;
18
19
  };
19
- export declare const setCurrentSlide: (payload: SlideFromAPI) => SetCurrentSlideAction;
20
+ export declare const setCurrentSlide: (slideFromAPI: SlideFromAPI) => (dispatch: Dispatch) => Promise<void>;
20
21
  export {};
@@ -1,5 +1,10 @@
1
+ import { fetchPropsVideo } from '../api/fetch-video-props';
1
2
  export const SET_CURRENT_SLIDE = '@@slide/SET_CURRENT_SLIDE';
2
- export const setCurrentSlide = (payload) => ({
3
- type: SET_CURRENT_SLIDE,
4
- payload
5
- });
3
+ export const setCurrentSlide = (slideFromAPI) => async (dispatch) => {
4
+ dispatch({
5
+ type: SET_CURRENT_SLIDE,
6
+ payload: slideFromAPI
7
+ });
8
+ await dispatch(fetchPropsVideo(slideFromAPI._id));
9
+ return;
10
+ };
@@ -4,6 +4,7 @@ import { SlidesState } from './slides';
4
4
  import { TokenState } from './token';
5
5
  import { RankState } from './rank';
6
6
  import { CurrentSkillState } from './current-skill';
7
+ import { VideoPropsState } from './videos';
7
8
  export declare type DataState = {
8
9
  corrections: CorrectionsState;
9
10
  progression: ProgressionState;
@@ -11,6 +12,7 @@ export declare type DataState = {
11
12
  token: TokenState;
12
13
  rank: RankState;
13
14
  currentSkill: CurrentSkillState;
15
+ videos: VideoPropsState;
14
16
  };
15
17
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
16
18
  corrections: CorrectionsState;
@@ -19,5 +21,6 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
19
21
  token: string;
20
22
  rank: RankState;
21
23
  currentSkill: CurrentSkillState;
22
- }>, import("../../actions/api/fetch-skill").ReceivedSkill | import("../../actions/api/post-progression").FetchProgression | import("../../actions/api/post-progression").ReceivedProgression | import("./corrections").CorrectionsAction | import("../../actions/api/fetch-rank").RankAction | import("../../actions/api/post-answer").PostAnswerSuccessAction | import("./slides").SlidesAction | import("../../actions/data/token").StoreToken>;
24
+ videos: VideoPropsState;
25
+ }>, import("../../actions/api/fetch-video-props").SetVideoPropsAction | import("../../actions/api/fetch-video-props").ShowVideoAction | import("../../actions/ui/slides").SetCurrentSlideAction | import("../../actions/api/fetch-skill").ReceivedSkill | import("../../actions/api/post-progression").FetchProgression | import("../../actions/api/post-progression").ReceivedProgression | import("./corrections").CorrectionsAction | import("../../actions/api/fetch-rank").RankAction | import("../../actions/api/post-answer").PostAnswerSuccessAction | import("./slides").SlidesAction | import("../../actions/data/token").StoreToken | import("../../actions/ui/next-slide").NextSlideAction>;
23
26
  export default _default;
@@ -5,11 +5,13 @@ import slides from './slides';
5
5
  import token from './token';
6
6
  import rank from './rank';
7
7
  import currentSkill from './current-skill';
8
+ import videos from './videos';
8
9
  export default combineReducers({
9
10
  corrections,
10
11
  progression,
11
12
  slides,
12
13
  token,
13
14
  rank,
14
- currentSkill
15
+ currentSkill,
16
+ videos
15
17
  });
@@ -0,0 +1,8 @@
1
+ import { VideoPropsForPlayer } from '../../types/common';
2
+ import { SetVideoPropsAction, ShowVideoAction } from '../../actions/api/fetch-video-props';
3
+ import { NextSlideAction } from '../../actions/ui/next-slide';
4
+ import { SetCurrentSlideAction } from '../../actions/ui/slides';
5
+ export declare type VideoPropsState = Record<string, VideoPropsForPlayer>;
6
+ export declare const initialState: VideoPropsState;
7
+ declare const reducer: (state: VideoPropsState | undefined, action: SetVideoPropsAction | NextSlideAction | SetCurrentSlideAction | ShowVideoAction) => VideoPropsState;
8
+ export default reducer;
@@ -0,0 +1,33 @@
1
+ import { get, set } from 'lodash/fp';
2
+ import { SET_VIDEO_PROPS, SHOW_VIDEO } from '../../actions/api/fetch-video-props';
3
+ import { NEXT_SLIDE } from '../../actions/ui/next-slide';
4
+ export const initialState = {};
5
+ const reducer = (
6
+ // eslint-disable-next-line default-param-last
7
+ state = initialState, action) => {
8
+ switch (action.type) {
9
+ case SET_VIDEO_PROPS: {
10
+ const { slideId, props } = action.payload;
11
+ return set(slideId, props, state);
12
+ }
13
+ case NEXT_SLIDE: {
14
+ const { currentSlideRef } = action.payload;
15
+ const isMediaVideo = get(currentSlideRef, state);
16
+ if (isMediaVideo) {
17
+ return set([currentSlideRef, 'src', '0', 'loading'], true, state);
18
+ }
19
+ return state;
20
+ }
21
+ case SHOW_VIDEO: {
22
+ const { slideId } = action.payload;
23
+ const isMediaVideo = get(slideId, state);
24
+ if (isMediaVideo) {
25
+ return set([slideId, 'src', '0', 'loading'], false, state);
26
+ }
27
+ return state;
28
+ }
29
+ default:
30
+ return state;
31
+ }
32
+ };
33
+ export default reducer;
@@ -12,6 +12,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
12
  token: string;
13
13
  rank: import("./data/rank").RankState;
14
14
  currentSkill: import("./data/current-skill").CurrentSkillState;
15
+ videos: import("./data/videos").VideoPropsState;
15
16
  }>;
16
17
  ui: import("redux").CombinedState<{
17
18
  currentSlideRef: string;
@@ -23,7 +24,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
23
24
  showButtonRevising: boolean;
24
25
  showCongrats: boolean;
25
26
  }>;
26
- }>, import("../actions/ui/slides").SetCurrentSlideAction | import("../actions/api/fetch-skill").ReceivedSkill | import("../actions/api/post-progression").FetchProgression | import("../actions/api/post-progression").ReceivedProgression | import("./data/corrections").CorrectionsAction | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/api/fetch-slides-to-review-by-skill-ref").ReceivedSlidesToReviewBySkillRef | import("../actions/ui/next-slide").NextSlideAction | import("../actions/ui/navigation").NavigateToAction | import("../actions/ui/navigation").NavigateBackAction | import("../actions/ui/answers").EditAnswerAction | {
27
+ }>, import("../actions/api/fetch-video-props").SetVideoPropsAction | import("../actions/api/fetch-video-props").ShowVideoAction | import("../actions/ui/slides").SetCurrentSlideAction | import("../actions/api/fetch-skill").ReceivedSkill | import("../actions/api/post-progression").FetchProgression | import("../actions/api/post-progression").ReceivedProgression | import("./data/corrections").CorrectionsAction | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/api/fetch-slides-to-review-by-skill-ref").ReceivedSlidesToReviewBySkillRef | import("../actions/ui/next-slide").NextSlideAction | import("../actions/ui/navigation").NavigateToAction | import("../actions/ui/navigation").NavigateBackAction | import("../actions/ui/answers").EditAnswerAction | {
27
28
  type: "@@ui/OPEN_POPIN";
28
29
  } | {
29
30
  type: "@@ui/CLOSE_POPIN";
@@ -1,4 +1,4 @@
1
- import type { Services, VideoMedia, VideoPropsForPlayer } from '@coorpacademy/review-services';
1
+ import type { Services, VideoMedia } from '@coorpacademy/review-services';
2
2
  export declare type WithRequired<T, K extends keyof T> = T & {
3
3
  [P in K]-?: T[P];
4
4
  };
@@ -11,6 +11,23 @@ export declare type Skin = {
11
11
  primary: string;
12
12
  };
13
13
  };
14
+ declare type VideoSrcPropsForPlayer = {
15
+ mimeType: string;
16
+ videoId: string;
17
+ jwpOptions: unknown;
18
+ loading?: boolean;
19
+ type: string;
20
+ };
21
+ export declare type VideoPropsForPlayer = {
22
+ type: string;
23
+ src: VideoSrcPropsForPlayer[];
24
+ };
25
+ export declare type MediaPropsForPlayer = {
26
+ type: 'img' | 'audio';
27
+ url: string;
28
+ _id: string;
29
+ mimeType: string;
30
+ };
14
31
  export declare type ConnectedOptions = {
15
32
  translate: Translate;
16
33
  onQuitClick: () => void;
@@ -32,3 +49,4 @@ export declare type ThunkOptions = {
32
49
  export declare type Options = {
33
50
  services: Services;
34
51
  };
52
+ export {};
@@ -62,6 +62,28 @@ const getCurrentSlideRef = (state) => {
62
62
  const isLastSlideAnswered = (slidesRef, slideRef) => {
63
63
  return last(slidesRef) === slideRef;
64
64
  };
65
+ const getSlideMedia = (state, slideFromAPI) => {
66
+ const media = get(['question', 'medias', '0'], slideFromAPI);
67
+ if (!media)
68
+ return;
69
+ const { type } = media;
70
+ const resource = get(['src', '0'], media);
71
+ switch (type) {
72
+ case 'img':
73
+ case 'audio': {
74
+ const mediaProps = {
75
+ ...resource,
76
+ type,
77
+ url: get('url', resource)
78
+ };
79
+ return mediaProps;
80
+ }
81
+ case 'video': {
82
+ const videoProps = get(['data', 'videos', slideFromAPI._id, 'src', '0'], state);
83
+ return videoProps;
84
+ }
85
+ }
86
+ };
65
87
  const buildStackSlides = (state, dispatch, options) => {
66
88
  const { translate } = options;
67
89
  const currentSlideRef = getCurrentSlideRef(state);
@@ -84,7 +106,8 @@ const buildStackSlides = (state, dispatch, options) => {
84
106
  if (!slideFromAPI)
85
107
  return set(index, { ...uiSlide, position }, acc);
86
108
  const answers = getOr([], ['ui', 'answers', slideRef], state);
87
- const { questionText, answerUI } = mapApiSlideToUi(dispatch, translate)(slideFromAPI, answers);
109
+ const media = getSlideMedia(state, slideFromAPI);
110
+ const { questionText, answerUI } = mapApiSlideToUi(dispatch, translate)(slideFromAPI, answers, media);
88
111
  const { title: parentContentTitle, type: parentContentType } = slideFromAPI.parentContentTitle;
89
112
  const isCurrentSlideRef = currentSlideRef === slideRef;
90
113
  const slideUI = get(['ui', 'slide', slideRef], state);
@@ -1,9 +1,9 @@
1
1
  import { Dispatch } from 'redux';
2
2
  import type { Question, SlideFromAPI } from '@coorpacademy/review-services';
3
3
  import { AnswerUI } from '../../types/slides';
4
- import { Translate } from '../../types/common';
4
+ import { MediaPropsForPlayer, Translate, VideoPropsForPlayer } from '../../types/common';
5
5
  export declare const getQuestionType: (question: Question) => Question['type'];
6
- export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: Translate) => (slide: SlideFromAPI, answers: string[]) => {
6
+ export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: Translate) => (slide: SlideFromAPI, answers: string[], media: MediaPropsForPlayer | VideoPropsForPlayer | void) => {
7
7
  questionText: string;
8
8
  answerUI: AnswerUI;
9
9
  };
@@ -163,30 +163,14 @@ const getAnswerUIModel = (question, answers, dispatch, translate) => {
163
163
  throw new Error(`${type} is not an handled question.type`);
164
164
  }
165
165
  };
166
- const getMedia = (media) => {
167
- if (!media)
168
- return;
169
- const { type } = media;
170
- const resource = get('src.0', media);
171
- switch (type) {
172
- case 'img':
173
- case 'audio':
174
- return {
175
- ...resource,
176
- type,
177
- url: get('url', resource)
178
- };
179
- }
180
- };
181
- export const mapApiSlideToUi = (dispatch, translate) => (slide, answers) => {
166
+ export const mapApiSlideToUi = (dispatch, translate) => (slide, answers, media) => {
182
167
  const questionText = getOr('', 'question.header', slide);
183
- const media = get('question.medias.0', slide);
184
168
  return {
185
169
  questionText,
186
170
  answerUI: {
187
171
  model: getAnswerUIModel(slide.question, answers, dispatch, translate),
188
172
  help: getHelp(slide),
189
- media: getMedia(media)
173
+ media
190
174
  }
191
175
  };
192
176
  };
@@ -0,0 +1,22 @@
1
+ import type { Dispatch } from 'redux';
2
+ import type { ThunkOptions, VideoPropsForPlayer } from '../../types/common';
3
+ import type { StoreState } from '../../reducers';
4
+ export declare const SET_VIDEO_PROPS: "@@slide/SET_VIDEO_PROPS";
5
+ export declare const SHOW_VIDEO: "@@slide/SHOW_VIDEO";
6
+ export declare type VideoPropsPayload = {
7
+ slideId: string;
8
+ props: VideoPropsForPlayer;
9
+ };
10
+ export declare type SetVideoPropsAction = {
11
+ type: typeof SET_VIDEO_PROPS;
12
+ payload: VideoPropsPayload;
13
+ };
14
+ export declare const setVideoProps: (payload: VideoPropsPayload) => SetVideoPropsAction;
15
+ export declare type ShowVideoAction = {
16
+ type: typeof SHOW_VIDEO;
17
+ payload: {
18
+ slideId: string;
19
+ };
20
+ };
21
+ export declare const showVideo: (slideId: string) => ShowVideoAction;
22
+ export declare const fetchPropsVideo: (slideId: string) => (dispatch: Dispatch, getState: () => StoreState, { appendVideoOptions }: ThunkOptions) => Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchPropsVideo = exports.showVideo = exports.setVideoProps = exports.SHOW_VIDEO = exports.SET_VIDEO_PROPS = void 0;
7
+ const get_1 = __importDefault(require("lodash/fp/get"));
8
+ exports.SET_VIDEO_PROPS = '@@slide/SET_VIDEO_PROPS';
9
+ exports.SHOW_VIDEO = '@@slide/SHOW_VIDEO';
10
+ const setVideoProps = (payload) => ({
11
+ type: exports.SET_VIDEO_PROPS,
12
+ payload
13
+ });
14
+ exports.setVideoProps = setVideoProps;
15
+ const showVideo = (slideId) => ({
16
+ type: exports.SHOW_VIDEO,
17
+ payload: { slideId }
18
+ });
19
+ exports.showVideo = showVideo;
20
+ const fetchPropsVideo = (slideId) => async (dispatch, getState, { appendVideoOptions }) => {
21
+ const state = getState();
22
+ const slideFromAPI = (0, get_1.default)(['data', 'slides', slideId], state);
23
+ if (!slideFromAPI) {
24
+ return;
25
+ }
26
+ const slideMedia = (0, get_1.default)(['question', 'medias', '0'], slideFromAPI);
27
+ if (slideMedia && slideMedia.type === 'video') {
28
+ const videoProps = (0, get_1.default)(['data', 'videos', slideId], state);
29
+ if (videoProps) {
30
+ dispatch((0, exports.showVideo)(slideId));
31
+ return;
32
+ }
33
+ const props = await appendVideoOptions(slideMedia);
34
+ props.src[0].loading = false; // set to false to not show it until the next slide is unstack
35
+ props.src[0].type = 'video';
36
+ dispatch((0, exports.setVideoProps)({
37
+ slideId,
38
+ props
39
+ }));
40
+ }
41
+ return;
42
+ };
43
+ exports.fetchPropsVideo = fetchPropsVideo;
@@ -12,5 +12,5 @@ export declare type NextSlideAction = {
12
12
  type: typeof NEXT_SLIDE;
13
13
  payload: NextSlidePayload;
14
14
  };
15
- export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => Promise<NextSlideAction>;
15
+ export declare const nextSlide: (dispatch: Dispatch, getState: () => StoreState) => Promise<void>;
16
16
  export {};
@@ -8,6 +8,7 @@ const filter_1 = __importDefault(require("lodash/fp/filter"));
8
8
  const get_1 = __importDefault(require("lodash/fp/get"));
9
9
  const fetch_rank_1 = require("../api/fetch-rank");
10
10
  const fetch_slides_to_review_by_skill_ref_1 = require("../api/fetch-slides-to-review-by-skill-ref");
11
+ const fetch_video_props_1 = require("../api/fetch-video-props");
11
12
  exports.NEXT_SLIDE = '@@slide/NEXT_SLIDE';
12
13
  const nextSlide = async (dispatch, getState) => {
13
14
  const state = getState();
@@ -29,7 +30,11 @@ const nextSlide = async (dispatch, getState) => {
29
30
  if (nextSlideRef === 'successExitNode') {
30
31
  await dispatch(fetch_rank_1.fetchEndRank);
31
32
  await dispatch(fetch_slides_to_review_by_skill_ref_1.fetchSlidesToReviewBySkillRef);
33
+ dispatch(action);
34
+ }
35
+ else {
36
+ dispatch(action);
37
+ await dispatch((0, fetch_video_props_1.fetchPropsVideo)(payload.nextSlideRef));
32
38
  }
33
- return dispatch(action);
34
39
  };
35
40
  exports.nextSlide = nextSlide;
@@ -1,3 +1,4 @@
1
+ import type { Dispatch } from 'redux';
1
2
  import type { SlideFromAPI } from '@coorpacademy/review-services';
2
3
  import { AnswerUI } from '../../types/slides';
3
4
  declare type SlideUIAnimations = 'unstack' | 'restack';
@@ -16,5 +17,5 @@ export declare type SetCurrentSlideAction = {
16
17
  type: typeof SET_CURRENT_SLIDE;
17
18
  payload: SlideFromAPI;
18
19
  };
19
- export declare const setCurrentSlide: (payload: SlideFromAPI) => SetCurrentSlideAction;
20
+ export declare const setCurrentSlide: (slideFromAPI: SlideFromAPI) => (dispatch: Dispatch) => Promise<void>;
20
21
  export {};
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setCurrentSlide = exports.SET_CURRENT_SLIDE = void 0;
4
+ const fetch_video_props_1 = require("../api/fetch-video-props");
4
5
  exports.SET_CURRENT_SLIDE = '@@slide/SET_CURRENT_SLIDE';
5
- const setCurrentSlide = (payload) => ({
6
- type: exports.SET_CURRENT_SLIDE,
7
- payload
8
- });
6
+ const setCurrentSlide = (slideFromAPI) => async (dispatch) => {
7
+ dispatch({
8
+ type: exports.SET_CURRENT_SLIDE,
9
+ payload: slideFromAPI
10
+ });
11
+ await dispatch((0, fetch_video_props_1.fetchPropsVideo)(slideFromAPI._id));
12
+ return;
13
+ };
9
14
  exports.setCurrentSlide = setCurrentSlide;
@@ -4,6 +4,7 @@ import { SlidesState } from './slides';
4
4
  import { TokenState } from './token';
5
5
  import { RankState } from './rank';
6
6
  import { CurrentSkillState } from './current-skill';
7
+ import { VideoPropsState } from './videos';
7
8
  export declare type DataState = {
8
9
  corrections: CorrectionsState;
9
10
  progression: ProgressionState;
@@ -11,6 +12,7 @@ export declare type DataState = {
11
12
  token: TokenState;
12
13
  rank: RankState;
13
14
  currentSkill: CurrentSkillState;
15
+ videos: VideoPropsState;
14
16
  };
15
17
  declare const _default: import("redux").Reducer<import("redux").CombinedState<{
16
18
  corrections: CorrectionsState;
@@ -19,5 +21,6 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
19
21
  token: string;
20
22
  rank: RankState;
21
23
  currentSkill: CurrentSkillState;
22
- }>, import("../../actions/api/fetch-skill").ReceivedSkill | import("../../actions/api/post-progression").FetchProgression | import("../../actions/api/post-progression").ReceivedProgression | import("./corrections").CorrectionsAction | import("../../actions/api/fetch-rank").RankAction | import("../../actions/api/post-answer").PostAnswerSuccessAction | import("./slides").SlidesAction | import("../../actions/data/token").StoreToken>;
24
+ videos: VideoPropsState;
25
+ }>, import("../../actions/api/fetch-video-props").SetVideoPropsAction | import("../../actions/api/fetch-video-props").ShowVideoAction | import("../../actions/ui/slides").SetCurrentSlideAction | import("../../actions/api/fetch-skill").ReceivedSkill | import("../../actions/api/post-progression").FetchProgression | import("../../actions/api/post-progression").ReceivedProgression | import("./corrections").CorrectionsAction | import("../../actions/api/fetch-rank").RankAction | import("../../actions/api/post-answer").PostAnswerSuccessAction | import("./slides").SlidesAction | import("../../actions/data/token").StoreToken | import("../../actions/ui/next-slide").NextSlideAction>;
23
26
  export default _default;
@@ -10,11 +10,13 @@ const slides_1 = __importDefault(require("./slides"));
10
10
  const token_1 = __importDefault(require("./token"));
11
11
  const rank_1 = __importDefault(require("./rank"));
12
12
  const current_skill_1 = __importDefault(require("./current-skill"));
13
+ const videos_1 = __importDefault(require("./videos"));
13
14
  exports.default = (0, redux_1.combineReducers)({
14
15
  corrections: corrections_1.default,
15
16
  progression: progression_1.default,
16
17
  slides: slides_1.default,
17
18
  token: token_1.default,
18
19
  rank: rank_1.default,
19
- currentSkill: current_skill_1.default
20
+ currentSkill: current_skill_1.default,
21
+ videos: videos_1.default
20
22
  });
@@ -0,0 +1,8 @@
1
+ import { VideoPropsForPlayer } from '../../types/common';
2
+ import { SetVideoPropsAction, ShowVideoAction } from '../../actions/api/fetch-video-props';
3
+ import { NextSlideAction } from '../../actions/ui/next-slide';
4
+ import { SetCurrentSlideAction } from '../../actions/ui/slides';
5
+ export declare type VideoPropsState = Record<string, VideoPropsForPlayer>;
6
+ export declare const initialState: VideoPropsState;
7
+ declare const reducer: (state: VideoPropsState | undefined, action: SetVideoPropsAction | NextSlideAction | SetCurrentSlideAction | ShowVideoAction) => VideoPropsState;
8
+ export default reducer;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialState = void 0;
4
+ const fp_1 = require("lodash/fp");
5
+ const fetch_video_props_1 = require("../../actions/api/fetch-video-props");
6
+ const next_slide_1 = require("../../actions/ui/next-slide");
7
+ exports.initialState = {};
8
+ const reducer = (
9
+ // eslint-disable-next-line default-param-last
10
+ state = exports.initialState, action) => {
11
+ switch (action.type) {
12
+ case fetch_video_props_1.SET_VIDEO_PROPS: {
13
+ const { slideId, props } = action.payload;
14
+ return (0, fp_1.set)(slideId, props, state);
15
+ }
16
+ case next_slide_1.NEXT_SLIDE: {
17
+ const { currentSlideRef } = action.payload;
18
+ const isMediaVideo = (0, fp_1.get)(currentSlideRef, state);
19
+ if (isMediaVideo) {
20
+ return (0, fp_1.set)([currentSlideRef, 'src', '0', 'loading'], true, state);
21
+ }
22
+ return state;
23
+ }
24
+ case fetch_video_props_1.SHOW_VIDEO: {
25
+ const { slideId } = action.payload;
26
+ const isMediaVideo = (0, fp_1.get)(slideId, state);
27
+ if (isMediaVideo) {
28
+ return (0, fp_1.set)([slideId, 'src', '0', 'loading'], false, state);
29
+ }
30
+ return state;
31
+ }
32
+ default:
33
+ return state;
34
+ }
35
+ };
36
+ exports.default = reducer;
@@ -12,6 +12,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
12
12
  token: string;
13
13
  rank: import("./data/rank").RankState;
14
14
  currentSkill: import("./data/current-skill").CurrentSkillState;
15
+ videos: import("./data/videos").VideoPropsState;
15
16
  }>;
16
17
  ui: import("redux").CombinedState<{
17
18
  currentSlideRef: string;
@@ -23,7 +24,7 @@ declare const _default: import("redux").Reducer<import("redux").CombinedState<{
23
24
  showButtonRevising: boolean;
24
25
  showCongrats: boolean;
25
26
  }>;
26
- }>, import("../actions/ui/slides").SetCurrentSlideAction | import("../actions/api/fetch-skill").ReceivedSkill | import("../actions/api/post-progression").FetchProgression | import("../actions/api/post-progression").ReceivedProgression | import("./data/corrections").CorrectionsAction | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/api/fetch-slides-to-review-by-skill-ref").ReceivedSlidesToReviewBySkillRef | import("../actions/ui/next-slide").NextSlideAction | import("../actions/ui/navigation").NavigateToAction | import("../actions/ui/navigation").NavigateBackAction | import("../actions/ui/answers").EditAnswerAction | {
27
+ }>, import("../actions/api/fetch-video-props").SetVideoPropsAction | import("../actions/api/fetch-video-props").ShowVideoAction | import("../actions/ui/slides").SetCurrentSlideAction | import("../actions/api/fetch-skill").ReceivedSkill | import("../actions/api/post-progression").FetchProgression | import("../actions/api/post-progression").ReceivedProgression | import("./data/corrections").CorrectionsAction | import("../actions/api/fetch-rank").RankAction | import("../actions/api/post-answer").PostAnswerRequestAction | import("../actions/api/post-answer").PostAnswerSuccessAction | import("./data/slides").SlidesAction | import("../actions/data/token").StoreToken | import("../actions/api/fetch-slides-to-review-by-skill-ref").ReceivedSlidesToReviewBySkillRef | import("../actions/ui/next-slide").NextSlideAction | import("../actions/ui/navigation").NavigateToAction | import("../actions/ui/navigation").NavigateBackAction | import("../actions/ui/answers").EditAnswerAction | {
27
28
  type: "@@ui/OPEN_POPIN";
28
29
  } | {
29
30
  type: "@@ui/CLOSE_POPIN";
@@ -1,4 +1,4 @@
1
- import type { Services, VideoMedia, VideoPropsForPlayer } from '@coorpacademy/review-services';
1
+ import type { Services, VideoMedia } from '@coorpacademy/review-services';
2
2
  export declare type WithRequired<T, K extends keyof T> = T & {
3
3
  [P in K]-?: T[P];
4
4
  };
@@ -11,6 +11,23 @@ export declare type Skin = {
11
11
  primary: string;
12
12
  };
13
13
  };
14
+ declare type VideoSrcPropsForPlayer = {
15
+ mimeType: string;
16
+ videoId: string;
17
+ jwpOptions: unknown;
18
+ loading?: boolean;
19
+ type: string;
20
+ };
21
+ export declare type VideoPropsForPlayer = {
22
+ type: string;
23
+ src: VideoSrcPropsForPlayer[];
24
+ };
25
+ export declare type MediaPropsForPlayer = {
26
+ type: 'img' | 'audio';
27
+ url: string;
28
+ _id: string;
29
+ mimeType: string;
30
+ };
14
31
  export declare type ConnectedOptions = {
15
32
  translate: Translate;
16
33
  onQuitClick: () => void;
@@ -32,3 +49,4 @@ export declare type ThunkOptions = {
32
49
  export declare type Options = {
33
50
  services: Services;
34
51
  };
52
+ export {};
@@ -68,6 +68,28 @@ const getCurrentSlideRef = (state) => {
68
68
  const isLastSlideAnswered = (slidesRef, slideRef) => {
69
69
  return (0, last_1.default)(slidesRef) === slideRef;
70
70
  };
71
+ const getSlideMedia = (state, slideFromAPI) => {
72
+ const media = (0, get_1.default)(['question', 'medias', '0'], slideFromAPI);
73
+ if (!media)
74
+ return;
75
+ const { type } = media;
76
+ const resource = (0, get_1.default)(['src', '0'], media);
77
+ switch (type) {
78
+ case 'img':
79
+ case 'audio': {
80
+ const mediaProps = {
81
+ ...resource,
82
+ type,
83
+ url: (0, get_1.default)('url', resource)
84
+ };
85
+ return mediaProps;
86
+ }
87
+ case 'video': {
88
+ const videoProps = (0, get_1.default)(['data', 'videos', slideFromAPI._id, 'src', '0'], state);
89
+ return videoProps;
90
+ }
91
+ }
92
+ };
71
93
  const buildStackSlides = (state, dispatch, options) => {
72
94
  const { translate } = options;
73
95
  const currentSlideRef = getCurrentSlideRef(state);
@@ -90,7 +112,8 @@ const buildStackSlides = (state, dispatch, options) => {
90
112
  if (!slideFromAPI)
91
113
  return (0, set_1.default)(index, { ...uiSlide, position }, acc);
92
114
  const answers = (0, getOr_1.default)([], ['ui', 'answers', slideRef], state);
93
- const { questionText, answerUI } = (0, map_api_slide_to_ui_1.mapApiSlideToUi)(dispatch, translate)(slideFromAPI, answers);
115
+ const media = getSlideMedia(state, slideFromAPI);
116
+ const { questionText, answerUI } = (0, map_api_slide_to_ui_1.mapApiSlideToUi)(dispatch, translate)(slideFromAPI, answers, media);
94
117
  const { title: parentContentTitle, type: parentContentType } = slideFromAPI.parentContentTitle;
95
118
  const isCurrentSlideRef = currentSlideRef === slideRef;
96
119
  const slideUI = (0, get_1.default)(['ui', 'slide', slideRef], state);
@@ -1,9 +1,9 @@
1
1
  import { Dispatch } from 'redux';
2
2
  import type { Question, SlideFromAPI } from '@coorpacademy/review-services';
3
3
  import { AnswerUI } from '../../types/slides';
4
- import { Translate } from '../../types/common';
4
+ import { MediaPropsForPlayer, Translate, VideoPropsForPlayer } from '../../types/common';
5
5
  export declare const getQuestionType: (question: Question) => Question['type'];
6
- export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: Translate) => (slide: SlideFromAPI, answers: string[]) => {
6
+ export declare const mapApiSlideToUi: (dispatch: Dispatch, translate: Translate) => (slide: SlideFromAPI, answers: string[], media: MediaPropsForPlayer | VideoPropsForPlayer | void) => {
7
7
  questionText: string;
8
8
  answerUI: AnswerUI;
9
9
  };
@@ -167,30 +167,14 @@ const getAnswerUIModel = (question, answers, dispatch, translate) => {
167
167
  throw new Error(`${type} is not an handled question.type`);
168
168
  }
169
169
  };
170
- const getMedia = (media) => {
171
- if (!media)
172
- return;
173
- const { type } = media;
174
- const resource = (0, fp_1.get)('src.0', media);
175
- switch (type) {
176
- case 'img':
177
- case 'audio':
178
- return {
179
- ...resource,
180
- type,
181
- url: (0, fp_1.get)('url', resource)
182
- };
183
- }
184
- };
185
- const mapApiSlideToUi = (dispatch, translate) => (slide, answers) => {
170
+ const mapApiSlideToUi = (dispatch, translate) => (slide, answers, media) => {
186
171
  const questionText = (0, fp_1.getOr)('', 'question.header', slide);
187
- const media = (0, fp_1.get)('question.medias.0', slide);
188
172
  return {
189
173
  questionText,
190
174
  answerUI: {
191
175
  model: getAnswerUIModel(slide.question, answers, dispatch, translate),
192
176
  help: getHelp(slide),
193
- media: getMedia(media)
177
+ media
194
178
  }
195
179
  };
196
180
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.18.2-test-latest.2+f492cfc58",
3
+ "version": "0.19.0",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -35,11 +35,11 @@
35
35
  "main": "lib/index.js",
36
36
  "module": "es/index.js",
37
37
  "dependencies": {
38
- "@coorpacademy/components": "11.7.3",
38
+ "@coorpacademy/components": "11.8.0",
39
39
  "@coorpacademy/progression-engine": "11.5.3",
40
40
  "@coorpacademy/redux-task": "1.1.6",
41
- "@coorpacademy/review-services": "1.3.2",
42
- "@coorpacademy/review-services-mocks": "1.3.2",
41
+ "@coorpacademy/review-services": "1.3.3",
42
+ "@coorpacademy/review-services-mocks": "1.3.3",
43
43
  "@coorpacademy/translate": "6.2.0",
44
44
  "cross-fetch": "^3.1.5",
45
45
  "jwt-decode": "^3.1.2",
@@ -74,5 +74,5 @@
74
74
  "webpack-cli": "^4.10.0",
75
75
  "webpack-dev-server": "^4.11.1"
76
76
  },
77
- "gitHead": "f492cfc5838281dd911a2f9d1647dbafc125504f"
77
+ "gitHead": "f4e5ea7a4fe865d111ba8d2de620c9f763ec5edd"
78
78
  }
@@ -1 +0,0 @@
1
- {"ignore_dirs":[]}