From 4248620471ae69a585e0ae2077d1c9ba9a8065c6 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Fri, 22 Nov 2024 11:40:00 +0600 Subject: [PATCH] feat: empty view --- src/components/Course/CourseLayout.tsx | 2 +- src/components/Course/EmptyView.tsx | 17 ++++++++++ .../learn/[courseId]/[chapterId]/index.astro | 33 +++++++++---------- 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 src/components/Course/EmptyView.tsx diff --git a/src/components/Course/CourseLayout.tsx b/src/components/Course/CourseLayout.tsx index 73c9274ef..4edc419b3 100644 --- a/src/components/Course/CourseLayout.tsx +++ b/src/components/Course/CourseLayout.tsx @@ -17,7 +17,7 @@ import { RoadmapLogoIcon } from '../ReactIcons/RoadmapLogo'; export type CourseLayoutProps = { children: ReactNode; -} & Omit; +} & Omit; export function CourseLayout(props: CourseLayoutProps) { const { children, ...sidebarProps } = props; diff --git a/src/components/Course/EmptyView.tsx b/src/components/Course/EmptyView.tsx new file mode 100644 index 000000000..3b401aadf --- /dev/null +++ b/src/components/Course/EmptyView.tsx @@ -0,0 +1,17 @@ +import { CourseLayout, type CourseLayoutProps } from './CourseLayout'; +import { BookOpenIcon } from 'lucide-react'; + +type EmptyViewProps = Omit & {}; + +export function EmptyView(props: EmptyViewProps) { + return ( + +
+ +

+ Select a lesson from the left sidebar to get started. +

+
+
+ ); +} diff --git a/src/pages/learn/[courseId]/[chapterId]/index.astro b/src/pages/learn/[courseId]/[chapterId]/index.astro index 81997fe67..38d0bf2b6 100644 --- a/src/pages/learn/[courseId]/[chapterId]/index.astro +++ b/src/pages/learn/[courseId]/[chapterId]/index.astro @@ -1,4 +1,5 @@ --- +import { EmptyView } from '../../../../components/Course/EmptyView'; import SkeletonLayout from '../../../../layouts/SkeletonLayout.astro'; import { getAllCourses, @@ -20,7 +21,10 @@ export async function getStaticPaths() { chapterId: chapter.id, }, props: { - course, + course: { + ...course, + chapters, + }, chapter, }, }; @@ -37,27 +41,20 @@ interface Params extends Record { } interface Props { - course: CourseFileType; + course: CourseFileType & { chapters: ChapterFileType[] }; chapter: ChapterFileType; } const { courseId, chapterId } = Astro.params; -const { chapter } = Astro.props; - -const firstLesson = chapter.lessons?.sort( - (a, b) => a.frontmatter.order - b.frontmatter.order, -)?.[0]; - -const fullUrl = firstLesson - ? `/learn/${courseId}/${chapterId}/${firstLesson?.id}` - : `/learn/${courseId}`; +const { course } = Astro.props; --- - -
-

Redirecting ..

-

Click the link below if you are not redirected automatically.

- -

{fullUrl}

-
+ +