diff --git a/apps/dashboard/src/routes/api/courses/exercises/+server.ts b/apps/dashboard/src/routes/api/courses/exercises/+server.ts index 8a7134e3..bce9f3a1 100644 --- a/apps/dashboard/src/routes/api/courses/exercises/+server.ts +++ b/apps/dashboard/src/routes/api/courses/exercises/+server.ts @@ -49,16 +49,9 @@ export const POST: RequestHandler = async ({ request }) => { throw new Error('Error fetching exercises'); } - const formattedExercises = exercises.map((exercise) => ({ - lesson_id: exercise.lesson_id, - exercise_id: exercise.id, - exercise_title: exercise.title, - points: exercise.points - })); - return json({ success: true, - data: formattedExercises + data: exercises }); } catch (error) { const message = error instanceof Error ? error.message : 'Internal server error'; diff --git a/apps/dashboard/src/routes/courses/[id]/marks/+page.svelte b/apps/dashboard/src/routes/courses/[id]/marks/+page.svelte index f391dbc3..b0d9c243 100644 --- a/apps/dashboard/src/routes/courses/[id]/marks/+page.svelte +++ b/apps/dashboard/src/routes/courses/[id]/marks/+page.svelte @@ -18,7 +18,12 @@ import { profile } from '$lib/utils/store/user'; import type { GroupPerson } from '$lib/utils/types'; import type { CurrentOrg } from '$lib/utils/types/org'; - import { Loading, OverflowMenu, OverflowMenuItem } from 'carbon-components-svelte'; + import { + Loading, + OverflowMenu, + OverflowMenuItem, + SkeletonPlaceholder + } from 'carbon-components-svelte'; import AudioConsoleIcon from 'carbon-icons-svelte/lib/AudioConsole.svelte'; import Download from 'carbon-icons-svelte/lib/Download.svelte'; import jsPDF from 'jspdf'; @@ -33,6 +38,7 @@ let lessonMapping = {}; // { lessonId: { exerciseId: exerciseTitle, ... }, ... } let studentMarksByExerciseId = {}; // { groupMemberId: { exerciseId: `total_gotten/points`, ... }, ... } let isDownloading = false; + let isLoading = false; function calculateStudentTotal(studentExerciseData) { if (!studentExerciseData) return 0; @@ -44,14 +50,19 @@ } async function firstRender(courseId: string) { + isLoading = true; const { data: marks, error } = await fetchMarks(courseId); if (error) { + isLoading = false; console.error('Error fetching marks', error); snackbar.error('snackbar.marks.error'); return; } - if (!marks || !Array.isArray(marks)) return; + if (!marks || !Array.isArray(marks)) { + isLoading = false; + return; + } marks.forEach((mark) => { const { groupmember_id, exercise_id, total_points_gotten } = mark; @@ -85,6 +96,8 @@ }; } }); + + isLoading = false; } // TODO WRITE A REDIRECT FUNCTION FOR THIS THIS PAGE @@ -238,86 +251,95 @@ -
-
-
-

{$t('course.navItem.marks.student')}

-
- {#each $lessons as lesson, index} - {#if lessonMapping[lesson.id]} -
-

- {getLectureNo(index + 1)} -

-
- {#each Object.keys(lessonMapping[lesson.id]) as exerciseId, index} -

- {lessonMapping[lesson.id][exerciseId].title} - ({lessonMapping[lesson.id][exerciseId].points}) -

- {/each} -
-
- {/if} - {/each} -
-

{$t('course.navItem.marks.total')}

-
+ {#if isLoading} +
+ + + +
- - {#each students as student} -
-
- Student avatar -
-

- {student.profile.fullname} -

-

- {`${student.assigned_student_id ? '#' + student.assigned_student_id : '-'}`} -

-
+ {:else} +
+
+
+

{$t('course.navItem.marks.student')}

- {#each $lessons as lesson} + {#each $lessons as lesson, index} {#if lessonMapping[lesson.id]} -
- {#each Object.keys(lessonMapping[lesson.id]) as exerciseId} -

- {studentMarksByExerciseId[student.id] - ? studentMarksByExerciseId[student.id][exerciseId] || '-' - : '-'} -

- {/each} +
+

+ {getLectureNo(index + 1)} +

+
+ {#each Object.keys(lessonMapping[lesson.id]) as exerciseId, index} +

+ {lessonMapping[lesson.id][exerciseId].title} + ({lessonMapping[lesson.id][exerciseId].points}) +

+ {/each} +
{/if} {/each} - -
-
-

- {calculateStudentTotal(studentMarksByExerciseId[student.id])} -

-
+
+

{$t('course.navItem.marks.total')}

- {:else} - - -

- {$t('course.navItem.marks.no_student')} -

-
- {/each} -
+ + {#each students as student} +
+
+ Student avatar +
+

+ {student.profile.fullname} +

+

+ {`${student.assigned_student_id ? '#' + student.assigned_student_id : '-'}`} +

+
+
+ {#each $lessons as lesson} + {#if lessonMapping[lesson.id]} +
+ {#each Object.keys(lessonMapping[lesson.id]) as exerciseId} +

+ {studentMarksByExerciseId[student.id] + ? studentMarksByExerciseId[student.id][exerciseId] || '-' + : '-'} +

+ {/each} +
+ {/if} + {/each} + +
+
+

+ {calculateStudentTotal(studentMarksByExerciseId[student.id])} +

+
+
+
+ {:else} + + +

+ {$t('course.navItem.marks.no_student')} +

+
+ {/each} +
+ {/if}