2015-12-22 19:33:25 -08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-01-27 11:34:44 -08:00
|
|
|
import { connect } from 'react-redux';
|
2016-01-15 03:09:31 -08:00
|
|
|
import { Col, Row } from 'react-bootstrap';
|
2016-01-27 11:34:44 -08:00
|
|
|
import { createSelector } from 'reselect';
|
2015-12-22 19:33:25 -08:00
|
|
|
|
|
|
|
|
import Lecture from './Lecture.jsx';
|
|
|
|
|
import Questions from './Questions.jsx';
|
2016-01-27 11:34:44 -08:00
|
|
|
import { resetHike } from '../redux/actions';
|
2016-02-04 15:03:05 -08:00
|
|
|
import { getCurrentHike } from '../redux/selectors';
|
2015-12-22 19:33:25 -08:00
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
const mapStateToProps = createSelector(
|
2016-02-04 15:03:05 -08:00
|
|
|
getCurrentHike,
|
|
|
|
|
state => state.hikesApp.shouldShowQuestions,
|
|
|
|
|
(currentHike, shouldShowQuestions) => ({
|
|
|
|
|
title: currentHike ? currentHike.title : '',
|
|
|
|
|
shouldShowQuestions
|
|
|
|
|
})
|
2016-01-06 13:17:57 -08:00
|
|
|
);
|
2016-02-04 12:40:49 -08:00
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
// export plain component for testing
|
|
|
|
|
export class Hike extends React.Component {
|
|
|
|
|
static displayName = 'Hike';
|
|
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-02-04 14:13:13 -08:00
|
|
|
// actions
|
2016-01-27 11:34:44 -08:00
|
|
|
resetHike: PropTypes.func,
|
2016-02-04 14:13:13 -08:00
|
|
|
// ui
|
|
|
|
|
title: PropTypes.string,
|
|
|
|
|
params: PropTypes.object,
|
|
|
|
|
shouldShowQuestions: PropTypes.bool
|
2016-01-27 11:34:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
this.props.resetHike();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps({ params: { dashedName } }) {
|
|
|
|
|
if (this.props.params.dashedName !== dashedName) {
|
|
|
|
|
this.props.resetHike();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderBody(showQuestions) {
|
|
|
|
|
if (showQuestions) {
|
|
|
|
|
return <Questions />;
|
|
|
|
|
}
|
|
|
|
|
return <Lecture />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
title,
|
2016-02-04 14:13:13 -08:00
|
|
|
shouldShowQuestions
|
2016-01-27 11:34:44 -08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Col xs={ 12 }>
|
|
|
|
|
<Row>
|
|
|
|
|
<header className='text-center'>
|
|
|
|
|
<h4>{ title }</h4>
|
|
|
|
|
</header>
|
|
|
|
|
<hr />
|
|
|
|
|
<div className='spacer' />
|
|
|
|
|
<section
|
|
|
|
|
className={ 'text-center' }
|
|
|
|
|
title={ title }>
|
2016-02-04 14:13:13 -08:00
|
|
|
{ this.renderBody(shouldShowQuestions) }
|
2016-01-27 11:34:44 -08:00
|
|
|
</section>
|
|
|
|
|
</Row>
|
|
|
|
|
</Col>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// export redux aware component
|
2016-02-04 12:40:49 -08:00
|
|
|
export default connect(mapStateToProps, { resetHike })(Hike);
|