Add overview of open and completed quiz rounds

This commit is contained in:
2022-11-08 00:28:12 +01:00
parent b45114a2d1
commit 22deb8812a
8 changed files with 317 additions and 133 deletions

View File

@@ -42,7 +42,7 @@
<TutorPanel :course-id="courseID" />
</v-col>
<v-col cols="12">
<Challenge :course-id="courseID" />
<QuizComponent :course-id="courseID" />
</v-col>
<v-col cols="12">
<Coop :course-id="courseID" />

View File

@@ -181,6 +181,7 @@ export default {
this.game.player2id = this.$auth.currentUser.uid
this.game.player2name = this.$store.state.user.displayName
this.game.player2answers = []
this.game.playerIds.push(this.game.player2id)
// Get a new write batch
const batch = writeBatch(this.$db)
@@ -214,6 +215,7 @@ export default {
null,
rndQuestions.map(q => q.id),
Date.now() / 1000, // Current UNIX timestamp in seconds
false,
this.$auth.currentUser.uid,
this.$store.state.user.displayName,
[],
@@ -252,7 +254,11 @@ export default {
// Update the user's given answers for the current game
const gameRef = doc(this.$db, `kurse/${this.courseID}/spiele/${this.game.id}`)
batch.update(gameRef, {
[`spieler${this.playerNumber}antworten`]: arrayUnion({ frage: this.selectedQuestion.id, antwort: this.submittedAnswer })
[`spieler${this.playerNumber}antworten`]: arrayUnion({
frage: this.selectedQuestion.id,
antwort: this.submittedAnswer,
richtig: this.answerCorrect
})
})
// Increment the number of correct/incorrect answers given by the user by 1
@@ -265,7 +271,11 @@ export default {
// Commit the batch
batch.commit().then((empty) => {
// Batch execution was successful
this.game[`player${this.playerNumber}answers`].push({ frage: this.selectedQuestion.id, antwort: this.submittedAnswer })
this.game[`player${this.playerNumber}answers`].push({
frage: this.selectedQuestion.id,
antwort: this.submittedAnswer,
richtig: this.answerCorrect
})
}).catch((error) => {
// Batch execution failed; display error message
this.$toast({content: error, color: 'error'})
@@ -319,6 +329,7 @@ export default {
})
},
completeGame () {
this.game.completed = true
const result = this.game.getResult()
// Figure out which player won and which player lost, or if the game was a tie
@@ -345,6 +356,10 @@ export default {
const refPl2 = doc(this.$db, `benutzer/${this.game.player2id}`)
batch.update(refPl2, { [`spiele.${this.courseID}.${updateFieldPl2}`]: increment(1) })
// Set the game's "completed" field to true
const refGame = doc(this.$db, `kurse/${this.courseID}/spiele/${this.game.id}`)
batch.update(refGame, { abgeschlossen: true })
// Commit the batch
batch.commit().catch((error) => {
// Batch execution failed; display error message