Files
classroomio/apps/dashboard/src/lib/features/lms/components/learning.svelte
T

107 lines
4.0 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { goto } from '$app/navigation';
2026-04-27 11:40:38 +01:00
import { Badge } from '@cio/ui/base/badge';
import { Button } from '@cio/ui/base/button';
2026-03-09 11:18:22 +01:00
import { Progress } from '@cio/ui/base/progress';
2024-04-19 05:45:48 +01:00
import { t } from '$lib/utils/functions/translations';
import { Empty } from '@cio/ui/custom/empty';
import BookOpenIcon from '@lucide/svelte/icons/book-open';
2026-03-09 11:18:22 +01:00
import { coursesApi } from '$features/course/api';
2026-04-27 11:40:38 +01:00
import {
getStudentCourseComplianceDate,
getStudentCourseComplianceStatusKey,
getStudentCourseComplianceStatusVariant,
getStudentCourseProgressPercent
} from '$features/course/utils/compliance-utils';
const gotoCourse = (id: string | undefined) => {
if (!id) return;
goto(`/courses/${id}/lessons?next=true`);
};
2026-04-27 11:40:38 +01:00
let highlightedCourses = $derived.by(() => {
const courses = [...coursesApi.enrolledCourses];
2026-03-09 11:18:22 +01:00
2026-04-27 11:40:38 +01:00
return courses
.sort((leftCourse, rightCourse) => {
const leftComplianceDate = getStudentCourseComplianceDate(leftCourse)?.value;
const rightComplianceDate = getStudentCourseComplianceDate(rightCourse)?.value;
const leftTimestamp = leftComplianceDate ? new Date(leftComplianceDate).getTime() : Number.POSITIVE_INFINITY;
const rightTimestamp = rightComplianceDate ? new Date(rightComplianceDate).getTime() : Number.POSITIVE_INFINITY;
return leftTimestamp - rightTimestamp;
})
.slice(0, 3);
});
function formatDate(value: string | null | undefined) {
if (!value) {
return '';
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return '';
}
return new Intl.DateTimeFormat('en-US', {
dateStyle: 'medium'
}).format(date);
2026-03-09 11:18:22 +01:00
}
</script>
<section class="h-full">
2025-11-01 15:49:29 +01:00
<p class="pb-3 text-base font-semibold text-[#040F2D] dark:text-white">
2024-04-19 05:45:48 +01:00
{$t('dashboard.current_lesson')}
</p>
<div
2025-11-01 15:49:29 +01:00
class="flex w-full flex-col items-center gap-2 rounded border border-[#EAEAEA] p-3 lg:h-[40vh] dark:bg-neutral-800"
>
2026-04-27 11:40:38 +01:00
{#if highlightedCourses.length > 0}
2025-11-01 15:49:29 +01:00
<div class="flex h-full w-full flex-col justify-start overflow-y-auto">
2026-04-27 11:40:38 +01:00
{#each highlightedCourses as course}
<div class="p-5">
2025-11-01 15:49:29 +01:00
<span class="flex flex-col items-start gap-3 pb-5 lg:flex-row">
<img
src={course.logo || '/images/classroomio-course-img-template.jpg'}
alt="course"
2025-11-01 15:49:29 +01:00
class="hidden lg:block lg:h-[60px] lg:w-[60px]"
/>
<div class="w-full">
<p class="text-base font-semibold dark:text-white">{course.title}</p>
<p class="line-clamp-2 text-xs font-normal text-[#656565] dark:text-white">
{course.description}
</p>
2026-04-27 11:40:38 +01:00
{#if course.type === 'COMPLIANCE'}
{@const complianceStatusKey = getStudentCourseComplianceStatusKey(course)}
{@const complianceDate = getStudentCourseComplianceDate(course)}
<div class="mt-2 flex flex-wrap items-center gap-2">
{#if complianceStatusKey}
<Badge variant={getStudentCourseComplianceStatusVariant(course)}>
{$t(complianceStatusKey)}
</Badge>
{/if}
{#if complianceDate?.value}
<p class="ui:text-muted-foreground text-xs dark:text-white">
{$t(complianceDate.labelKey)}: {formatDate(complianceDate.value)}
</p>
{/if}
</div>
{/if}
</div>
<Button variant="outline" onclick={() => gotoCourse(course.id)}>
{$t('dashboard.continue')}
</Button>
</span>
2026-04-27 11:40:38 +01:00
<Progress value={getStudentCourseProgressPercent(course)} max={100} class="ui:h-1" />
</div>
{/each}
</div>
{:else}
<Empty title={$t('dashboard.no_courses')} description={$t('dashboard.start_course')} icon={BookOpenIcon} />
{/if}
</div>
</section>