Commit b1ccd08a authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

Merge branch '540-students-page-crashing' into 'master'

Student page crashing after infinite recursion

Closes #540

See merge request zesje/zesje!327
parents 4a7ccad0 02599a75
......@@ -43,6 +43,7 @@ class ExamRouter extends React.PureComponent {
componentDidUpdate = (prevProps, prevState) => {
const examID = this.props.parentMatch.params.examID
if (prevProps.parentMatch.params.examID !== examID) {
// sends the selected exam to the navbar
this.props.selectExam(examID)
}
}
......@@ -60,6 +61,10 @@ class ExamRouter extends React.PureComponent {
const examID = this.props.parentMatch.params.examID
const parentURL = this.props.parentMatch.url
if (!examID || isNaN(examID)) {
return <Fail message={'Invalid exam'} />
}
return (
<Switch>
<Route path={`${parentURL}/scans`} render={({ match }) =>
......
......@@ -122,7 +122,7 @@ class NavBar extends React.Component {
}
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.examID !== this.props.examID) {
if (prevProps.examID !== this.props.examID && !isNaN(this.props.examID)) {
this.setState({examID: this.props.examID})
}
}
......
......@@ -7,6 +7,7 @@ import Hero from '../components/Hero.jsx'
import ProgressBar from '../components/ProgressBar.jsx'
import SearchBox from '../components/SearchBox.jsx'
import withShortcuts from '../components/ShortcutBinder.jsx'
import Fail from './Fail.jsx'
import SearchPanel from './students/SearchPanel.jsx'
import EditPanel from './students/EditPanel.jsx'
......@@ -19,7 +20,7 @@ class CheckStudents extends React.Component {
editStud: null,
index: 0,
copies: [],
examID: null // The exam ID the loaded copies belong to
examID: undefined // The exam ID the loaded copies belong to
}
componentDidMount = () => {
......@@ -40,14 +41,14 @@ class CheckStudents extends React.Component {
this.fetchCopies()
}
componentDidUpdate = () => {
if (this.state.examID !== this.props.examID) {
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.examID !== this.props.examID) {
this.fetchCopies()
}
}
fetchCopies = () => {
if (this.props.examID === null) return
if (!this.props.examID || isNaN(this.props.examID)) return
api.get(`copies/${this.props.examID}`).then(copies => {
const newIndex = this.state.index < copies.length ? this.state.index : 0
......@@ -56,6 +57,13 @@ class CheckStudents extends React.Component {
copies: copies,
examID: this.props.examID
})
}).catch(err => {
console.log(err)
this.setState({
index: 0,
copies: [],
examID: null
})
})
}
......@@ -144,10 +152,18 @@ class CheckStudents extends React.Component {
const total = copies.length
const done = copies.filter(c => c.validated).length
const hero = <Hero title='Match Students' subtitle='Check that all submissions are correctly identified' />
if (this.state.examID === undefined && this) return hero
if (!this.state.examID) {
return <Fail message={'No copies where found for this exam'} />
}
return (
<div>
<Hero title='Match Students' subtitle='Check that all submissions are correctly identified' />
{hero}
<section className='section'>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment