Skip to content

Instantly share code, notes, and snippets.

@Jpoliachik
Created January 9, 2024 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jpoliachik/31f2594feb4e3edfb9553fbf2ac8536b to your computer and use it in GitHub Desktop.
Save Jpoliachik/31f2594feb4e3edfb9553fbf2ac8536b to your computer and use it in GitHub Desktop.
Question.ts updated
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