diff --git a/src/routes/[course]/+page.svelte b/src/routes/[course]/+page.svelte index ba05efc..425c57c 100644 --- a/src/routes/[course]/+page.svelte +++ b/src/routes/[course]/+page.svelte @@ -2,16 +2,16 @@ import { page } from '$app/state'; import { Button } from 'bits-ui'; import CoursePie from '$lib/components/CoursePie.svelte'; - import { getCourseStatistic, type DataCourseStatistic } from 'liu-tentor-package'; + import type { DataCourseStatistic } from 'liu-tentor-package'; import { locale, getTranslation } from '$lib/i18n'; import type { Locale } from '$lib/i18n/translations'; import type { LanguageContent } from 'liu-tentor-package'; + import type { PageData } from './$types'; + + let { data }: { data: PageData } = $props(); let course = page.params.course; - - let loading = $state(true); - let error: null | Error = $state(null); - let courseStats: DataCourseStatistic = $state({} as DataCourseStatistic); + let courseStats: DataCourseStatistic = $derived(data.courseStats ?? ({} as DataCourseStatistic)); let currentPage = $state(0); let selectedModuleCode = $state(undefined); let currentLocale = $state('en'); @@ -19,20 +19,6 @@ locale.subscribe((l) => (currentLocale = l)); - $effect(() => { - getCourseStats(); - }); - - async function getCourseStats() { - if (!course) { - error = new Error('Course not found'); - loading = false; - return; - } - courseStats = (await getCourseStatistic(course)) ?? ({} as DataCourseStatistic); - loading = false; - } - function next() { currentPage++; } @@ -68,11 +54,7 @@

{getLocalizedTitle(courseStats.courseTitle)}

-{#if loading} -

{getTranslation('loading', currentLocale)}

-{:else if error} -

{error.message}

-{:else if courseStats?.modules} +{#if courseStats?.modules}