mirror of
https://github.com/strapi/strapi.git
synced 2025-08-15 04:08:04 +00:00
retrieve videos from API and update redux store and UI
This commit is contained in:
parent
163ca8c317
commit
a2bc9ab609
@ -10,25 +10,22 @@ import cn from 'classnames';
|
|||||||
|
|
||||||
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
|
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import PopUpVideo from 'components/PopUpVideo';
|
|
||||||
import { Player } from 'video-react';
|
import { Player } from 'video-react';
|
||||||
import '../../../../node_modules/video-react/dist/video-react.css';
|
import '../../../../node_modules/video-react/dist/video-react.css';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
import auth from 'utils/auth';
|
|
||||||
|
|
||||||
class OnboardingList extends React.Component {
|
class OnboardingVideo extends React.Component {
|
||||||
|
hiddenPlayer = React.createRef();
|
||||||
player = React.createRef();
|
player = React.createRef();
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
//console.log(this.player.current);
|
this.hiddenPlayer.current.subscribeToStateChange(
|
||||||
this.player.current.subscribeToStateChange(
|
|
||||||
this.handleChangeState.bind(this),
|
this.handleChangeState.bind(this),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeState = (state, prevState) => {
|
handleChangeState = (state, prevState) => {
|
||||||
//console.log({ state, prevState });
|
|
||||||
|
|
||||||
const { duration } = state;
|
const { duration } = state;
|
||||||
const { id } = this.props;
|
const { id } = this.props;
|
||||||
@ -45,11 +42,18 @@ class OnboardingList extends React.Component {
|
|||||||
this.player.current.play();
|
this.player.current.play();
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
/*onModalClose = () => {
|
||||||
const content = this.props.video.isOpen ? 'yo' : 'ya';
|
console.log('CLOSE');
|
||||||
const { video } = this.props;
|
|
||||||
|
|
||||||
//getVideoDuration = e => {};
|
const { player } = this.player.current.getState();
|
||||||
|
const currTime = player.currentTime;
|
||||||
|
|
||||||
|
console.log(currTime);
|
||||||
|
|
||||||
|
};*/
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { video } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
@ -64,62 +68,61 @@ class OnboardingList extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.txtWrapper}>
|
<div className={styles.txtWrapper}>
|
||||||
<p className={styles.title}>{video.title}</p>
|
<p className={styles.title}>{video.title}</p>
|
||||||
<p className={styles.time}>{this.props.video.duration}</p>
|
<p className={styles.time}>{isNaN(video.duration) ? ' ' : `${Math.floor(video.duration / 60)}:${Math.floor(video.duration)%60}`}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <PopUpVideo video={video.video} /> */}
|
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={video.isOpen}
|
isOpen={video.isOpen}
|
||||||
toggle={this.props.onClick}
|
toggle={this.props.onClick}
|
||||||
className={styles.modalPosition}
|
className={styles.videoModal}
|
||||||
onOpened={this.afterOpenModal}
|
onOpened={this.afterOpenModal}
|
||||||
onClosed={this.afterOpenModal}
|
// onClosed={this.onModalClose}
|
||||||
>
|
>
|
||||||
<ModalHeader
|
<ModalHeader
|
||||||
toggle={this.props.onClick}
|
toggle={this.props.onClick}
|
||||||
className={styles.popUpWarningHeader}
|
className={styles.videoModalHeader}
|
||||||
>
|
>
|
||||||
<FormattedMessage id={video.title} />
|
<FormattedMessage id={video.title} />
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody className={styles.modalBodyHelper}>
|
<ModalBody className={styles.modalBodyHelper}>
|
||||||
<div>
|
<div>
|
||||||
{/* <Player
|
<Player
|
||||||
|
ref={this.player}
|
||||||
playsInline
|
playsInline
|
||||||
poster="/assets/poster.png"
|
poster="/assets/poster.png"
|
||||||
src={video.video}
|
src={video.video}
|
||||||
/> */}
|
preload="auto"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
{!video.duration ? (
|
||||||
<div
|
<div className={cn(styles.hiddenPlayerWrapper)}>
|
||||||
className={cn(
|
<Player
|
||||||
styles.playerWrapper,
|
ref={this.hiddenPlayer}
|
||||||
video.isOpen ? styles.visible : '',
|
playsInline
|
||||||
)}
|
poster="/assets/poster.png"
|
||||||
>
|
src={video.video}
|
||||||
<Player
|
preload="auto"
|
||||||
ref={this.player}
|
subscribeToStateChange={this.subscribeToStateChange}
|
||||||
playsInline
|
/>
|
||||||
poster="/assets/poster.png"
|
</div>
|
||||||
src={video.video}
|
) : (
|
||||||
preload="auto"
|
<div></div>
|
||||||
subscribeToStateChange={this.subscribeToStateChange}
|
)}
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnboardingList.defaultProps = {
|
OnboardingVideo.defaultProps = {
|
||||||
video: {},
|
video: {},
|
||||||
setVideoDuration: () => {},
|
setVideoDuration: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
OnboardingList.propTypes = {
|
OnboardingVideo.propTypes = {
|
||||||
videos: PropTypes.object,
|
videos: PropTypes.object,
|
||||||
|
setVideoDuration: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default OnboardingList;
|
export default OnboardingVideo;
|
@ -73,21 +73,27 @@ li.listItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.modal .modal-dialog {
|
||||||
.playerWrapper {
|
|
||||||
background: red;
|
background: red;
|
||||||
width: 100%;
|
}
|
||||||
height: 100%;
|
|
||||||
position: fixed;
|
.hiddenPlayerWrapper {
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
z-index: 1051;
|
|
||||||
display: none;
|
display: none;
|
||||||
max-width: 74.5rem;
|
}
|
||||||
margin: 16rem auto 3rem calc(50% - 24rem);
|
|
||||||
&.visible {
|
.videoModal {
|
||||||
display: block;
|
margin-right: auto !important;
|
||||||
|
margin-left: auto !important;
|
||||||
|
.videoModalHeader {
|
||||||
|
border-bottom: 0;
|
||||||
|
> h5 {
|
||||||
|
font-family: Lato;
|
||||||
|
font-weight: bold!important;
|
||||||
|
font-size: 1.8rem!important;
|
||||||
|
}
|
||||||
|
> button {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -283,8 +283,7 @@ export class AdminPage extends React.Component {
|
|||||||
isOpen={this.props.blockApp && this.props.showGlobalAppBlocker}
|
isOpen={this.props.blockApp && this.props.showGlobalAppBlocker}
|
||||||
{...this.props.overlayBlockerData}
|
{...this.props.overlayBlockerData}
|
||||||
/>
|
/>
|
||||||
|
<Onboarding/>
|
||||||
<Onboarding />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { GET_VIDEOS, GET_VIDEOS_SUCCEEDED, ON_CLICK } from './constants';
|
import { GET_VIDEOS, GET_VIDEOS_SUCCEEDED, ON_CLICK, SET_VIDEOS_DURATION } from './constants';
|
||||||
|
|
||||||
export function getVideos() {
|
export function getVideos() {
|
||||||
return {
|
return {
|
||||||
@ -18,9 +18,18 @@ export function getVideosSucceeded(videos) {
|
|||||||
videos,
|
videos,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onClick(e) {
|
export function onClick(e) {
|
||||||
return {
|
return {
|
||||||
type: ON_CLICK,
|
type: ON_CLICK,
|
||||||
index: parseInt(e.currentTarget.id, 10),
|
index: parseInt(e.currentTarget.id, 10),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setVideoDuration(id, duration) {
|
||||||
|
return {
|
||||||
|
type: SET_VIDEOS_DURATION,
|
||||||
|
index: parseInt(id, 10),
|
||||||
|
duration: parseFloat(duration, 10),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
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 ON_CLICK = 'StrapiAdmin/Onboarding/ON_CLICK';
|
export const ON_CLICK = 'StrapiAdmin/Onboarding/ON_CLICK';
|
||||||
|
export const SET_VIDEOS_DURATION = 'StrapiAdmin/Onboarding/SET_VIDEOS_DURATION';
|
||||||
|
@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
|
|||||||
import cn from 'classnames';
|
import cn from 'classnames';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators, compose } from 'redux';
|
import { bindActionCreators, compose } from 'redux';
|
||||||
import { getVideos, onClick } from './actions';
|
import { getVideos, onClick, setVideoDuration } from './actions';
|
||||||
|
|
||||||
import injectSaga from 'utils/injectSaga';
|
import injectSaga from 'utils/injectSaga';
|
||||||
import injectReducer from 'utils/injectReducer';
|
import injectReducer from 'utils/injectReducer';
|
||||||
@ -17,29 +17,21 @@ import makeSelectOnboarding from './selectors';
|
|||||||
import reducer from './reducer';
|
import reducer from './reducer';
|
||||||
import saga from './saga';
|
import saga from './saga';
|
||||||
|
|
||||||
import OnboardingVideo from 'components/OnboardingList';
|
import OnboardingVideo from 'components/OnboardingVideo';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
import auth from 'utils/auth';
|
|
||||||
|
|
||||||
export class Onboarding extends React.Component {
|
export class Onboarding extends React.Component {
|
||||||
state = { showVideos: false };
|
state = { showVideos: false, videosTime: [] };
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.setState({ showVideos: true });
|
this.setState({ showVideos: true });
|
||||||
this.props.getVideos();
|
|
||||||
|
|
||||||
localStorage.setItem('videos', JSON.stringify(['video0', 'video1']));
|
if (!localStorage.getItem('videos')) {
|
||||||
console.log(localStorage.getItem('videos'));
|
localStorage.setItem('videos', JSON.stringify([0,0,0,0]));
|
||||||
|
|
||||||
if (auth.get('videos')) {
|
|
||||||
console.log('localStorageExist');
|
|
||||||
console.log(auth.get('videos'));
|
|
||||||
} else {
|
|
||||||
console.log('localStorageNoooo');
|
|
||||||
auth.set('videos', JSON.stringify(['video0', 'video1']), true);
|
|
||||||
//localStorage.setItem('videos', stringify(['video0', 'video1']));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.props.getVideos();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleVideos = e => {
|
toggleVideos = e => {
|
||||||
@ -48,7 +40,7 @@ export class Onboarding extends React.Component {
|
|||||||
|
|
||||||
// eslint-disable-line react/prefer-stateless-function
|
// eslint-disable-line react/prefer-stateless-function
|
||||||
render() {
|
render() {
|
||||||
const { videos, onClick } = this.props;
|
const { videos, onClick, setVideoDuration } = this.props;
|
||||||
return (
|
return (
|
||||||
<div className={styles.videosWrapper}>
|
<div className={styles.videosWrapper}>
|
||||||
<div
|
<div
|
||||||
@ -70,6 +62,7 @@ export class Onboarding extends React.Component {
|
|||||||
id={i}
|
id={i}
|
||||||
video={video}
|
video={video}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
setVideoDuration={setVideoDuration}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -98,7 +91,7 @@ Onboarding.propTypes = {
|
|||||||
const mapStateToProps = makeSelectOnboarding();
|
const mapStateToProps = makeSelectOnboarding();
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
return bindActionCreators({ getVideos, onClick }, dispatch);
|
return bindActionCreators({ getVideos, onClick, setVideoDuration }, dispatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
const withConnect = connect(
|
const withConnect = connect(
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { fromJS } from 'immutable';
|
import { fromJS } from 'immutable';
|
||||||
import { GET_VIDEOS_SUCCEEDED, ON_CLICK } from './constants';
|
import { GET_VIDEOS_SUCCEEDED, ON_CLICK, SET_VIDEOS_DURATION } from './constants';
|
||||||
|
|
||||||
const initialState = fromJS({
|
const initialState = fromJS({
|
||||||
videos: fromJS([]),
|
videos: fromJS([]),
|
||||||
@ -25,6 +25,8 @@ function onboardingReducer(state = initialState, action) {
|
|||||||
return acc.updateIn([index, 'isOpen'], () => false);
|
return acc.updateIn([index, 'isOpen'], () => false);
|
||||||
}, list);
|
}, list);
|
||||||
});
|
});
|
||||||
|
case SET_VIDEOS_DURATION:
|
||||||
|
return state.updateIn(['videos', action.index, 'duration'], () => action.duration);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,14 @@ function* getVideos() {
|
|||||||
|
|
||||||
yield put(
|
yield put(
|
||||||
getVideosSucceeded(
|
getVideosSucceeded(
|
||||||
videos.map(video => {
|
videos.map((video, index) => {
|
||||||
|
|
||||||
video.isOpen = false;
|
video.isOpen = false;
|
||||||
|
/*if (index === 0) {
|
||||||
|
video.isOpen = true;
|
||||||
|
}*/
|
||||||
video.duration = null;
|
video.duration = null;
|
||||||
|
video.startTime = localStorage.getItem("videos");
|
||||||
|
|
||||||
return video;
|
return video;
|
||||||
}),
|
}),
|
||||||
|
@ -58,15 +58,11 @@ const auth = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
set(value, key, isLocalStorage) {
|
set(value, key, isLocalStorage) {
|
||||||
console.log(value);
|
|
||||||
console.log(key);
|
|
||||||
console.log(isLocalStorage);
|
|
||||||
if (isEmpty(value)) {
|
if (isEmpty(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalStorage && localStorage) {
|
if (isLocalStorage && localStorage) {
|
||||||
console.log('Hey');
|
|
||||||
return localStorage.setItem(key, stringify(value));
|
return localStorage.setItem(key, stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user