From 8cf4148703a65ba558dc8bd2a569beb221884cf6 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Thu, 3 Aug 2023 02:51:02 +0100 Subject: [PATCH] CLASSROOMIO-T-88: Mark lesson as complete --- src/lib/components/Chip/Text.svelte | 9 +- .../Course/components/Lesson/store/lessons.ts | 49 ++++---- .../Navigation/NavExpandable.svelte | 13 +-- .../Course/components/Navigation/index.svelte | 74 ++++++------ src/lib/components/Course/function.js | 8 +- src/lib/components/PageBody/index.svelte | 4 +- src/lib/utils/services/courses/clone.ts | 29 ++--- src/lib/utils/services/courses/index.ts | 110 +++++------------- src/lib/utils/types/dashboard.ts | 2 +- src/lib/utils/types/index.ts | 3 +- src/routes/+layout.svelte | 5 +- src/routes/courses/[id]/lessons/+page.svelte | 17 +-- .../lessons/[...lessonParams]/+page.svelte | 23 +++- src/routes/dashboard/+page.svelte | 48 +++----- src/routes/org/[slug]/+page.svelte | 75 +++++------- 15 files changed, 190 insertions(+), 279 deletions(-) diff --git a/src/lib/components/Chip/Text.svelte b/src/lib/components/Chip/Text.svelte index a87203c3..970f2a5a 100644 --- a/src/lib/components/Chip/Text.svelte +++ b/src/lib/components/Chip/Text.svelte @@ -2,14 +2,15 @@ export let className = ''; export let value = ''; export let size = ''; + export let shape = 'rounded-md';

{value}

diff --git a/src/lib/components/Course/components/Lesson/store/lessons.ts b/src/lib/components/Course/components/Lesson/store/lessons.ts index 5c8ac14e..604e315f 100644 --- a/src/lib/components/Course/components/Lesson/store/lessons.ts +++ b/src/lib/components/Course/components/Lesson/store/lessons.ts @@ -1,10 +1,6 @@ import { writable } from 'svelte/store'; import type { Writable, Updater } from 'svelte/store'; -import { - createLesson, - updateLesson, - deleteLesson, -} from '$lib/utils/services/courses'; +import { createLesson, updateLesson, deleteLesson } from '$lib/utils/services/courses'; import type { Lesson, Course } from '$lib/utils/types'; @@ -12,12 +8,13 @@ export const lessons: Writable = writable([]); export const lesson = writable({ id: null, totalExercises: 0, + is_complete: false, materials: { note: null, slide_url: null, - video_url: null, + video_url: null }, - exercises: [], + exercises: [] }); export const isLessonDirty = writable(false); @@ -31,8 +28,9 @@ export function handleAddLesson() { // profile: undefined, call_url: undefined, lesson_at: new Date(), - is_complete: false, - }, + is_unlocked: false, + is_complete: false + } ]; }) as Updater); } @@ -48,17 +46,12 @@ export function handleDelete(lessonId: Lesson['id']) { } } - lessons.update((_lessons) => - _lessons.filter((lesson) => lesson.id !== lessonId) - ); + lessons.update((_lessons) => _lessons.filter((lesson) => lesson.id !== lessonId)); console.log(`lessonId`, lessonId); }; } -export async function handleSaveLesson( - lesson: Lesson, - course_id: Course['id'] -) { +export async function handleSaveLesson(lesson: Lesson, course_id: Course['id']) { console.log(`handleSaveLesson lesson`, lesson); const newLesson = { title: lesson.title, @@ -66,10 +59,11 @@ export async function handleSaveLesson( call_url: lesson.call_url, teacher_id: lesson.profile ? lesson.profile.id : undefined, course_id, - is_complete: lesson.is_complete, + is_unlocked: lesson.is_unlocked, + is_complete: lesson.is_complete }; - let updatedLesson: any[] | null = null; + let newLessonData: any[] | null = null; if (typeof lesson.id === 'string') { // No need to get the result of update cause we have all in local state @@ -77,26 +71,25 @@ export async function handleSaveLesson( } else { const { data } = await createLesson(newLesson); - updatedLesson = data; + newLessonData = data; } lessons.update((l) => - l.map((lesson) => { - if (!lesson.id && updatedLesson) { - lesson.id = updatedLesson[0].id; + l.map((_lesson) => { + if (!_lesson.id && newLessonData) { + _lesson.id = newLessonData[0].id; + } else if (typeof lesson.id === 'string' && lesson.id === _lesson.id) { + return { ..._lesson, is_complete: lesson.is_complete }; } - return lesson; + return _lesson; }) ); } -export async function handleUpdateLessonMaterials( - lesson: any, - lessonId: Lesson['id'] -) { +export async function handleUpdateLessonMaterials(lesson: any, lessonId: Lesson['id']) { const materials = { - ...lesson.materials, + ...lesson.materials }; delete materials.totalExercises; diff --git a/src/lib/components/Course/components/Navigation/NavExpandable.svelte b/src/lib/components/Course/components/Navigation/NavExpandable.svelte index 75ef3f24..966a1c5a 100644 --- a/src/lib/components/Course/components/Navigation/NavExpandable.svelte +++ b/src/lib/components/Course/components/Navigation/NavExpandable.svelte @@ -15,20 +15,13 @@
-
- {#if !hideSortIcon} - - {/if} {label} -
+ {#if isExpanded}
diff --git a/src/lib/components/Course/components/Navigation/index.svelte b/src/lib/components/Course/components/Navigation/index.svelte index eff97a0a..886f8c2b 100644 --- a/src/lib/components/Course/components/Navigation/index.svelte +++ b/src/lib/components/Course/components/Navigation/index.svelte @@ -4,8 +4,9 @@ import { page } from '$app/stores'; import hotkeys from 'hotkeys-js'; import { browser } from '$app/environment'; + import LockedIcon from 'carbon-icons-svelte/lib/Locked.svelte'; import HomeIcon from 'carbon-icons-svelte/lib/Home.svelte'; - import CheckmarkFilledIcon from 'carbon-icons-svelte/lib/CheckmarkFilled.svelte'; + import CheckmarkOutline from 'carbon-icons-svelte/lib/CheckmarkOutline.svelte'; import SettingsIcon from 'carbon-icons-svelte/lib/Settings.svelte'; import ChevronLeftIcon from 'carbon-icons-svelte/lib/ChevronLeft.svelte'; import ChevronRightIcon from 'carbon-icons-svelte/lib/ChevronRight.svelte'; @@ -13,12 +14,9 @@ import PageNav from '$lib/components/PageNav/index.svelte'; import IconButton from '$lib/components/IconButton/index.svelte'; import Avatar from '$lib/components/Avatar/index.svelte'; - import { - getNavItemRoute, - getLessonsRoute, - getLectureNo, - } from '$lib/components/Course/function'; + import { getNavItemRoute, getLessonsRoute, getLectureNo } from '$lib/components/Course/function'; + import TextChip from '$lib/components/Chip/Text.svelte'; import RoleBasedSecurity from '$lib/components/RoleBasedSecurity/index.svelte'; import Settings from '../Settings/index.svelte'; import { settingsDialog } from '../Settings/store'; @@ -47,7 +45,7 @@ function getHref(item) { return item.to; - // return item.is_complete ? item.to : path || $page.url.pathname + // return item.is_unlocked ? item.to : path || $page.url.pathname } function handleSaveTitle() { @@ -89,18 +87,18 @@ { label: 'Overview', to: getNavItemRoute($course.id), - hideSortIcon: true, + hideSortIcon: true }, { label: 'Lessons', to: getLessonsRoute($course.id), hideSortIcon: false, - isLecture: true, + isLecture: true }, { label: 'Attendance', to: getNavItemRoute($course.id, 'attendance'), - hideSortIcon: true, + hideSortIcon: true }, { label: 'Submissions', @@ -108,12 +106,12 @@ hideSortIcon: true, show() { return !isStudent; - }, + } }, { label: 'Marks', to: getNavItemRoute($course.id, 'marks'), - hideSortIcon: true, + hideSortIcon: true }, // { // label: 'Scoreboard', @@ -123,12 +121,12 @@ { label: 'People', to: getNavItemRoute($course.id, 'people'), - hideSortIcon: true, + hideSortIcon: true }, { label: 'Certificates', to: getNavItemRoute($course.id, 'certificates'), - hideSortIcon: true, + hideSortIcon: true }, { label: 'Landing Page', @@ -136,17 +134,15 @@ hideSortIcon: true, show() { return !isStudent; - }, - }, + } + } ]; } -
+
{#if show}
@@ -155,9 +151,7 @@ - ($settingsDialog.open = !$settingsDialog.open)} - > + ($settingsDialog.open = !$settingsDialog.open)}> @@ -175,13 +169,11 @@ {#if navItem.isLecture} {#each $lessons as item, index} { @@ -189,17 +181,23 @@ setTimeout(() => (show = false), 500); } }} + aria-disabled={!item.is_unlocked} > - - {getLectureNo(index + 1)} - + {item.title} - {#if item.is_complete} - - + {#if !item.is_unlocked} + + + + {:else if item.is_complete} + + - {:else} - 🔒 {/if} {/each} @@ -209,9 +207,7 @@ {/each}
-