Internal: Refactor: Move course ID watcher to router and manage course settings cleanup - refs BT#21576

pull/5468/head
christianbeeznst 1 year ago
parent 46d5963ea1
commit a9b12de726
  1. 8
      assets/vue/composables/locale.js
  2. 4
      assets/vue/router/index.js
  3. 15
      assets/vue/store/courseSettingStore.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')

@ -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()
}
})

@ -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
}
})
};
});

Loading…
Cancel
Save