Created
January 9, 2024 17:01
-
-
Save Jpoliachik/31f2594feb4e3edfb9553fbf2ac8536b to your computer and use it in GitHub Desktop.
Question.ts updated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shuffle from "lodash.shuffle" | |
export const QuestionModel = types | |
.model("Question") | |
.props({ | |
id: types.identifier, | |
category: types.maybe(types.string), | |
type: types.enumeration(["multiple", "boolean"]), | |
difficulty: types.enumeration(["easy", "medium", "hard"]), | |
question: types.maybe(types.string), | |
correctAnswer: types.maybe(types.string), | |
incorrectAnswers: types.optional(types.array(types.string), []), | |
guess: types.maybe(types.string), | |
}) | |
.actions(withSetPropAction) | |
.views((self) => ({ | |
get allAnswers() { | |
return shuffle([ | |
...self.incorrectAnswers, | |
...(self.correctAnswer ? [self.correctAnswer] : []), | |
]) | |
}, | |
get isCorrect() { | |
return self.guess === self.correctAnswer | |
}, | |
})) | |
.actions((self) => ({ | |
setGuess(guess: string) { | |
self.setProp("guess", guess) | |
}, | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment