2023-09-29 09:25:32 +01:00
|
|
|
<script lang="ts">
|
2023-08-15 14:28:51 +00:00
|
|
|
import { goto } from '$app/navigation';
|
2026-04-27 11:40:38 +01:00
|
|
|
import { Badge } from '@cio/ui/base/badge';
|
2025-12-22 02:36:48 +01:00
|
|
|
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';
|
2025-12-02 09:54:38 +01:00
|
|
|
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';
|
2023-08-10 12:23:10 +00:00
|
|
|
|
2023-09-29 09:25:32 +01:00
|
|
|
const gotoCourse = (id: string | undefined) => {
|
|
|
|
|
if (!id) return;
|
2024-04-16 08:51:53 +01:00
|
|
|
goto(`/courses/${id}/lessons?next=true`);
|
2023-08-15 14:28:51 +00:00
|
|
|
};
|
2024-05-21 00:14:47 +01:00
|
|
|
|
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
|
|
|
}
|
2023-08-10 12:23:10 +00:00
|
|
|
</script>
|
|
|
|
|
|
2023-09-30 09:56:42 +01:00
|
|
|
<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>
|
2023-08-15 14:28:51 +00:00
|
|
|
<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"
|
2023-08-11 17:11:19 +00:00
|
|
|
>
|
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}
|
2023-08-10 12:23:10 +00:00
|
|
|
<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">
|
2023-09-29 09:25:32 +01:00
|
|
|
<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]"
|
2023-09-29 09:25:32 +01:00
|
|
|
/>
|
2023-08-10 12:23:10 +00:00
|
|
|
<div class="w-full">
|
2023-09-29 09:25:32 +01:00
|
|
|
<p class="text-base font-semibold dark:text-white">{course.title}</p>
|
2023-08-15 14:28:51 +00:00
|
|
|
<p class="line-clamp-2 text-xs font-normal text-[#656565] dark:text-white">
|
2023-09-29 09:25:32 +01:00
|
|
|
{course.description}
|
2023-08-15 14:28:51 +00:00
|
|
|
</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}
|
2023-08-10 12:23:10 +00:00
|
|
|
</div>
|
2025-12-22 02:36:48 +01:00
|
|
|
<Button variant="outline" onclick={() => gotoCourse(course.id)}>
|
|
|
|
|
{$t('dashboard.continue')}
|
|
|
|
|
</Button>
|
2023-08-10 12:23:10 +00:00
|
|
|
</span>
|
2026-04-27 11:40:38 +01:00
|
|
|
<Progress value={getStudentCourseProgressPercent(course)} max={100} class="ui:h-1" />
|
2023-08-10 12:23:10 +00:00
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2023-08-15 14:28:51 +00:00
|
|
|
{:else}
|
2025-12-02 09:54:38 +01:00
|
|
|
<Empty title={$t('dashboard.no_courses')} description={$t('dashboard.start_course')} icon={BookOpenIcon} />
|
2023-08-10 12:23:10 +00:00
|
|
|
{/if}
|
2023-08-15 14:28:51 +00:00
|
|
|
</div>
|
2023-08-10 12:23:10 +00:00
|
|
|
</section>
|