feat: empty view

feat/course
Arik Chakma 2 days ago
parent e5af0b1b52
commit 4248620471
  1. 2
      src/components/Course/CourseLayout.tsx
  2. 17
      src/components/Course/EmptyView.tsx
  3. 33
      src/pages/learn/[courseId]/[chapterId]/index.astro

@ -17,7 +17,7 @@ import { RoadmapLogoIcon } from '../ReactIcons/RoadmapLogo';
export type CourseLayoutProps = { export type CourseLayoutProps = {
children: ReactNode; children: ReactNode;
} & Omit<CourseSidebarProps, 'completedPercentage'>; } & Omit<CourseSidebarProps, 'completedPercentage' | 'isLoading'>;
export function CourseLayout(props: CourseLayoutProps) { export function CourseLayout(props: CourseLayoutProps) {
const { children, ...sidebarProps } = props; const { children, ...sidebarProps } = props;

@ -0,0 +1,17 @@
import { CourseLayout, type CourseLayoutProps } from './CourseLayout';
import { BookOpenIcon } from 'lucide-react';
type EmptyViewProps = Omit<CourseLayoutProps, 'children'> & {};
export function EmptyView(props: EmptyViewProps) {
return (
<CourseLayout {...props}>
<div className="mx-auto flex max-w-sm flex-col items-center justify-center gap-2 p-4 text-gray-700">
<BookOpenIcon className="size-24" />
<p className="text-balance text-center text-lg font-medium">
Select a lesson from the left sidebar to get started.
</p>
</div>
</CourseLayout>
);
}

@ -1,4 +1,5 @@
--- ---
import { EmptyView } from '../../../../components/Course/EmptyView';
import SkeletonLayout from '../../../../layouts/SkeletonLayout.astro'; import SkeletonLayout from '../../../../layouts/SkeletonLayout.astro';
import { import {
getAllCourses, getAllCourses,
@ -20,7 +21,10 @@ export async function getStaticPaths() {
chapterId: chapter.id, chapterId: chapter.id,
}, },
props: { props: {
course, course: {
...course,
chapters,
},
chapter, chapter,
}, },
}; };
@ -37,27 +41,20 @@ interface Params extends Record<string, string | undefined> {
} }
interface Props { interface Props {
course: CourseFileType; course: CourseFileType & { chapters: ChapterFileType[] };
chapter: ChapterFileType; chapter: ChapterFileType;
} }
const { courseId, chapterId } = Astro.params; const { courseId, chapterId } = Astro.params;
const { chapter } = Astro.props; const { course } = 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}`;
--- ---
<SkeletonLayout title='Redirecting..' noIndex={true} redirectUrl={fullUrl}> <SkeletonLayout title={course.frontmatter.title}>
<div class='p-8'> <EmptyView
<h2 class='text-xl font-bold'>Redirecting ..</h2> activeCourseId={courseId}
<p>Click the link below if you are not redirected automatically.</p> activeChapterId={chapterId}
title={course.frontmatter.title}
<p><a href={fullUrl} class='text-blue-700 underline'>{fullUrl}</a></p> chapters={course.chapters}
</div> client:load
/>
</SkeletonLayout> </SkeletonLayout>

Loading…
Cancel
Save