2021-07-10 19:16:10 +00:00
|
|
|
<script context="module">
|
|
|
|
|
export async function preload({ params }) {
|
2021-07-12 05:55:57 +03:00
|
|
|
let [courseId, courseNavItem, lessonId] = params.id;
|
2021-07-13 16:27:02 +00:00
|
|
|
const res = await this.fetch(`api/course?id=${courseId}`);
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
return { courseId, courseData: data };
|
|
|
|
|
} else {
|
|
|
|
|
this.error(res.status, data.message);
|
|
|
|
|
}
|
2021-07-10 19:16:10 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-07-13 16:27:02 +00:00
|
|
|
import Time24 from "carbon-icons-svelte/lib/Time24";
|
|
|
|
|
import Edit24 from "carbon-icons-svelte/lib/Edit24";
|
|
|
|
|
import Save24 from "carbon-icons-svelte/lib/Save24";
|
|
|
|
|
import CheckmarkFilled24 from "carbon-icons-svelte/lib/CheckmarkFilled24";
|
|
|
|
|
import PageNav from "../../../../components/PageNav/index.svelte";
|
|
|
|
|
import PageBody from "../../../../components/PageBody/index.svelte";
|
|
|
|
|
import PrimaryButton from "../../../../components/PrimaryButton/index.svelte";
|
|
|
|
|
import TextField from "../../../../components/Form/TextField.svelte";
|
|
|
|
|
import IconButton from "../../../../components/IconButton/index.svelte";
|
|
|
|
|
import Select from "../../../../components/Form/Select.svelte";
|
|
|
|
|
import CourseContainer from "../../../../components/CourseContainer/index.svelte";
|
2021-07-10 19:16:10 +00:00
|
|
|
import {
|
|
|
|
|
lessons,
|
2021-07-12 05:55:57 +03:00
|
|
|
tutors,
|
2021-07-10 19:16:10 +00:00
|
|
|
handleAddLesson,
|
2021-07-13 16:27:02 +00:00
|
|
|
} from "../../../../components/Course/components/Lesson/store/lessons";
|
2021-07-10 19:16:10 +00:00
|
|
|
|
2021-07-13 16:27:02 +00:00
|
|
|
export let courseData;
|
2021-07-10 19:16:10 +00:00
|
|
|
|
2021-07-12 05:55:57 +03:00
|
|
|
let lessonEditing;
|
2021-07-10 19:16:10 +00:00
|
|
|
let ref;
|
|
|
|
|
|
|
|
|
|
function formatDate(date) {
|
|
|
|
|
const d = new Date(date);
|
|
|
|
|
|
2021-07-13 16:27:02 +00:00
|
|
|
const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d);
|
|
|
|
|
const mo = new Intl.DateTimeFormat("en", { month: "2-digit" }).format(d);
|
|
|
|
|
const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d);
|
2021-07-10 19:16:10 +00:00
|
|
|
|
|
|
|
|
return `${ye}-${mo}-${da}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addLesson() {
|
|
|
|
|
handleAddLesson();
|
|
|
|
|
setTimeout(() => {
|
2021-07-12 05:55:57 +03:00
|
|
|
lessonEditing = $lessons.length - 1;
|
2021-07-10 19:16:10 +00:00
|
|
|
if (ref) {
|
2021-07-13 16:27:02 +00:00
|
|
|
ref.scrollIntoView({ block: "end", behavior: "smooth" });
|
2021-07-10 19:16:10 +00:00
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-07-13 16:27:02 +00:00
|
|
|
<CourseContainer {courseData}>
|
2021-07-12 05:55:57 +03:00
|
|
|
<PageNav title="Lessons">
|
2021-07-10 19:16:10 +00:00
|
|
|
<div slot="widget">
|
|
|
|
|
<PrimaryButton label="Add" onClick={addLesson} />
|
|
|
|
|
</div>
|
|
|
|
|
</PageNav>
|
|
|
|
|
|
|
|
|
|
<PageBody width="w-11/12 m-auto">
|
|
|
|
|
<div class="w-4/5 m-auto">
|
2021-07-12 05:55:57 +03:00
|
|
|
{#each $lessons as lesson, index}
|
2021-07-10 19:16:10 +00:00
|
|
|
<div
|
|
|
|
|
bind:this={ref}
|
|
|
|
|
class="group relative m-auto rounded-md border-2 border-gray-100 py-3 px-5 mr-4 mb-4 flex items-center hover:shadow-2xl shadow-md transition delay-150 duration-300 ease-in-out"
|
|
|
|
|
>
|
|
|
|
|
<!-- Complete or Not complete icon -->
|
|
|
|
|
<div class="absolute -left-6 -top-6 success">
|
|
|
|
|
<IconButton
|
2021-07-12 05:55:57 +03:00
|
|
|
onClick={() => (lesson.isComplete = !lesson.isComplete)}
|
2021-07-13 09:43:53 +03:00
|
|
|
toolTipProps={{
|
2021-07-13 16:27:02 +00:00
|
|
|
title: `Click to ${lesson.isComplete ? "lock" : "unlock"}`,
|
|
|
|
|
direction: "right",
|
2021-07-13 09:43:53 +03:00
|
|
|
}}
|
2021-07-10 19:16:10 +00:00
|
|
|
>
|
2021-07-12 05:55:57 +03:00
|
|
|
{#if lesson.isComplete}
|
2021-07-10 19:16:10 +00:00
|
|
|
<CheckmarkFilled24 class="carbon-icon" />
|
|
|
|
|
{:else}
|
|
|
|
|
<span class="text-2xl">🔒</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Edit/Save -->
|
|
|
|
|
<div class="absolute top-2 right-0">
|
2021-07-12 05:55:57 +03:00
|
|
|
{#if lessonEditing === index}
|
|
|
|
|
<IconButton onClick={() => (lessonEditing = null)}>
|
2021-07-10 19:16:10 +00:00
|
|
|
<Save24 class="carbon-icon" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
{:else}
|
2021-07-12 05:55:57 +03:00
|
|
|
<IconButton onClick={() => (lessonEditing = index)}>
|
2021-07-10 19:16:10 +00:00
|
|
|
<Edit24 class="carbon-icon" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="">
|
|
|
|
|
<h3 class="text-3xl font-bold">{index + 1}.</h3>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="ml-8 w-4/5">
|
2021-07-12 05:55:57 +03:00
|
|
|
{#if lessonEditing === index}
|
|
|
|
|
<TextField bind:value={lesson.title} autofocus={true} />
|
2021-07-10 19:16:10 +00:00
|
|
|
{:else}
|
|
|
|
|
<h3 class="text-3xl font-semibold m-0 flex items-center">
|
2021-07-12 05:55:57 +03:00
|
|
|
<a href={lesson.to} class="hover:underline text-black">
|
|
|
|
|
{lesson.title}
|
2021-07-10 19:16:10 +00:00
|
|
|
</a>
|
|
|
|
|
</h3>
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="flex items-center mb-2">
|
|
|
|
|
<div class="flex items-center mr-2">
|
2021-07-12 05:55:57 +03:00
|
|
|
{lesson.resources
|
2021-07-10 19:16:10 +00:00
|
|
|
.map((r) => `${r.value} ${r.label}`)
|
2021-07-13 16:27:02 +00:00
|
|
|
.join(", ")}
|
2021-07-10 19:16:10 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center justify-between mt-3 w-full">
|
2021-07-12 05:55:57 +03:00
|
|
|
{#if lessonEditing === index}
|
2021-07-10 19:16:10 +00:00
|
|
|
<Select
|
2021-07-12 05:55:57 +03:00
|
|
|
bind:value={lesson.tutor.name}
|
|
|
|
|
options={$tutors}
|
2021-07-10 19:16:10 +00:00
|
|
|
valueKey="text"
|
|
|
|
|
/>
|
|
|
|
|
{:else}
|
|
|
|
|
<a
|
|
|
|
|
href="courses/1/people"
|
|
|
|
|
class="flex items-center hover:underline text-black"
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
alt="Placeholder"
|
|
|
|
|
class="block rounded-full"
|
|
|
|
|
width="24"
|
|
|
|
|
height="20"
|
2021-07-12 05:55:57 +03:00
|
|
|
src={lesson.tutor.avatar}
|
2021-07-10 19:16:10 +00:00
|
|
|
/>
|
2021-07-12 05:55:57 +03:00
|
|
|
<p class="ml-2 text-sm font-bold">{lesson.tutor.name}</p>
|
2021-07-10 19:16:10 +00:00
|
|
|
</a>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<div class="flex items-center">
|
2021-07-12 05:55:57 +03:00
|
|
|
{#if lessonEditing === index}
|
2021-07-10 19:16:10 +00:00
|
|
|
<input
|
|
|
|
|
type="date"
|
2021-07-12 05:55:57 +03:00
|
|
|
name="lesson-date-picker"
|
2021-07-10 19:16:10 +00:00
|
|
|
class="p-2 rounded-md w-40"
|
2021-07-12 05:55:57 +03:00
|
|
|
value={formatDate(lesson.date)}
|
|
|
|
|
on:input={(e) => (lesson.date = e.target.value)}
|
2021-07-10 19:16:10 +00:00
|
|
|
/>
|
|
|
|
|
{:else}
|
|
|
|
|
<Time24 class="carbon-icon" />
|
|
|
|
|
<p class="text-md font-semibold ml-2">
|
2021-07-12 05:55:57 +03:00
|
|
|
{new Date(lesson.date).toDateString()}
|
2021-07-10 19:16:10 +00:00
|
|
|
</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</PageBody>
|
|
|
|
|
</CourseContainer>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.group {
|
|
|
|
|
min-height: 170px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|