Fix transitioning between hikes resets questions

This commit is contained in:
Berkeley Martinez
2016-01-06 13:17:57 -08:00
parent cb101a631f
commit 5c10678a58
4 changed files with 58 additions and 37 deletions

View File

@ -10,7 +10,7 @@ const initValue = {
hikes: [], hikes: [],
// lecture state // lecture state
currentHike: {}, currentHike: {},
showQuestion: false showQuestions: false
}, },
jobsApp: { jobsApp: {
showModal: false showModal: false

View File

@ -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>
);
}
});

View File

@ -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>

View File

@ -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 };
} }
}; };