From afe7df2989f50b439ea69b9d1bf498ce0a9f6b77 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 5 Aug 2024 16:29:43 +0530 Subject: [PATCH] fix: fetch question --- frontend/src/components/Modals/Question.vue | 49 +++++++-------------- frontend/src/pages/QuizCreation.vue | 30 +++++++++++-- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/frontend/src/components/Modals/Question.vue b/frontend/src/components/Modals/Question.vue index 74e14f13..2a7966c1 100644 --- a/frontend/src/components/Modals/Question.vue +++ b/frontend/src/components/Modals/Question.vue @@ -113,23 +113,12 @@ const existingQuestion = reactive({ question: '', marks: 0, }) - const question = reactive({ question: '', type: 'Choices', marks: 0, }) -const props = defineProps({ - title: { - type: String, - default: __('Add a new question'), - }, - questionName: { - type: String, - }, -}) - const populateFields = () => { let fields = ['option', 'is_correct', 'explanation', 'possibility'] let counter = 1 @@ -141,17 +130,22 @@ const populateFields = () => { }) } -const questionData = createResource({ - url: 'frappe.client.get', - makeParams(values) { - return { - doctype: 'LMS Question', - name: props.questionName, - } +populateFields() + +const props = defineProps({ + title: { + type: String, + default: __('Add a new question'), }, - auto: false, - cache: ['question', props.questionName], - onSuccess(data) { + questionData: { + type: [Object, null], + required: true, + }, +}) + +watch(show, () => { + let data = props.questionData + if (show.value && data) { let counter = 1 Object.keys(data).forEach((key) => { if (Object.hasOwn(question, key)) question[key] = data[key] @@ -161,7 +155,7 @@ const questionData = createResource({ ? true : false } - }, + } }) const questionRow = createResource({ @@ -247,17 +241,6 @@ const addQuestionRow = (question, close) => { ) } -watch( - () => props.questionName, - async (name) => { - console.log('name', name) - populateFields() - if (name != 'new') { - questionData.reload() - } - } -) - const dialogOptions = computed(() => { return { title: __(props.title), diff --git a/frontend/src/pages/QuizCreation.vue b/frontend/src/pages/QuizCreation.vue index 90f6fdcb..3c96bb5a 100644 --- a/frontend/src/pages/QuizCreation.vue +++ b/frontend/src/pages/QuizCreation.vue @@ -123,7 +123,7 @@