Files
freeCodeCamp/common/app/routes/Hikes/components/Lecture.jsx

95 lines
2.3 KiB
React
Raw Normal View History

2015-07-09 00:29:29 -07:00
import React, { PropTypes } from 'react';
2015-07-15 23:36:33 -07:00
import { Button, Col, Row, Panel } from 'react-bootstrap';
2015-07-15 20:50:11 -07:00
import { Navigation } from 'react-router';
import { contain } from 'thundercats-react';
2015-07-09 00:29:29 -07:00
import stampit from 'react-stampit';
import Vimeo from 'react-vimeo';
import debugFactory from 'debug';
const debug = debugFactory('freecc:hikes');
export default contain(
{
store: 'hikesStore',
fetchAction: 'hikesActions.fetchCurrentHike',
getPayload({ currentHike, params: { dashedName } }) {
const filterRegex = new RegExp(dashedName, 'i');
if (currentHike && filterRegex.test(currentHike.dashedName)) {
return {
isPrimed: true,
dashedName
};
}
return {
isPrimed: false,
dashedName: dashedName
};
}
2015-07-09 00:29:29 -07:00
},
stampit(React, {
displayName: 'Lecture',
2015-07-09 00:29:29 -07:00
propTypes: {
currentHike: PropTypes.object,
dashedName: PropTypes.string,
params: PropTypes.object
},
handleError: debug,
2015-07-15 20:50:11 -07:00
handleFinish() {
debug('loading questions');
2015-07-15 20:50:11 -07:00
const { dashedName } = this.props.params;
this.transitionTo(`/hikes/${dashedName}/questions/1`);
2015-07-14 23:44:21 -07:00
},
2015-07-16 09:04:57 -07:00
renderTranscript(transcript) {
return transcript.map((line, index) => (
<p key={ index }>{ line }</p>
)
);
},
render() {
2015-07-14 23:06:54 -07:00
const {
title,
2015-07-15 20:50:11 -07:00
challengeSeed = ['1'],
description = []
2015-07-14 23:06:54 -07:00
} = this.props.currentHike;
const [ id ] = challengeSeed;
2015-07-09 00:29:29 -07:00
2015-07-14 23:44:21 -07:00
const videoTitle = <h2>{ title }</h2>;
return (
<Col xs={ 12 }>
<Row>
2015-07-14 23:44:21 -07:00
<Panel className={ 'text-center' } title={ videoTitle }>
<Vimeo
onError={ this.handleError }
2015-07-15 20:50:11 -07:00
onFinish= { ::this.handleFinish }
2015-07-14 23:44:21 -07:00
videoId={ id } />
</Panel>
</Row>
2015-07-15 20:50:11 -07:00
<Row>
<Col xs={ 12 }>
<Panel>
<p>
2015-07-16 09:04:57 -07:00
{ this.renderTranscript(description) }
2015-07-15 20:50:11 -07:00
</p>
</Panel>
2015-07-15 23:36:33 -07:00
<Panel>
<Button
block={ true }
bsSize='large'
onClick={ ::this.handleFinish }>
Take me to the Questions
</Button>
</Panel>
2015-07-15 20:50:11 -07:00
</Col>
</Row>
</Col>
);
}
2015-07-15 20:50:11 -07:00
}).compose(Navigation)
);