Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EQM: What happens when I refresh? #12393

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@
}

/* Note that the use of snake_case here is to map directly to the API */
const learners_see_fixed_order = ref(activeSection.value.learners_see_fixed_order);
const description = ref(activeSection.value.description);
const section_title = ref(activeSection.value.section_title.trim());
const learners_see_fixed_order = ref(activeSection?.value?.learners_see_fixed_order || false);
const description = ref(activeSection?.value?.description || '');
const section_title = ref(activeSection?.value?.section_title?.trim() || '');

const sectionTitleInvalidText = computed(() => {
if (section_title.value.trim() === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,15 @@
setup() {
const closeConfirmationToRoute = ref(null);
const { classId, groups } = useCoreCoach();
const { quizHasChanged, quiz, updateQuiz, saveQuiz, initializeQuiz, allSectionsEmpty } =
useQuizCreation();
const {
quizHasChanged,
quiz,
updateQuiz,
saveQuiz,
initializeQuiz,
allSectionsEmpty,
allSections,
} = useQuizCreation();
const showError = ref(false);
const quizInitialized = ref(false);

Expand Down Expand Up @@ -162,6 +169,7 @@
updateQuiz,
initializeQuiz,
quizInitialized,
allSections,
allSectionsEmpty,
allSectionsEmptyWarning$,
saveAndClose$,
Expand Down Expand Up @@ -219,6 +227,35 @@
});
},
},
beforeRouteEnter(to, from, next) {
// If we're coming from no quizId and going to replace questions, redirect to exam creation
// then we're coming from another page altogether OR we're coming back from a refresh
if (!from.params?.quizId && to.name === PageNames.QUIZ_REPLACE_QUESTIONS) {
next({
name: PageNames.EXAM_CREATION_ROOT,
params: {
classId: to.params.classId,
quizId: to.params.quizId,
},
});
} else {
next();
}
},
beforeRouteUpdate(to, from, next) {
if (to.params.sectionIndex >= this.allSections.length) {
next({
name: PageNames.EXAM_CREATION_ROOT,
params: {
classId: to.params.classId,
quizId: to.params.quizId,
sectionIndex: '0',
},
});
} else {
next();
}
},
beforeRouteLeave(to, from, next) {
if (this.quizHasChanged && !this.closeConfirmationToRoute) {
this.closeConfirmationToRoute = to;
Expand All @@ -231,10 +268,31 @@
this.$store.dispatch('notLoading');
},
async created() {
window.addEventListener('beforeunload', this.beforeUnload);
await this.initializeQuiz(this.$route.params.classId, this.$route.params.quizId);
// If the section index doesn't exist, redirect to the first section; we also do this in
// beforeRouteUpdate. We do this here to avoid fully initializing the quiz if we're going to
// redirect anyway.
if (this.$route.params.sectionIndex >= this.allSections.length) {
this.$router.replace({
name: PageNames.EXAM_CREATION_ROOT,
params: {
classId: this.$route.params.classId,
quizId: this.$route.params.quizId,
sectionIndex: '0',
},
});
}
this.quizInitialized = true;
},
methods: {
beforeUnload(e) {
if (this.quizHasChanged) {
if (!window.confirm(this.closeConfirmationTitle$())) {
e.preventDefault();
}
}
},
saveQuizAndRedirect(close = true) {
this.saveQuiz()
.then(exam => {
Expand Down