Fix: user stats would only be updated after a hard refresh
This commit is contained in:
@@ -275,6 +275,9 @@ export default {
|
|||||||
antwort: this.submittedAnswer,
|
antwort: this.submittedAnswer,
|
||||||
richtig: this.answerCorrect
|
richtig: this.answerCorrect
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Update user stats (correct/incorrect answers given) in store
|
||||||
|
this.$store.commit('addAnswerToStats', this.answerCorrect)
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
// Batch execution failed; display error message
|
// Batch execution failed; display error message
|
||||||
this.$toast({content: error, color: 'error'})
|
this.$toast({content: error, color: 'error'})
|
||||||
@@ -360,7 +363,10 @@ export default {
|
|||||||
batch.update(refGame, { abgeschlossen: true })
|
batch.update(refGame, { abgeschlossen: true })
|
||||||
|
|
||||||
// Commit the batch
|
// Commit the batch
|
||||||
batch.commit().catch((error) => {
|
batch.commit().then((empty) => {
|
||||||
|
// Update user stats (wins/losses/ties) in store
|
||||||
|
this.$store.commit('addGameToStats', { won: result.winner === this.playerNumber, tie: result.tie })
|
||||||
|
}).catch((error) => {
|
||||||
// Batch execution failed; display error message
|
// Batch execution failed; display error message
|
||||||
this.$toast({ content: error, color: 'error' })
|
this.$toast({ content: error, color: 'error' })
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -55,6 +55,28 @@ export const mutations = {
|
|||||||
setSelectedCourse (state, courseID) {
|
setSelectedCourse (state, courseID) {
|
||||||
state.selectedCourse = courseID
|
state.selectedCourse = courseID
|
||||||
},
|
},
|
||||||
|
addGameInProgress (state, { courseID, gameID }) {
|
||||||
|
const index = state.user.gamesStarted.findIndex(e => e.course === courseID)
|
||||||
|
if (index !== -1) {
|
||||||
|
state.user.gamesStarted[index].course = courseID
|
||||||
|
state.user.gamesStarted[index].game = gameID
|
||||||
|
} else {
|
||||||
|
state.user.gamesStarted.push({ course: courseID, game: gameID })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeGameInProgress (state, courseID) {
|
||||||
|
const index = state.user.gamesStarted.findIndex(e => e.course === courseID)
|
||||||
|
state.user.gamesStarted.splice(index, 1)
|
||||||
|
},
|
||||||
|
addAnswerToStats (state, answerCorrect) {
|
||||||
|
if (answerCorrect) state.user.games[state.selectedCourse].questionsCorrect++
|
||||||
|
else state.user.games[state.selectedCourse].questionsIncorrect++
|
||||||
|
},
|
||||||
|
addGameToStats (state, { won, tie }) {
|
||||||
|
if (tie) state.user.games[state.selectedCourse].tie++
|
||||||
|
else if (won) state.user.games[state.selectedCourse].won++
|
||||||
|
else state.user.games[state.selectedCourse].lost++
|
||||||
|
},
|
||||||
setOpenEndedQuestions (state, questions) {
|
setOpenEndedQuestions (state, questions) {
|
||||||
state.openEndedQuestions = questions
|
state.openEndedQuestions = questions
|
||||||
},
|
},
|
||||||
@@ -95,19 +117,6 @@ export const mutations = {
|
|||||||
|
|
||||||
state.openEndedQuestions[index].updateDifficultyLevel()
|
state.openEndedQuestions[index].updateDifficultyLevel()
|
||||||
}
|
}
|
||||||
},
|
|
||||||
addGameInProgress (state, { courseID, gameID }) {
|
|
||||||
const index = state.user.gamesStarted.findIndex(e => e.course === courseID)
|
|
||||||
if (index !== -1) {
|
|
||||||
state.user.gamesStarted[index].course = courseID
|
|
||||||
state.user.gamesStarted[index].game = gameID
|
|
||||||
} else {
|
|
||||||
state.user.gamesStarted.push({ course: courseID, game: gameID })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
removeGameInProgress (state, courseID) {
|
|
||||||
const index = state.user.gamesStarted.findIndex(e => e.course === courseID)
|
|
||||||
state.user.gamesStarted.splice(index, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user