diff --git a/client/src/components/MainNavigationBar.vue b/client/src/components/MainNavigationBar.vue index a67918ed..51b3ac17 100644 --- a/client/src/components/MainNavigationBar.vue +++ b/client/src/components/MainNavigationBar.vue @@ -63,7 +63,9 @@ function logout() { onMounted(() => { log.debug("MainNavigationBar mounted"); - courseSessionsStore.loadCourseSessionsData(); + if (userStore.loggedIn) { + courseSessionsStore.loadCourseSessionsData(); + } }); const profileDropdownData: DropdownListItem[] = [ diff --git a/client/src/components/learningPath/LearningPathDiagramSmall.vue b/client/src/components/learningPath/LearningPathDiagramSmall.vue index b53aec77..9680f8be 100644 --- a/client/src/components/learningPath/LearningPathDiagramSmall.vue +++ b/client/src/components/learningPath/LearningPathDiagramSmall.vue @@ -17,7 +17,7 @@ const learningPathData = ref(undefined); const learningPathStore = useLearningPathStore(); learningPathStore - .loadLearningPath(props.learningPathUrl.replace("/learn/", "")) + .loadLearningPath(props.learningPathUrl.replace("/learn/", ""), false, false) .then((data) => { learningPathData.value = data; }); diff --git a/client/src/stores/learningPath.ts b/client/src/stores/learningPath.ts index 5ecbba19..f836469e 100644 --- a/client/src/stores/learningPath.ts +++ b/client/src/stores/learningPath.ts @@ -22,7 +22,7 @@ export const useLearningPathStore = defineStore({ }, getters: {}, actions: { - async loadLearningPath(slug: string, reload = false) { + async loadLearningPath(slug: string, reload = false, fail = true) { this.loading = true; const completionStore = useCompletionStore(); if (this.learningPath && !reload && slug === lastSlug) { @@ -30,18 +30,21 @@ export const useLearningPathStore = defineStore({ } this.learningPath = undefined; const learningPathData = await itGetCached(`/api/course/page/${slug}/`); - lastSlug = slug; - const completionData = await completionStore.loadCompletionData( - learningPathData.course.id - ); - if (!learningPathData) { + if (!learningPathData && fail) { throw `No learning path found with: ${slug}`; } - this.learningPath = LearningPath.fromJson(learningPathData, completionData); - this.loading = false; - return this.learningPath; + if (learningPathData) { + lastSlug = slug; + const completionData = await completionStore.loadCompletionData( + learningPathData.course.id + ); + + this.learningPath = LearningPath.fromJson(learningPathData, completionData); + this.loading = false; + return this.learningPath; + } }, }, }); diff --git a/client/src/stores/user.ts b/client/src/stores/user.ts index fef704bb..bdf82349 100644 --- a/client/src/stores/user.ts +++ b/client/src/stores/user.ts @@ -2,6 +2,7 @@ import * as log from "loglevel"; import { bustItGetCache, itGetCached, itPost } from "@/fetchHelpers"; import { useAppStore } from "@/stores/app"; +import { useCourseSessionsStore } from "@/stores/courseSessions"; import { defineStore } from "pinia"; const logoutRedirectUrl = import.meta.env.VITE_LOGOUT_REDIRECT; @@ -75,6 +76,8 @@ export const useUserStore = defineStore({ this.$state = data; this.loggedIn = true; appStore.userLoaded = true; + const courseSessionsStore = useCourseSessionsStore(); + courseSessionsStore.loadCourseSessionsData(); }) .catch(() => { this.loggedIn = false;