Files
classroomio/apps/dashboard/src/lib/components/Courses/index.svelte
T

61 lines
2.0 KiB
Svelte
Raw Normal View History

2023-09-27 04:23:45 +01:00
<script lang="ts">
2021-08-29 07:23:19 +03:00
import Box from '../Box/index.svelte';
import Card from './components/Card/index.svelte';
import CardLoader from './components/Card/Loader.svelte';
import CoursesEmptyIcon from '../Icons/CoursesEmptyIcon.svelte';
2023-09-27 04:23:45 +01:00
import { courseMetaDeta } from './store';
import type { Course } from '$lib/utils/types';
import { globalStore } from '$lib/utils/store/app';
2023-09-27 04:23:45 +01:00
export let courses: Course[] = [];
export let emptyTitle = 'No Courses Created';
export let emptyDescription =
'Share your knowledge with the world by creating engaging courses for your students.';
function calcProgressRate(progressRate?: number, totalLessons?: number): number {
if (!progressRate || !totalLessons) {
return 0;
}
return Math.round((progressRate / totalLessons) * 100);
}
2021-05-06 08:22:25 +03:00
</script>
<!-- <CopyCourseModal /> -->
2021-12-30 22:30:30 +02:00
2023-09-27 04:23:45 +01:00
<div class={`w-full ${$courseMetaDeta.isLoading || courses ? 'cards-container' : ''} my-4 mx-auto`}>
2021-12-30 22:30:30 +02:00
{#if $courseMetaDeta.isLoading}
<CardLoader />
<CardLoader />
<CardLoader />
2021-12-30 22:30:30 +02:00
{:else}
2023-09-27 04:23:45 +01:00
{#each courses as courseData}
{#key courseData.id}
<Card
showContextMenu
2023-09-27 04:23:45 +01:00
id={courseData.id}
bannerImage={courseData.logo || '/images/classroomio-course-img-template.jpg'}
title={courseData.title}
description={courseData.description}
isPublished={courseData.is_published}
cost={courseData.cost}
currency={courseData.currency}
totalLessons={courseData.total_lessons}
2023-12-07 09:37:12 +03:00
totalStudents={courseData.total_students}
isLMS={$globalStore.isOrgSite}
progressRate={calcProgressRate(courseData.progress_rate, courseData.total_lessons)}
2023-09-27 04:23:45 +01:00
/>
{/key}
2021-12-30 22:30:30 +02:00
{/each}
{/if}
2021-05-07 03:43:37 +03:00
</div>
2023-09-27 04:23:45 +01:00
{#if !$courseMetaDeta.isLoading && !courses.length}
<Box className="w-full">
<CoursesEmptyIcon />
<h3 class="dark:text-white text-2xl my-5">{emptyTitle}</h3>
<p class="dark:text-white w-1/3 text-center">
{emptyDescription}
</p>
</Box>
{/if}