From 94996879216337d440a377653b4f8b1fc27f919b Mon Sep 17 00:00:00 2001 From: Jacob Pierce Date: Thu, 25 Jul 2024 13:55:40 -0700 Subject: [PATCH] fix handleConfirmDelete issues in SectionEditor --- .../plan/CreateExamPage/SectionEditor.vue | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionEditor.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionEditor.vue index a299316cff4..d8f3e30a407 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionEditor.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/SectionEditor.vue @@ -138,6 +138,8 @@ mixins: [commonCoreStrings], setup(_, context) { const router = getCurrentInstance().proxy.$router; + const store = getCurrentInstance().proxy.$store; + const route = computed(() => store.state.route); const { sectionSettings$, @@ -193,17 +195,17 @@ function handleConfirmDelete() { const section_title = displaySectionTitle(activeSection.value, activeSectionIndex.value); - const newIndex = this.activeSectionIndex > 0 ? this.activeSectionIndex - 1 : 0; + const newIndex = activeSectionIndex.value > 0 ? activeSectionIndex.value - 1 : 0; removeSection(activeSectionIndex.value); router.replace({ name: PageNames.EXAM_CREATION_ROOT, params: { - classId: this.$route.params.classId, - quizId: this.$route.params.quizId, + classId: route.value.params.classId, + quizId: route.value.params.quizId, sectionIndex: newIndex, }, }); - this.$store.dispatch('createSnackbar', sectionDeletedNotification$({ section_title })); + store.dispatch('createSnackbar', sectionDeletedNotification$({ section_title })); } function handleDeleteSection() { @@ -334,17 +336,16 @@ }, }, beforeRouteLeave(to, __, next) { - if (this.formDataHasChanged) { - if (!this.showCloseConfirmation && !this.showDeleteConfirmation) { - this.applySettings(to.name); + if (this.formDataHasChanged && !this.showDeleteConfirmation) { + if (this.showCloseConfirmation) { + // The user should be confirming losing changes next(false); } else { - this.showCloseConfirmation = true; - next(false); + // The user needs to confirm they want to leave + return (this.showCloseConfirmation = true); } - } else { - next(); } + next(); }, methods: { applySettings(nextRouteName = PageNames.EXAM_CREATION_ROOT) {