chore: loading state to submission

This commit is contained in:
Rotimi Best
2024-08-03 23:18:58 +01:00
parent 30a6193e3c
commit 0961aad01a
@@ -3,6 +3,7 @@
import { dndzone } from 'svelte-dnd-action'; import { dndzone } from 'svelte-dnd-action';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { SkeletonPlaceholder } from 'carbon-components-svelte';
import PageNav from '$lib/components/PageNav/index.svelte'; import PageNav from '$lib/components/PageNav/index.svelte';
import RoleBasedSecurity from '$lib/components/RoleBasedSecurity/index.svelte'; import RoleBasedSecurity from '$lib/components/RoleBasedSecurity/index.svelte';
import MarkExerciseModal from '$lib/components/Course/components/Lesson/Exercise/MarkExerciseModal.svelte'; import MarkExerciseModal from '$lib/components/Course/components/Lesson/Exercise/MarkExerciseModal.svelte';
@@ -45,6 +46,7 @@
let submissionId: string; let submissionId: string;
let openExercise = false; let openExercise = false;
let isGradeWithAI = false; let isGradeWithAI = false;
let fetching = false;
const submissionStatus: { [key: number]: string } = { const submissionStatus: { [key: number]: string } = {
1: $t('course.navItem.submissions.submission_status.submitted'), 1: $t('course.navItem.submissions.submission_status.submitted'),
@@ -268,6 +270,7 @@
} }
async function firstRender(courseId: string) { async function firstRender(courseId: string) {
fetching = true;
const { data: submissions } = await fetchSubmissions(courseId); const { data: submissions } = await fetchSubmissions(courseId);
const sectionById: { [key: number]: SubmissionSection[] } = {}; const sectionById: { [key: number]: SubmissionSection[] } = {};
@@ -332,6 +335,7 @@
value: Array.isArray(sectionById[index + 1]) ? sectionById[index + 1].length : 0, value: Array.isArray(sectionById[index + 1]) ? sectionById[index + 1].length : 0,
items: Array.isArray(sectionById[index + 1]) ? sectionById[index + 1] : [] items: Array.isArray(sectionById[index + 1]) ? sectionById[index + 1] : []
})); }));
fetching = false;
} }
$: browser && $course.id && firstRender($course.id); $: browser && $course.id && firstRender($course.id);
@@ -367,63 +371,69 @@
<Chip value={items.length} className="bg-set dark:bg-neutral-800" /> <Chip value={items.length} className="bg-set dark:bg-neutral-800" />
<p class="dark:text-white ml-2 font-bold">{title}</p> <p class="dark:text-white ml-2 font-bold">{title}</p>
</div> </div>
<div {#if fetching}
class="content pr-2 overflow-y-auto mb-3" <SkeletonPlaceholder style="width: 100%; height: 170px;" class="rounded-md my-2" />
use:dndzone={{ <SkeletonPlaceholder style="width: 100%; height: 170px;" class="rounded-md my-2" />
items, <SkeletonPlaceholder style="width: 100%; height: 170px;" class="rounded-md my-2" />
flipDurationMs, {:else}
dropTargetStyle: { outline: 'blue' } <div
}} class="content pr-2 overflow-y-auto mb-3"
on:consider={handleDndConsiderCards(idx)} use:dndzone={{
on:finalize={handleDndFinalizeCards(idx)} items,
> flipDurationMs,
{#each items as item (item.id)} dropTargetStyle: { outline: 'blue' }
<div }}
class="{item.isEarly on:consider={handleDndConsiderCards(idx)}
? 'border-none' on:finalize={handleDndFinalizeCards(idx)}
: 'border border-red-700'} w-full my-2 mx-0 rounded-md bg-white dark:bg-neutral-800 py-3 px-3" >
animate:flip={{ duration: flipDurationMs }} {#each items as item (item.id)}
> <div
<a class="{item.isEarly
class="flex w-full items-center cursor-pointer text-black mb-2" ? 'border-none'
href={`${$page.url.pathname}?submissionId=${item.id}`} : 'border border-red-700'} w-full my-2 mx-0 rounded-md bg-white dark:bg-neutral-800 py-3 px-3"
animate:flip={{ duration: flipDurationMs }}
> >
<img <a
alt="Student avatar" class="flex w-full items-center cursor-pointer text-black mb-2"
class="block rounded-full h-6 w-6" href={`${$page.url.pathname}?submissionId=${item.id}`}
src={item.student.avatar_url} >
/> <img
<p class="dark:text-white ml-2 text-sm"> alt="Student avatar"
{item.student.username} class="block rounded-full h-6 w-6"
src={item.student.avatar_url}
/>
<p class="dark:text-white ml-2 text-sm">
{item.student.username}
</p>
</a>
<a
class="text-primary-700 text-md font-bold"
href="{$page.url.pathname}?submissionId={item.id}"
>
{item.exercise.title}
</a>
<a
class="flex items-center no-underline hover:underline text-black my-2"
href="{$page.url?.pathname?.replace('submissions', 'lessons')}/{item.lesson
.id}/exercises/{item.exercise.id}"
>
<p class="dark:text-white text-grey text-sm">
#{item.lesson.title}
</p>
</a>
<p class="dark:text-white text-gray-500 text-xs">
{item.submittedAt}
</p> </p>
</a> <!-- <div class="badge rounded-md px-2 bg-green-500 text-white">
<a
class="text-primary-700 text-md font-bold"
href="{$page.url.pathname}?submissionId={item.id}"
>
{item.exercise.title}
</a>
<a
class="flex items-center no-underline hover:underline text-black my-2"
href="{$page.url?.pathname?.replace('submissions', 'lessons')}/{item.lesson
.id}/exercises/{item.exercise.id}"
>
<p class="dark:text-white text-grey text-sm">
#{item.lesson.title}
</p>
</a>
<p class="dark:text-white text-gray-500 text-xs">
{item.submittedAt}
</p>
<!-- <div class="badge rounded-md px-2 bg-green-500 text-white">
early early
</div> </div>
<div class="badge rounded-md px-2 bg-red-600 text-white"> <div class="badge rounded-md px-2 bg-red-600 text-white">
late late
</div> --> </div> -->
</div> </div>
{/each} {/each}
</div> </div>
{/if}
</div> </div>
{/each} {/each}
</div> </div>