2018-02-20 17:04:45 -05:00
|
|
|
const React = require('react');
|
2018-03-08 15:57:19 -05:00
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const bindAll = require('lodash.bindall');
|
|
|
|
const connect = require('react-redux').connect;
|
|
|
|
const Page = require('../../components/page/www/page.jsx');
|
2018-02-20 17:04:45 -05:00
|
|
|
const render = require('../../lib/render.jsx');
|
|
|
|
|
2018-03-08 15:57:19 -05:00
|
|
|
const api = require('../../lib/api');
|
|
|
|
const log = require('../../lib/log.js');
|
|
|
|
|
|
|
|
const PreviewPresentation = require('./presentation.jsx');
|
|
|
|
|
|
|
|
const sessionActions = require('../../redux/session.js');
|
2018-02-20 17:04:45 -05:00
|
|
|
|
|
|
|
class Preview extends React.Component {
|
2018-03-08 15:57:19 -05:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
|
|
|
'getProjectInfo'
|
|
|
|
]);
|
|
|
|
this.state = {
|
|
|
|
projectInfo: {} // project data to show
|
|
|
|
};
|
|
|
|
}
|
2018-02-20 17:04:45 -05:00
|
|
|
componentDidMount () {
|
2018-03-08 15:57:19 -05:00
|
|
|
let pathname = window.location.pathname.toLowerCase();
|
|
|
|
if (pathname[pathname.length - 1] === '/') {
|
|
|
|
pathname = pathname.substring(0, pathname.length - 1);
|
|
|
|
}
|
|
|
|
const path = pathname.split('/');
|
|
|
|
const projectId = path[path.length - 1];
|
|
|
|
this.getProjectInfo(projectId);
|
|
|
|
}
|
|
|
|
getProjectInfo (projectId) {
|
|
|
|
api({
|
|
|
|
uri: `/projects/${projectId}`
|
|
|
|
}, (err, body) => {
|
|
|
|
if (!body) return log.error('No project info');
|
|
|
|
if (!err) return this.setState({projectInfo: body});
|
|
|
|
});
|
2018-02-20 17:04:45 -05:00
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
2018-03-08 15:57:19 -05:00
|
|
|
<PreviewPresentation
|
|
|
|
projectInfo={this.state.projectInfo}
|
|
|
|
sessionStatus={this.props.sessionStatus}
|
|
|
|
/>
|
2018-02-20 17:04:45 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 15:57:19 -05:00
|
|
|
Preview.propTypes = {
|
|
|
|
sessionStatus: PropTypes.string,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.number,
|
|
|
|
banned: PropTypes.bool,
|
|
|
|
username: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
|
|
|
thumbnailUrl: PropTypes.string,
|
|
|
|
dateJoined: PropTypes.string,
|
|
|
|
email: PropTypes.string,
|
|
|
|
classroomId: PropTypes.string
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
Preview.defaultProps = {
|
|
|
|
sessionStatus: sessionActions.Status.NOT_FETCHED,
|
|
|
|
user: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
sessionStatus: state.session.status,
|
|
|
|
user: state.session.session.user
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
refreshSession: () => {
|
|
|
|
dispatch(sessionActions.refreshSession());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const ConnectedPreview = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Preview);
|
|
|
|
|
|
|
|
render(<Page><ConnectedPreview /></Page>, document.getElementById('app'));
|