import { defineStore } from 'pinia' import { itGet } from '@/fetchHelpers' import { LearningPath } from '@/services/learningPath' export type LearningPathStoreState = { learningPath: LearningPath | undefined } export const useLearningPathStore = defineStore({ id: 'learningPath', state: () => { return { learningPath: undefined, } as LearningPathStoreState; }, getters: {}, actions: { async loadLearningPath(slug: string, reload = false) { if (this.learningPath && !reload) { return this.learningPath; } const learningPathData = await itGet(`/api/course/page/${slug}/`); const completionData = await itGet(`/api/completion/learning_path/${learningPathData.translation_key}/`); if (!learningPathData) { throw `No learning path found with: ${slug}`; } this.learningPath = LearningPath.fromJson(learningPathData, completionData); return this.learningPath; }, } })