From a9b12de7262c204e7a215007a865f00900366dfd Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Fri, 3 May 2024 12:29:17 -0500 Subject: [PATCH] Internal: Refactor: Move course ID watcher to router and manage course settings cleanup - refs BT#21576 --- assets/vue/composables/locale.js | 8 -------- assets/vue/router/index.js | 4 ++++ assets/vue/store/courseSettingStore.js | 15 +++++++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/assets/vue/composables/locale.js b/assets/vue/composables/locale.js index eeac7de4db..cf616391a3 100644 --- a/assets/vue/composables/locale.js +++ b/assets/vue/composables/locale.js @@ -12,14 +12,6 @@ export function useLocale() { const appLocale = ref(document.querySelector('html').lang) - watch(() => { - return cidReqStore.course ? cidReqStore.course.id : null - }, (newId, oldId) => { - if (newId) { - courseSettingsStore.loadCourseSettings(newId) - } - }, { immediate: true }) - const localeList = computed(() => { const list = {} list['platform_lang'] = platformConfigStore.getSetting('language.platform_language') diff --git a/assets/vue/router/index.js b/assets/vue/router/index.js index 50d8686436..8db10aa8af 100644 --- a/assets/vue/router/index.js +++ b/assets/vue/router/index.js @@ -21,6 +21,7 @@ import assignments from "./assignments" import links from "./links" import glossary from "./glossary" import { useSecurityStore } from "../store/securityStore" +import { useCourseSettings } from "../store/courseSettingStore" import MyCourseList from "../views/user/courses/List.vue" import MySessionList from "../views/user/sessions/SessionsCurrent.vue" import MySessionListPast from "../views/user/sessions/SessionsPast.vue" @@ -190,6 +191,7 @@ router.beforeEach((to, from, next) => { router.beforeResolve(async (to) => { const cidReqStore = useCidReqStore() + const courseSettingsStore = useCourseSettings() let cid = parseInt(to.query?.cid ?? 0) const sid = parseInt(to.query?.sid ?? 0) @@ -200,8 +202,10 @@ router.beforeResolve(async (to) => { if (cid) { await cidReqStore.setCourseAndSessionById(cid, sid) + await courseSettingsStore.loadCourseSettings(cid) } else { cidReqStore.resetCid() + courseSettingsStore.resetCourseSettings() } }) diff --git a/assets/vue/store/courseSettingStore.js b/assets/vue/store/courseSettingStore.js index fbbcbdc690..1d7d46b5b1 100644 --- a/assets/vue/store/courseSettingStore.js +++ b/assets/vue/store/courseSettingStore.js @@ -1,6 +1,6 @@ import { defineStore } from "pinia" import axios from "axios" -import { computed, ref } from "vue" +import { ref } from "vue" export const useCourseSettings = defineStore("courseSettings", () => { const isLoading = ref(false) @@ -18,14 +18,17 @@ export const useCourseSettings = defineStore("courseSettings", () => { } } - const getSetting = computed(() => { - return (variable) => settings.value[variable] || null - }); + function resetCourseSettings() { + settings.value = {} + } + + const getSetting = (variable) => settings.value[variable] || null return { isLoading, settings, loadCourseSettings, + resetCourseSettings, getSetting - } -}) + }; +});