Skip to content

Commit

Permalink
only load the quiz data once for quiz summary page
Browse files Browse the repository at this point in the history
  • Loading branch information
nucleogenesis committed Aug 26, 2024
1 parent af6a30f commit 2cf6724
Showing 1 changed file with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</p>

<QuestionListPreview
:sections="quiz.question_sources || []"
:sections="exam.question_sources || []"
:selectedExercises="selectedExercises"
/>
</section>
Expand All @@ -55,7 +55,7 @@
</KGrid>
<ManageExamModals
:currentAction="currentAction"
:quiz="quiz"
:quiz="exam"
@submit_delete="handleSubmitDelete"
@submit_copy="handleSubmitCopy"
@cancel="closeModal"
Expand All @@ -70,6 +70,7 @@
import { mapState } from 'vuex';
import fromPairs from 'lodash/fromPairs';
import find from 'lodash/find';
import { fetchExamWithContent } from 'kolibri.utils.exams';
import { ERROR_CONSTANTS } from 'kolibri.coreVue.vuex.constants';
import CatchErrors from 'kolibri.utils.CatchErrors';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
Expand All @@ -82,12 +83,7 @@
import { coachStringsMixin } from '../../common/commonCoachStrings';
import QuizOptionsDropdownMenu from './QuizOptionsDropdownMenu';
import ManageExamModals from './ManageExamModals';
import {
fetchQuizSummaryPageData,
serverAssignmentPayload,
clientAssigmentState,
deleteExam,
} from './api';
import { serverAssignmentPayload, clientAssigmentState, deleteExam } from './api';
export default {
name: 'QuizSummaryPage',
Expand All @@ -108,13 +104,6 @@
},
data() {
return {
quiz: {
active: false,
assignments: [],
learners_see_fixed_order: false,
question_sources: [],
title: '',
},
selectedExercises: {},
loading: true,
currentAction: '',
Expand All @@ -123,13 +112,13 @@
computed: {
...mapState(['classList']),
selectedQuestions() {
return this.quiz.question_sources.reduce((acc, section) => {
return this.exam.question_sources.reduce((acc, section) => {
acc = [...acc, ...section.questions];
return acc;
}, []);
},
quizIsRandomized() {
return !this.quiz.learners_see_fixed_order;
return !this.exam.learners_see_fixed_order;
},
avgScore() {
return this.getExamAvgScore(this.$route.params.quizId, this.recipients);
Expand All @@ -150,20 +139,19 @@
},
},
created() {
return fetchQuizSummaryPageData(this.$route.params.quizId)
fetchExamWithContent(this.exam)
.then(data => {
this.setData(data);
})
.catch(error => {
this.setError(error);
.catch(e => {
this.setError(e);
});
},
methods: {
// @public
setData(data) {
const { exam, exerciseContentNodes } = data;
this.quiz = exam;
this.selectedExercises = fromPairs(exerciseContentNodes.map(x => [x.id, x]));
const { exam, exercises } = data;
this.selectedExercises = fromPairs(exercises.map(x => [x.id, x]));
this.loading = false;
this.$store.dispatch('notLoading');
},
Expand Down Expand Up @@ -197,7 +185,7 @@
collection: classroomId,
assignments,
learner_ids: adHocLearnerIds,
question_sources: this.quiz.question_sources,
question_sources: this.exam.question_sources,
};
ExamResource.saveModel({ data: newQuiz })
Expand Down Expand Up @@ -242,7 +230,7 @@
handleSubmitDelete() {
return deleteExam(this.$route.params.quizId)
.then(() => {
this.$store.commit('classSummary/DELETE_ITEM', { map: 'examMap', id: this.quiz.id });
this.$store.commit('classSummary/DELETE_ITEM', { map: 'examMap', id: this.exam.id });
this.$router.replace(this.$router.getRoute('EXAMS'), () => {
this.showSnackbarNotification('quizDeleted');
});
Expand Down

0 comments on commit 2cf6724

Please sign in to comment.