var LoadableItem, Name, React, ScoresActions, ScoresStore, ViewingAsStudentName, ref;
React = require('react');
LoadableItem = require('../loadable-item');
Name = require('../name');
ref = require('../../flux/scores'), ScoresStore = ref.ScoresStore, ScoresActions = ref.ScoresActions;
ViewingAsStudentName = React.createClass({
displayName: 'ViewingAsStudentName',
propTypes: {
courseId: React.PropTypes.string.isRequired,
taskId: React.PropTypes.string.isRequired,
className: React.PropTypes.string
},
getInitialState: function() {
return this.getStudentState();
},
getStudentState: function(props) {
var courseId, ref1, student, taskId;
ref1 = props || this.props, courseId = ref1.courseId, taskId = ref1.taskId;
student = ScoresStore.getStudentOfTask(courseId, taskId);
return {
student: student
};
},
updateStudent: function(props) {
if (props == null) {
props = this.props;
}
return this.setState(this.getStudentState(props));
},
componentWillMount: function() {
var courseId, ref1, student, taskId;
ref1 = this.props, courseId = ref1.courseId, taskId = ref1.taskId;
student = this.state.student;
if (student == null) {
ScoresStore.once('change', this.updateStudent);
return ScoresActions.load(courseId);
}
},
componentWillReceiveProps: function(nextProps) {
return this.updateStudent(nextProps);
},
render: function() {
var className, student, studentName;
className = this.props.className;
studentName = null;
className += ' task-student';
student = this.state.student;
if (student != null) {
studentName = React.createElement("div", {
"className": className
}, React.createElement(Name, React.__spread({}, student)));
}
return studentName;
}
});
module.exports = {
ViewingAsStudentName: ViewingAsStudentName
};
|