Fix transitioning between hikes resets questions
This commit is contained in:
@ -10,7 +10,7 @@ const initValue = {
|
|||||||
hikes: [],
|
hikes: [],
|
||||||
// lecture state
|
// lecture state
|
||||||
currentHike: {},
|
currentHike: {},
|
||||||
showQuestion: false
|
showQuestions: false
|
||||||
},
|
},
|
||||||
jobsApp: {
|
jobsApp: {
|
||||||
showModal: false
|
showModal: false
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
|
import { contain } from 'thundercats-react';
|
||||||
import {
|
import {
|
||||||
Col,
|
Col,
|
||||||
Panel,
|
Panel,
|
||||||
@ -8,40 +9,56 @@ import {
|
|||||||
import Lecture from './Lecture.jsx';
|
import Lecture from './Lecture.jsx';
|
||||||
import Questions from './Questions.jsx';
|
import Questions from './Questions.jsx';
|
||||||
|
|
||||||
export default React.createClass({
|
export default contain(
|
||||||
displayName: 'Hike',
|
{
|
||||||
|
actions: ['hikesActions']
|
||||||
propTypes: {
|
|
||||||
currentHike: PropTypes.object,
|
|
||||||
showQuestions: PropTypes.bool
|
|
||||||
},
|
},
|
||||||
|
React.createClass({
|
||||||
|
displayName: 'Hike',
|
||||||
|
|
||||||
renderBody(showQuestions) {
|
propTypes: {
|
||||||
if (showQuestions) {
|
currentHike: PropTypes.object,
|
||||||
return <Questions />;
|
hikesActions: PropTypes.object,
|
||||||
|
params: PropTypes.object,
|
||||||
|
showQuestions: PropTypes.bool
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps({ params: { dashedName }, showQuestions }) {
|
||||||
|
if (
|
||||||
|
showQuestions &&
|
||||||
|
this.props.params.dashedName !== dashedName
|
||||||
|
) {
|
||||||
|
this.props.hikesActions.toggleQuestions();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renderBody(showQuestions) {
|
||||||
|
if (showQuestions) {
|
||||||
|
return <Questions />;
|
||||||
|
}
|
||||||
|
return <Lecture />;
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
currentHike: { title } = {},
|
||||||
|
showQuestions
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const videoTitle = <h4>{ title }</h4>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Col xs={ 12 }>
|
||||||
|
<Row>
|
||||||
|
<Panel
|
||||||
|
className={ 'text-center' }
|
||||||
|
header={ videoTitle }
|
||||||
|
title={ title }>
|
||||||
|
{ this.renderBody(showQuestions) }
|
||||||
|
</Panel>
|
||||||
|
</Row>
|
||||||
|
</Col>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return <Lecture />;
|
})
|
||||||
},
|
);
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
currentHike: { title } = {},
|
|
||||||
showQuestions
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
const videoTitle = <h4>{ title }</h4>;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Col xs={ 12 }>
|
|
||||||
<Row>
|
|
||||||
<Panel
|
|
||||||
className={ 'text-center' }
|
|
||||||
header={ videoTitle }
|
|
||||||
title={ title }>
|
|
||||||
{ this.renderBody(showQuestions) }
|
|
||||||
</Panel>
|
|
||||||
</Row>
|
|
||||||
</Col>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
@ -69,7 +69,7 @@ export default contain(
|
|||||||
<Row>
|
<Row>
|
||||||
<Vimeo
|
<Vimeo
|
||||||
onError={ this.handleError }
|
onError={ this.handleError }
|
||||||
onFinish= { this.handleFinish }
|
onFinish= { () => this.handleFinish(hikesActions) }
|
||||||
videoId={ id } />
|
videoId={ id } />
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
|
@ -88,7 +88,11 @@ export default Actions({
|
|||||||
toggleQuestions() {
|
toggleQuestions() {
|
||||||
return {
|
return {
|
||||||
transform(state) {
|
transform(state) {
|
||||||
const hikesApp = { ...state.hikesApp, showQuestions: true };
|
const hikesApp = {
|
||||||
|
...state.hikesApp,
|
||||||
|
showQuestions: !state.hikesApp.showQuestions,
|
||||||
|
currentQuestion: 1
|
||||||
|
};
|
||||||
return { ...state, hikesApp };
|
return { ...state, hikesApp };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user