frondend/app/courses/[slug]/page.tsx

39 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2024-10-05 15:04:17 +08:00
import React from 'react'
import ResponsiveNav from "@/components/Navbar/ResponsiveNav";
2024-10-08 19:47:35 +08:00
import { fetchCourses, fetchSettings } from "@/utils";
2024-10-05 15:04:17 +08:00
import dynamic from 'next/dynamic'
2024-10-08 19:51:36 +08:00
//import Course from '@/components/Course/Course';
const DynamicComponent = dynamic(() => import('@/components/Course/Course'), {
ssr: true,
})
2024-10-05 15:04:17 +08:00
async function getCourses() {
const courses = await fetchCourses();
return courses;
}
2024-10-08 15:11:16 +08:00
// async function getCourse(slug: string) {
// const course = await fetchCourse(slug);
// return course;
// }
2024-10-05 15:04:17 +08:00
async function getSettings() {
const settings = await fetchSettings();
return settings;
}
export default async function Page({ params }: { params: { slug: string } }) {
const courses = await getCourses();
const settings = await getSettings();
//const course = await getCourse(params.slug);
const course = courses.find(course => course.id === params.slug);
if (!course) {
throw new Error(`Course with slug ${params.slug} not found`);
}
return (
<div className='bg-[#F6E8E8]'>
2024-10-08 19:08:37 +08:00
2024-10-05 15:04:17 +08:00
<ResponsiveNav courses={courses} settings={settings} />
2024-10-08 19:51:36 +08:00
<DynamicComponent course={course} settings={settings} />
2024-10-05 15:04:17 +08:00
</div>
)
}