Commit aa16e9cf authored by Anton Akhmerov's avatar Anton Akhmerov

improve logic of updating the exam list

parent 06983cad
Pipeline #10763 passed with stages
in 2 minutes and 6 seconds
......@@ -65,10 +65,13 @@ class App extends React.Component {
}
updateExam = (examID) => {
api.get('exams/' + examID)
.then(ex => this.setState({
exam: ex
}))
if (examID === null) {
this.setState({ exam: nullExam() })
} else {
api.get('exams/' + examID)
.catch(resp => this.setState({ exam: nullExam() }))
.then(ex => this.setState({ exam: ex }))
}
}
deleteExam = (examID) => {
......
......@@ -102,8 +102,14 @@ class NavBar extends React.Component {
examList: exams
})
const examIDs = exams.map(exam => exam.id)
const examIsValid = this.props.exam.id !== null && examIDs.includes(this.props.exam.id)
if (!examIsValid && exams.length) this.props.updateExam(exams[exams.length - 1].id)
const examID = this.props.exam.id
if (!examIDs.includes(examID) || examID === null) {
if (!exams.length) {
this.props.updateExam(null)
} else {
this.props.updateExam(exams[exams.length - 1].id)
}
}
})
}
......
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