Open videos box on first co optim

This commit is contained in:
Ky 2019-02-27 11:55:24 +01:00
parent 7ddb21c2f7
commit b7fb018f73
7 changed files with 49 additions and 10 deletions

View File

@ -4,6 +4,13 @@
* *
*/ */
// shouldopenmodal -> action
// reduceur => videos (false, true)
// componentdidupdate if shouldopenmodal is different
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import cn from 'classnames'; import cn from 'classnames';

View File

@ -4,7 +4,7 @@
* *
*/ */
import { GET_VIDEOS, GET_VIDEOS_SUCCEEDED, ON_CLICK, SET_VIDEOS_DURATION, UPDATE_VIDEO_START_TIME, SET_VIDEO_END, REMOVE_VIDEOS } from './constants'; import { GET_VIDEOS, GET_VIDEOS_SUCCEEDED, SHOULD_OPEN_MODAL, ON_CLICK, SET_VIDEOS_DURATION, UPDATE_VIDEO_START_TIME, SET_VIDEO_END, REMOVE_VIDEOS } from './constants';
export function getVideos() { export function getVideos() {
return { return {
@ -19,6 +19,13 @@ export function getVideosSucceeded(videos) {
}; };
} }
export function shouldOpenModal(opened) {
return {
type: SHOULD_OPEN_MODAL,
opened,
};
}
export function onClick(e) { export function onClick(e) {
return { return {
type: ON_CLICK, type: ON_CLICK,

View File

@ -7,6 +7,7 @@
export const GET_VIDEOS = 'StrapiAdmin/Onboarding/GET_VIDEOS'; export const GET_VIDEOS = 'StrapiAdmin/Onboarding/GET_VIDEOS';
export const GET_VIDEOS_SUCCEEDED = export const GET_VIDEOS_SUCCEEDED =
'StrapiAdmin/Onboarding/GET_VIDEOS_SUCCEEDED'; 'StrapiAdmin/Onboarding/GET_VIDEOS_SUCCEEDED';
export const SHOULD_OPEN_MODAL = 'StrapiAdmin/Onboarding/SHOULD_OPEN_MODAL';
export const ON_CLICK = 'StrapiAdmin/Onboarding/ON_CLICK'; export const ON_CLICK = 'StrapiAdmin/Onboarding/ON_CLICK';
export const SET_VIDEOS_DURATION = 'StrapiAdmin/Onboarding/SET_VIDEOS_DURATION'; export const SET_VIDEOS_DURATION = 'StrapiAdmin/Onboarding/SET_VIDEOS_DURATION';
export const UPDATE_VIDEO_START_TIME = 'StrapiAdmin/Onboarding/UPDATE_VIDEO_START_TIME'; export const UPDATE_VIDEO_START_TIME = 'StrapiAdmin/Onboarding/UPDATE_VIDEO_START_TIME';

View File

@ -27,12 +27,13 @@ export class Onboarding extends React.Component {
componentDidMount() { componentDidMount() {
this.props.getVideos(); this.props.getVideos();
}
if (JSON.parse(localStorage.getItem('onboarding')) === null) { componentDidUpdate(prevProps) {
setTimeout(() => { const { shouldOpenModal } = this.props;
this.setState({ showVideos: true });
localStorage.setItem('onboarding', true); if (shouldOpenModal !== prevProps.shouldOpenModal && shouldOpenModal) {
}, 1000); this.handleOpenModal();
} }
} }
@ -54,6 +55,8 @@ export class Onboarding extends React.Component {
this.context.emitEvent(eventName, {timestamp: currTime}); this.context.emitEvent(eventName, {timestamp: currTime});
} }
handleOpenModal = () => this.setState({ showVideos: true });
handleVideosToggle = () => { handleVideosToggle = () => {
this.setState(prevState => ({ showVideos: !prevState.showVideos })); this.setState(prevState => ({ showVideos: !prevState.showVideos }));
@ -135,8 +138,9 @@ Onboarding.defaultProps = {
removeVideos: () => {}, removeVideos: () => {},
setVideoDuration: () => {}, setVideoDuration: () => {},
setVideoEnd: () => {}, setVideoEnd: () => {},
updateVideoStartTime: () => {}, shouldOpenModal: false,
videos: [], videos: [],
updateVideoStartTime: () => {},
}; };
Onboarding.propTypes = { Onboarding.propTypes = {
@ -145,6 +149,7 @@ Onboarding.propTypes = {
removeVideos: PropTypes.func, removeVideos: PropTypes.func,
setVideoDuration: PropTypes.func, setVideoDuration: PropTypes.func,
setVideoEnd: PropTypes.func, setVideoEnd: PropTypes.func,
shouldOpenModal: PropTypes.bool,
updateVideoStartTime: PropTypes.func, updateVideoStartTime: PropTypes.func,
videos: PropTypes.array, videos: PropTypes.array,
}; };

View File

@ -5,7 +5,7 @@
*/ */
import { fromJS } from 'immutable'; import { fromJS } from 'immutable';
import { GET_VIDEOS_SUCCEEDED, ON_CLICK, SET_VIDEOS_DURATION, UPDATE_VIDEO_START_TIME, SET_VIDEO_END, REMOVE_VIDEOS } from './constants'; import { GET_VIDEOS_SUCCEEDED, SHOULD_OPEN_MODAL, ON_CLICK, SET_VIDEOS_DURATION, UPDATE_VIDEO_START_TIME, SET_VIDEO_END, REMOVE_VIDEOS } from './constants';
const initialState = fromJS({ const initialState = fromJS({
videos: fromJS([]), videos: fromJS([]),
@ -15,6 +15,8 @@ function onboardingReducer(state = initialState, action) {
switch (action.type) { switch (action.type) {
case GET_VIDEOS_SUCCEEDED: case GET_VIDEOS_SUCCEEDED:
return state.update('videos', () => fromJS(action.videos)); return state.update('videos', () => fromJS(action.videos));
case SHOULD_OPEN_MODAL:
return state.update('shouldOpenModal', () => action.opened);
case ON_CLICK: case ON_CLICK:
return state.updateIn(['videos'], list => { return state.updateIn(['videos'], list => {
return list.reduce((acc, current, index) => { return list.reduce((acc, current, index) => {

View File

@ -2,7 +2,7 @@ import request from 'utils/request';
import { all, call, fork, takeLatest, put } from 'redux-saga/effects'; import { all, call, fork, takeLatest, put } from 'redux-saga/effects';
import { GET_VIDEOS } from './constants'; import { GET_VIDEOS } from './constants';
import { getVideosSucceeded } from './actions'; import { getVideosSucceeded, shouldOpenModal } from './actions';
function* getVideos() { function* getVideos() {
try { try {
@ -38,11 +38,28 @@ function* getVideos() {
yield put( yield put(
getVideosSucceeded(videos), getVideosSucceeded(videos),
); );
const isFirstTime = JSON.parse(localStorage.getItem('onboarding')) || null;
if (isFirstTime === null) {
yield new Promise(resolve => {
setTimeout(() => {
resolve();
}, 500);
});
yield put(
shouldOpenModal(true),
);
localStorage.setItem('onboarding', true);
}
} catch (err) { } catch (err) {
console.log(err); // eslint-disable-line no-console console.log(err); // eslint-disable-line no-console
} }
} }
function* defaultSaga() { function* defaultSaga() {
yield all([fork(takeLatest, GET_VIDEOS, getVideos)]); yield all([fork(takeLatest, GET_VIDEOS, getVideos)]);
} }

View File

@ -86,7 +86,7 @@
"app.components.NotFoundPage.description": "Page introuvable", "app.components.NotFoundPage.description": "Page introuvable",
"app.components.Official": "Officiel", "app.components.Official": "Officiel",
"app.components.Onboarding.label.completed": "% complétées", "app.components.Onboarding.label.completed": "% complétées",
"app.components.Onboarding.title": "Videos de démarrage", "app.components.Onboarding.title": "Démarrons ensemble",
"app.components.PluginCard.Button.label.download": "Télécharger", "app.components.PluginCard.Button.label.download": "Télécharger",
"app.components.PluginCard.Button.label.install": "Déjà installé", "app.components.PluginCard.Button.label.install": "Déjà installé",
"app.components.PluginCard.Button.label.support": "Nous soutenir", "app.components.PluginCard.Button.label.support": "Nous soutenir",