Skip to content
Snippets Groups Projects
Commit e9ec96eb authored by Thomas Roos's avatar Thomas Roos
Browse files

Improve speed and accuracy of submission id on grade page

parent 6fa4a663
No related branches found
No related tags found
No related merge requests found
...@@ -22,28 +22,34 @@ class Grade extends React.Component { ...@@ -22,28 +22,34 @@ class Grade extends React.Component {
examID: null examID: null
} }
static inputString (sub) {
if(sub.student) {
return (sub.student.id + ' (' + sub.student.firstName + ' ' + sub.student.lastName + ')')
}
return ('#' + sub.id)
}
prev = () => { prev = () => {
const newIndex = this.state.sIndex - 1; const newIndex = this.state.sIndex - 1;
if (newIndex >= 0 && newIndex < this.props.exam.submissions.length) { if (newIndex >= 0 && newIndex < this.props.exam.submissions.length) {
this.props.updateSubmission(newIndex)
this.setState({ this.setState({
sIndex: newIndex, sIndex: newIndex,
input: this.props.exam.submissions[newIndex].student.id + ' (' + input: Grade.inputString(this.props.exam.submissions[newIndex])
this.props.exam.submissions[newIndex].student.firstName + ' ' + this.props.exam.submissions[newIndex].student.lastName + ')'
}) })
this.props.updateSubmission(newIndex)
} }
} }
next = () => { next = () => {
const newIndex = this.state.sIndex + 1; const newIndex = this.state.sIndex + 1;
if (newIndex >= 0 && newIndex < this.props.exam.submissions.length) { if (newIndex >= 0 && newIndex < this.props.exam.submissions.length) {
console.log(newIndex + ' / ' + this.props.exam.submissions.length)
this.props.updateSubmission(newIndex)
this.setState({ this.setState({
sIndex: newIndex, sIndex: newIndex,
input: this.props.exam.submissions[newIndex].student.id + ' (' + input: Grade.inputString(this.props.exam.submissions[newIndex])
this.props.exam.submissions[newIndex].student.firstName + ' ' + this.props.exam.submissions[newIndex].student.lastName + ')'
}) })
this.props.updateSubmission(newIndex)
} }
} }
...@@ -70,15 +76,14 @@ class Grade extends React.Component { ...@@ -70,15 +76,14 @@ class Grade extends React.Component {
const sub = this.state.submission.list[i]; const sub = this.state.submission.list[i];
if (i >= 0) { if (i >= 0) {
this.props.updateSubmission(i)
this.setState({ this.setState({
index: i, index: i,
input: sub.student.id + ' (' + sub.student.firstName + ' ' + sub.student.lastName + ')' input: Grade.inputString(sub)
}) })
this.props.updateSubmission(i)
} else { } else {
this.setState({ this.setState({
input: this.props.exam.submissions[this.state.sIndex].student.id + ' (' + input: Grade.inputString(this.props.exam.submissions[this.state.sIndex])
this.props.exam.submissions[this.state.sIndex].student.firstName + ' ' + this.props.exam.submissions[this.state.sIndex].student.lastName + ')'
}) })
alert('Could not find that submission number :(\nSorry!'); alert('Could not find that submission number :(\nSorry!');
} }
...@@ -93,16 +98,14 @@ class Grade extends React.Component { ...@@ -93,16 +98,14 @@ class Grade extends React.Component {
console.log('Nieuwe props') console.log('Nieuwe props')
if (newProps.exam.id != prevState.examID && newProps.exam.submissions.length) { if (newProps.exam.id != prevState.examID && newProps.exam.submissions.length) {
return { return {
input: newProps.exam.submissions[0].student.id + ' (' + input: Grade.inputString(newProps.exam.submissions[0]),
newProps.exam.submissions[0].student.firstName + ' ' + newProps.exam.submissions[0].student.lastName + ')',
sIndex: 0, sIndex: 0,
pIndex: 0, pIndex: 0,
examID: newProps.exam.id examID: newProps.exam.id
} }
} }
return { return {
input: newProps.exam.submissions[prevState.sIndex].student.id + ' (' + input: Grade.inputString(newProps.exam.submissions[prevState.sIndex])
newProps.exam.submissions[prevState.sIndex].student.firstName + ' ' + newProps.exam.submissions[prevState.sIndex].student.lastName + ')'
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment