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

544 lines
18 KiB
Svelte
Raw Normal View History

<script lang="ts">
import get from 'lodash/get';
import { onMount, onDestroy } from 'svelte';
import pluralize from 'pluralize';
import { page } from '$app/stores';
import Notebook from 'carbon-icons-svelte/lib/Notebook.svelte'; //note
import PresentationFile from 'carbon-icons-svelte/lib/PresentationFile.svelte'; // exercise
import Video from 'carbon-icons-svelte/lib/Video.svelte'; //video
import PageNumber from 'carbon-icons-svelte/lib/PageNumber.svelte';
import PlayFilled from 'carbon-icons-svelte/lib/PlayFilled.svelte';
import PricingSection from './components/PricingSection.svelte';
2023-10-05 09:22:39 +00:00
import { observeIntersection } from './components/IntersectionObserver';
import { getLectureNo } from '../Course/function';
import { NAV_ITEMS } from './constants';
2023-07-31 17:20:04 +00:00
import Modal from '../Modal/index.svelte';
import { handleOpenWidget, reviewsModalStore } from './store';
2023-10-05 09:22:39 +00:00
import Chip from '../Chip/index.svelte';
import Avatar from '$lib/components/Avatar/index.svelte';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
import { getEmbedId } from '$lib/utils/functions/formatYoutubeVideo';
import type { Course, Lesson, Review } from '$lib/utils/types';
2023-08-02 19:44:28 +01:00
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
2023-09-24 12:24:28 +01:00
import HtmlRender from '$lib/components/HTMLRender/HTMLRender.svelte';
import { calDateDiff } from '$lib/utils/functions/date';
2023-11-09 04:20:45 +00:00
import { currentOrg } from '$lib/utils/store/org';
import UploadWidget from '$lib/components/UploadWidget/index.svelte';
import { course } from '$lib/components/Course/store';
2023-10-05 09:22:39 +00:00
export let editMode = false;
2023-09-15 08:26:26 +01:00
export let courseData: Course;
2023-07-31 17:20:04 +00:00
const ratingsImg = [
'/images/rating-1.svg',
'/images/rating-2.svg',
'/images/rating-3.svg',
'/images/rating-4.svg',
2023-08-05 04:44:32 +01:00
'/images/rating-5.svg'
2023-07-31 17:20:04 +00:00
];
let lessons: Array<Lesson> = [];
2023-07-31 17:20:04 +00:00
let reviews: Review[] = [];
let player: any;
2023-07-31 17:20:04 +00:00
let averageRating = 0;
let totalRatings = 0;
2023-09-15 08:26:26 +01:00
let startCoursePayment = false;
let isVisible = false;
let observer: { destroy: () => void };
2023-07-31 17:20:04 +00:00
// initialize the expandDescription array with 'false' values for each review.
let expandDescription = Array(reviews.length).fill(false);
let activeNav = NAV_ITEMS[0].key;
let instructor = {};
let video: string | undefined;
function playVideo() {
console.log('open modal with video');
}
function locationHashChanged() {
activeNav = window.location.hash;
}
function initPlyr(_player: any, _video: string | undefined) {
if (!player) return;
// @ts-ignore
const plyr = new Plyr('#player', {});
// @ts-ignore
window.player = plyr;
}
2023-07-31 17:20:04 +00:00
function toggleDescription(id: number) {
expandDescription[id] = !expandDescription[id];
}
onMount(() => {
window.onhashchange = locationHashChanged;
const targetNode = document.querySelector('.target-component');
observer = observeIntersection(targetNode, (inView: boolean) => {
isVisible = inView;
});
});
onDestroy(() => {
observer?.destroy();
});
$: video = get(courseData, 'metadata.videoUrl');
$: allowNewStudent = get(courseData, 'metadata.allowNewStudent');
$: bannerImage = get(courseData, 'logo');
$: lessons = get(courseData, 'lessons', []);
2023-12-04 19:39:39 +03:00
$: instructor = get(courseData, 'metadata.instructor') || {};
$: initPlyr(player, video);
2023-07-31 17:20:04 +00:00
$: {
reviews = get(courseData, 'metadata.reviews') || [];
2023-08-05 04:44:32 +01:00
totalRatings = reviews?.reduce((acc = 0, review) => acc + (review?.rating || 0), 0);
2023-07-31 17:20:04 +00:00
averageRating = totalRatings / reviews?.length;
}
2024-03-06 22:36:49 +01:00
$: {
let imgurl = get(instructor, 'imgUrl', $currentOrg.avatar_url);
console.log({ imgurl, instructor, org: $currentOrg });
}
</script>
2024-03-06 22:36:49 +01:00
<div class="flex w-full flex-col items-center bg-white dark:bg-black">
<!-- Header Section -->
2024-03-06 22:36:49 +01:00
<header id="header" class="banner p- flex w-full items-center justify-center">
<div class="flex w-full flex-col-reverse items-center justify-between md:w-5/6 md:flex-row">
<!-- Course Description -->
2024-03-06 22:36:49 +01:00
<div class="w-11/12 py-10 md:w-2/5">
<h1 class="my-4 text-5xl font-bold text-white dark:text-white">
{get(courseData, 'title', '')}
</h1>
2024-03-06 22:36:49 +01:00
<p class="text-md mb-6 text-white dark:text-white">
{get(courseData, 'description', '')}
</p>
2024-03-06 22:36:49 +01:00
<p class="author my-3 text-sm dark:text-white">
{get(courseData, 'metadata.instructor.name', '')}
</p>
2023-09-15 08:26:26 +01:00
<PrimaryButton
label="Start Course"
className="px-6 py-5 mt-6 sm:w-fit hidden md:block"
2023-09-15 08:26:26 +01:00
onClick={() => {
2023-10-30 04:52:00 +00:00
if (editMode) return;
2023-09-15 08:26:26 +01:00
startCoursePayment = true;
}}
isDisabled={!allowNewStudent}
2023-09-15 08:26:26 +01:00
/>
{#if $handleOpenWidget.open}
<UploadWidget bind:imageURL={$course.logo} />
{/if}
</div>
<!-- Banner Image getEmbedId(videoUrl) -->
{#if video}
2024-03-06 22:36:49 +01:00
<div class="banner-image flex w-full md:w-2/3">
<div
bind:this={player}
id="player"
data-plyr-provider="youtube"
data-plyr-embed-id={getEmbedId(video)}
/>
</div>
<!-- <div class="container">
<div
bind:this={player}
id="player"
class="banner-image w-2/3 h-96 relative"
data-plyr-provider="youtube"
data-plyr-embed-id="bTqVqk7FSmY"
/>
</div> -->
{:else}
2024-03-06 22:36:49 +01:00
<div class="banner-image relative overflow-hidden rounded-md md:w-2/3">
<img
style="min-width:280px; min-height:200px"
alt="About us"
src={bannerImage ? bannerImage : '/images/classroomio-course-img-template.jpg'}
2024-03-06 22:36:49 +01:00
class="relative mt-2 h-full max-h-[400px] w-full max-w-[500px] rounded-md md:mt-0"
/>
</div>
<!-- <div
class="banner-image w-2/3 h-96 relative cursor-pointer"
on:click={playVideo}
>
<div
aria-hidden="true"
class="absolute top-0 left-0 backdrop w-full h-full"
/>
<img
src="/images/course-banner-image.png"
alt="banner"
class="w-full h-full"
/>
<div
class="absolute top-0 left-0 w-full h-full z-50 flex items-center justify-center"
>
<img src="/images/play_video.png" alt="play video" />
</div>
</div> -->
{/if}
</div>
</header>
<!-- Body -->
2024-03-06 22:36:49 +01:00
<div class="w-full bg-white dark:bg-black">
<div
2024-03-06 22:36:49 +01:00
class="mx-0 my-2 flex w-full max-w-[1200px] flex-col-reverse items-center justify-between lg:m-auto lg:w-11/12 lg:flex-row lg:items-start lg:py-8"
>
<!-- Course Details -->
2024-03-06 22:36:49 +01:00
<div class="course-content w-full p-3 lg:mr-10 lg:w-10/12">
<!-- Navigation -->
<nav
2024-03-06 22:36:49 +01:00
class="sticky top-0 flex items-center border-b border-gray-300 py-3 {!editMode &&
'lg:top-11'} bg-white dark:bg-neutral-800"
>
{#each NAV_ITEMS as navItem}
<a
href="{$page.url.pathname}{navItem.key}"
class="{navItem.key === activeNav &&
2024-03-06 22:36:49 +01:00
'active text-primary-700'} z-0 mr-6 rounded-lg px-2 font-normal text-slate-700 hover:bg-gray-200 dark:text-white dark:hover:text-slate-900"
>
{navItem.label}
</a>
{/each}
</nav>
<!-- Sections - Requirement -->
2024-03-06 22:36:49 +01:00
<section id="requirement" class="mt-8 border-b border-gray-300 pb-10">
<h3 class="mb-3 mt-0 text-2xl font-bold">Requirement</h3>
<ul class="list font-light">
2023-09-24 12:24:28 +01:00
<HtmlRender content={get(courseData, 'metadata.requirements', '')} />
</ul>
</section>
<!-- Sections - Course Description -->
2024-03-06 22:36:49 +01:00
<section id="description" class="mt-8 border-b border-gray-300 pb-10">
<h3 class="mb-3 mt-0 text-2xl font-bold">Course Description</h3>
2023-09-24 12:24:28 +01:00
<HtmlRender
className="dark:text-white text-sm font-light"
content={get(courseData, 'metadata.description', '')}
/>
</section>
<!-- Sections - Goal -->
<section id="goals" class="mt-8 pb-10">
2024-03-06 22:36:49 +01:00
<h3 class="mb-3 mt-0 text-2xl font-bold">What you'll learn</h3>
<ul class="list font-light">
2023-09-24 12:24:28 +01:00
<HtmlRender content={get(courseData, 'metadata.goals', '')} />
</ul>
</section>
<!-- Sections - Certificate -->
2024-03-06 22:36:49 +01:00
<section class="mt-8 border-b border-gray-300 pb-10">
<h3 class="mt-0 text-2xl font-bold">Certificate</h3>
<p class="mb-3 text-sm font-light dark:text-white">
2023-08-05 04:44:32 +01:00
When you complete all of the courses in the program, you'll earn a Certificate to share
with your professional network.
</p>
2023-08-05 04:44:32 +01:00
<img src="/images/certificate-template.svg" alt="certificate template" />
</section>
<!-- Sections - Lessons -->
2024-03-06 22:36:49 +01:00
<section id="lessons" class="mt-8 border-b border-gray-300 pb-10">
<div class="mb-3 flex w-full items-center justify-between">
<h3 class="mb-3 mt-0 text-2xl font-bold">Course Content</h3>
<p class="text-sm font-light dark:text-white">
<!-- {lessons.length} lessons -->
{pluralize('lesson', lessons.length, true)}
</p>
</div>
{#each lessons as lesson, index}
2024-03-06 22:36:49 +01:00
<div class="mb-6 flex w-full flex-col justify-between md:flex-row md:items-center">
<div class="mb-3 flex items-center">
2023-08-20 19:08:48 +00:00
<Chip
value={getLectureNo(index + 1, '0')}
className="bg-primary-100 text-primary-700"
/>
2024-03-06 22:36:49 +01:00
<p class="ml-2 text-sm font-light dark:text-white">
{lesson.title}
</p>
</div>
<div class="w-2/4">
<div class="flex items-center">
{#if lesson.slide_url}
2024-03-06 22:36:49 +01:00
<span class="flex w-2/4 text-sm font-light"
><PresentationFile size={16} class="mr-1" />1 slide</span
>
{/if}
{#if lesson.note}
2024-03-06 22:36:49 +01:00
<span class="flex w-2/4 text-sm font-light"
2023-12-04 19:39:39 +03:00
><Notebook size={16} class="mr-1" />note</span
>
{/if}
</div>
<div class="flex items-center">
2023-08-10 12:46:14 +01:00
{#if lesson.videos}
2024-03-06 22:36:49 +01:00
<span class="flex w-2/4 text-sm font-light"
2023-08-10 12:46:14 +01:00
><Video size={16} class="mr-1" />{lesson.videos.length} video{lesson.videos
.length > 1
? 's'
: ''}
</span>
{/if}
{#if get(lesson, 'totalExercises[0].count')}
2024-03-06 22:36:49 +01:00
<span class="flex w-2/4 text-sm font-light"
><PageNumber size={16} class="mr-1" />{pluralize(
'exercise',
get(lesson, 'totalExercises[0].count', 0),
true
)}</span
>
{/if}
</div>
</div>
</div>
{/each}
</section>
2023-07-31 17:20:04 +00:00
<!-- Sections - Reviews -->
{#if reviews && reviews.length > 0}
<section id="reviews">
2024-03-06 22:36:49 +01:00
<h2 class="my-16 mb-6 ml-0 mr-0 font-semibold">Reviews</h2>
2023-07-31 17:20:04 +00:00
<div class="flex flex-wrap">
{#each reviews.slice(0, 4) as review, id}
{#if !review.hide}
<!-- review -->
2024-03-06 22:36:49 +01:00
<div class="item-start my-2 flex w-2/4 flex-row">
2023-07-31 17:20:04 +00:00
<!-- image container -->
{#if review.avatar_url}
2023-08-05 04:44:32 +01:00
<Avatar src={review.avatar_url} name="Avatar" className="mt-1" />
2023-07-31 17:20:04 +00:00
{/if}
<!-- profile content -->
2024-03-06 22:36:49 +01:00
<div class="w-11/12 pl-2.5">
2023-07-31 17:20:04 +00:00
<p class="mb-0.5 font-medium">{review.name}</p>
<!-- ratings -->
<div class="flex flex-row items-center">
{#if review.rating}
2024-03-06 22:36:49 +01:00
<img src={ratingsImg[review.rating - 1]} class="mr-4 mt-1 w-24" alt="" />
2023-07-31 17:20:04 +00:00
{/if}
</div>
<div
class="read-more-content mb-2"
2023-08-05 04:44:32 +01:00
style="max-height: {expandDescription[id] ? 'none' : '50px'}"
2023-07-31 17:20:04 +00:00
>
2024-03-06 22:36:49 +01:00
<p class="my-2 text-sm leading-5 text-gray-600">
2023-07-31 17:20:04 +00:00
{review.description}
</p>
</div>
{#if !expandDescription[id] && review.description.split(' ').length > 9}
<button
2024-03-06 22:36:49 +01:00
class="text-primary-700 mt-2 font-normal underline"
2023-08-05 04:44:32 +01:00
on:click={() => toggleDescription(id)}>See More</button
2023-07-31 17:20:04 +00:00
>
{/if}
{#if expandDescription[id]}
<button
2024-03-06 22:36:49 +01:00
class="text-primary-700 mt-2 font-normal underline"
2023-08-05 04:44:32 +01:00
on:click={() => toggleDescription(id)}>See Less</button
2023-07-31 17:20:04 +00:00
>
{/if}
</div>
</div>
{/if}
{/each}
</div>
{#if reviews.length > 4}
<PrimaryButton
label="See All"
className="w-3/12 p-4 mt-2"
variant={VARIANTS.OUTLINED}
onClick={() => ($reviewsModalStore.open = true)}
/>
{/if}
<!-- Reviews Modal -->
<Modal
onClose={() => ($reviewsModalStore.open = false)}
bind:open={$reviewsModalStore.open}
width="w-9/12"
modalHeading="Reviews"
>
<div class="flex">
<!-- ratings -->
<div class="w-1/3">
<h2 class="text-xl font-bold">
{averageRating} Rating
</h2>
2024-03-06 22:36:49 +01:00
<h2 class="mt-2 text-lg font-semibold">
2023-07-31 17:20:04 +00:00
{reviews.length} Ratings
</h2>
</div>
<!-- reviews -->
2024-03-06 22:36:49 +01:00
<div class="flex w-4/6 flex-wrap">
2023-07-31 17:20:04 +00:00
{#each reviews as review, id}
<!-- review -->
2024-03-06 22:36:49 +01:00
<div class="item-start my-2 flex w-full flex-row">
2023-07-31 17:20:04 +00:00
<!-- image container -->
{#if review.avatar_url}
2023-08-05 04:44:32 +01:00
<Avatar src={review.avatar_url} name={review.name} className="mt-1" />
2023-07-31 17:20:04 +00:00
{/if}
<!-- profile content -->
2024-03-06 22:36:49 +01:00
<div class="w-11/12 pl-2.5">
2023-07-31 17:20:04 +00:00
<p class="mb-0.5 font-medium">{review.name}</p>
<!-- ratings -->
<div class="flex flex-row">
2023-08-05 04:44:32 +01:00
<img src="/images/rating-full.svg" alt="" class="mr-2" />
2023-07-31 17:20:04 +00:00
<p class="text-xs text-gray-600">
{calDateDiff(review.created_at)}
2023-07-31 17:20:04 +00:00
</p>
</div>
<div
class="read-more-content mb-2"
2023-08-05 04:44:32 +01:00
style="max-height: {expandDescription[id] ? 'none' : '50px'}"
2023-07-31 17:20:04 +00:00
>
2024-03-06 22:36:49 +01:00
<p class="my-2 text-sm leading-5 text-gray-600">
2023-07-31 17:20:04 +00:00
{review.description}
</p>
</div>
</div>
</div>
{/each}
</div>
</div>
</Modal>
</section>
{/if}
<!-- Sections - Instructor -->
<section id="instructor" class="mt-8 pb-10">
2024-03-06 22:36:49 +01:00
<h3 class="mb-3 mt-0 text-2xl font-bold">Instructor</h3>
<div class="mb-4 flex items-center">
<img
alt="Author Avatar"
2024-03-06 22:36:49 +01:00
class="mr-3 block h-20 w-20 rounded-full"
src={get(instructor, 'imgUrl', $currentOrg.avatar_url || '/logo-512.png')}
/>
<div>
2024-03-06 22:36:49 +01:00
<p class="text-md font-light dark:text-white">
{get(instructor, 'name', $currentOrg.name)}
</p>
2024-03-06 22:36:49 +01:00
<p class="text-xs font-light dark:text-white">
{get(instructor, 'role', '')}
</p>
2024-03-06 22:36:49 +01:00
<p class="text-md flex items-center font-light dark:text-white">
2023-08-20 19:08:48 +00:00
<PlayFilled size={16} class="text-primary-700" />
2024-03-06 22:36:49 +01:00
<span class="ml-1">{get(instructor, 'courseNo', 10)} courses</span>
</p>
</div>
</div>
2024-03-06 22:36:49 +01:00
<p class="text-sm font-light dark:text-white">
{get(instructor, 'description', '')}
</p>
</section>
</div>
<!-- Pricing Details -->
<PricingSection
{courseData}
{editMode}
bind:startCoursePayment
className="target-component"
/>
</div>
{#if !isVisible}
<PricingSection
{courseData}
{editMode}
bind:startCoursePayment
mobile={true}
className="w-full"
/>
{/if}
</div>
</div>
<style lang="scss">
.banner {
background-color: #040f2d;
min-height: 472px;
}
.author {
color: #7888b7;
}
.banner-image {
max-width: 559px;
}
.backdrop {
background-color: rgba(0, 0, 0, 0.5);
}
.active {
position: relative;
display: inline-block;
}
.active::after {
position: absolute;
content: '';
width: 100%;
height: 3px;
background-color: var(--main-primary-color);
display: block;
bottom: -14px;
left: 0px;
}
.price-container {
width: 405px;
min-width: 330px;
height: fit-content;
position: sticky;
top: 0;
}
.course-content {
max-width: 608px;
min-width: 60%;
}
nav {
overflow: auto;
margin: 0;
overflow-y: hidden;
width: 100%;
}
:global(.list ul li) {
margin-left: 1rem;
list-style-type: disc;
}
:global(.plyr) {
width: 100% !important;
}
2023-07-31 17:20:04 +00:00
.read-more-content {
max-height: 100px; /* Adjust this value to set the maximum height for the truncated content */
overflow: hidden;
transition: max-height 0.3s ease;
text-overflow: ellipsis;
}
.read-more-button {
cursor: pointer;
color: blue;
text-decoration: underline;
}
@media screen and (max-width: 1023px) {
.course-content {
min-width: 80%;
}
}
</style>