-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CoursePage component to include completed courses
- Loading branch information
1 parent
a984a99
commit a4d57b8
Showing
1 changed file
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,38 @@ import CourseCard from "../../components/CourseCard.tsx"; | |
import Footer from "../../components/Footer.tsx"; | ||
|
||
import IconChevronDown from "https://deno.land/x/[email protected]/tsx/chevron-down.tsx"; | ||
|
||
export const handler: Handlers<CourseGroup> = { | ||
GET(_req, ctx) { | ||
import { getCookies } from "$std/http/mod.ts"; | ||
import { getStudent } from "../../utils/KV.ts"; | ||
interface Props { | ||
courses: CourseGroup; | ||
completed: string[]; | ||
} | ||
export const handler: Handlers<Props> = { | ||
async GET(_req, ctx) { | ||
let foundCourseGroup: CourseGroup | Course | undefined = undefined; | ||
const toFind = decodeURIComponent(ctx.params.slug); | ||
foundCourseGroup = cache.courses.find((c) => { | ||
return "courses" in c && c.courses.length > 0 && | ||
c.lableSlug === toFind; | ||
}); | ||
|
||
const session = getCookies(_req.headers)["sessionId"]; | ||
if (!session) { | ||
return ctx.render({ | ||
completed: [], | ||
courses: foundCourseGroup as CourseGroup, | ||
}); | ||
} | ||
let completed = (await getStudent(session)).completedCourses; | ||
if (!foundCourseGroup) return ctx.renderNotFound(); | ||
return ctx.render(foundCourseGroup as CourseGroup); | ||
return ctx.render({ | ||
completed, | ||
courses: foundCourseGroup as CourseGroup, | ||
}); | ||
}, | ||
}; | ||
|
||
export default function CoursePage(props: PageProps<CourseGroup>) { | ||
const foundCourseGroup = props.data; | ||
export default function CoursePage(props: PageProps<Props>) { | ||
const {courses:foundCourseGroup, completed} = props.data; | ||
return ( | ||
<> | ||
<Head> | ||
|
@@ -43,7 +58,7 @@ export default function CoursePage(props: PageProps<CourseGroup>) { | |
</div> | ||
<div class="flex flex-col mt-2 pr-3"> | ||
{foundCourseGroup.courses.map((innerCourse) => ( | ||
<CourseCard key={innerCourse.slug} course={innerCourse} /> | ||
<CourseCard isDone={completed ? completed.includes(innerCourse.slug) : false} key={innerCourse.slug} course={innerCourse} /> | ||
))} | ||
</div> | ||
</div> | ||
|