Skip to content

Commit

Permalink
feat(quiz): not show feedback during quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
ManhLinhVu-ext54629 committed Dec 6, 2024
1 parent 3d3dc3d commit 238ece8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
16 changes: 2 additions & 14 deletions frontend/src/components/question/QuestionFormV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import type { QuizQuestionProps } from '../../model/quiz-question.ts'
export const QuestionFormV2 = (props: QuizQuestionProps) => {
const [selectedAnswer, setSelectedAnswer] = createSignal<number | null>(null)
const [selectedAnswers, setSelectedAnswers] = createSignal<{ [key: string]: boolean } | Record<string, boolean>>({})
const [isAnswerCorrect] = createSignal(false)
const [explanationIdx, setExplanationIdx] = createSignal<number | null>(null)
const [answersRequiringFeedback] = createSignal<number[]>([])

const [submitted, setSubmitted] = createSignal(false)

Expand All @@ -28,7 +25,6 @@ export const QuestionFormV2 = (props: QuizQuestionProps) => {
QuestionService.setAnswer(props.quizRunId, props.id, [selectedAnswerIdx])
.then(() => {
setSubmitted(true)
setExplanationIdx(selectedAnswerIdx)
})
.then(() => props.onSuccessfulSubmit())
})
Expand Down Expand Up @@ -98,14 +94,7 @@ export const QuestionFormV2 = (props: QuizQuestionProps) => {
return (
<li>
<input type={'radio'} name={'answer'} id={answerId} value={answer} onClick={selectAnswer(idx)} />
<label for={answerId}>
{answer}
<Show
when={explanationIdx() === idx}
children={Explanation(isAnswerCorrect, explanation, () => true)}
keyed
/>
</label>
<label for={answerId}>{answer}</label>
</li>
)
}
Expand All @@ -116,13 +105,12 @@ export const QuestionFormV2 = (props: QuizQuestionProps) => {
<ul>
<For each={props.answers}>
{(answer, idx) => {
const isFeedbackRequired = createMemo(() => answersRequiringFeedback().some(id => id === idx()))
return (
<Answer
answer={answer}
idx={idx()}
explanation={props.explanations ? props.explanations[idx()] : 'not defined'}
isFeedbackRequired={isFeedbackRequired}
isFeedbackRequired={createMemo(() => false)}
/>
)
}}
Expand Down
23 changes: 7 additions & 16 deletions frontend/src/pages/QuizQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ export const QuizQuestionDetail = () => {
const [question, setQuestion] = createSignal<QuizQuestion | null>(null)
const [formProps, setFormProps] = createSignal<QuizQuestionProps | null>(null)

// TODO resolve page rerender
// const location = useLocation()
// const [urlQuestionId, setUrlQuestionId] = createSignal<string | null>(null)
// setUrlQuestionId(questionId)
/*createEffect(async () => {
if (location.pathname) console.log('current URL', location.pathname)
const currQuestionId = urlQuestionId()
if (currQuestionId) {
setQuestion(await getQuestion(currQuestionId))
}
})*/

onMount(async () => setQuiz(await getQuizMaster(quizId)))
onMount(async () => setQuestion(await getQuestion(questionId)))

Expand All @@ -42,19 +29,23 @@ export const QuizQuestionDetail = () => {
const isFinalQuestion = currentQuestionIdx + 1 === quiz()?.questions?.length

if (isFinalQuestion) {
console.log('IS FINAL QUESTION')
navigate(`/quiz/${quizId}/run/${quizRunId}/result`)
} else {
const nextQuestionIdx = currentQuestionIdx > -1 ? currentQuestionIdx + 1 : -1
nextQuestionIdx > -1 &&
console.log('NEXT QUESTION IDX: ', nextQuestionIdx)
console.log('QUESTION', quiz()?.questions)
if (nextQuestionIdx > -1) {
navigate(`/quiz/${quizId}/run/${quizRunId}/question/${quiz()?.questions[nextQuestionIdx].id}`)
setTimeout(() => window.location.reload())
setTimeout(() => window.location.reload())
}
}
}
}

createEffect(() => {
if (question()) {
// @ts-ignore
// @ts-ignore TODO fix eslint
setFormProps({
...question(),
quizId,
Expand Down

0 comments on commit 238ece8

Please sign in to comment.