-
Notifications
You must be signed in to change notification settings - Fork 259
Implement modules page #3394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Implement modules page #3394
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| import { Button } from '@/components/ui/button' | ||||||
| import { | ||||||
| Card, | ||||||
| CardContent, | ||||||
| CardDescription, | ||||||
| CardFooter, | ||||||
| CardHeader, | ||||||
| CardTitle, | ||||||
| } from '@/components/ui/card' | ||||||
| import { CourseDetail, Module } from '@/data/course' | ||||||
| import Link from 'next/link' | ||||||
|
|
||||||
| type Props = { | ||||||
| course: CourseDetail | ||||||
| module: Module | ||||||
| } | ||||||
|
|
||||||
| export default function ModuleCard({ course, module }: Props) { | ||||||
| const coursePageUrl = `/${course.sourceLanguage.code}/courses/${course.targetLanguage.code}/courses/${module.slug}` | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐛 Bug: Potential Runtime Crash in ModuleCard ComponentIssue: The URL building logic in Current problematic code: const coursePageUrl = `/${course.sourceLanguage.code}/courses/${course.targetLanguage.code}/courses/${module.slug}`
If course or module is null or undefined, then the app might crash |
||||||
|
|
||||||
| return ( | ||||||
| <Card> | ||||||
| <CardHeader> | ||||||
| <CardTitle>{module.title}</CardTitle> | ||||||
| <CardDescription>Card Description</CardDescription> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </CardHeader> | ||||||
| <CardContent> | ||||||
| <p>Card Content</p> | ||||||
| </CardContent> | ||||||
| <CardFooter> | ||||||
| <Button asChild> | ||||||
| <Link href={coursePageUrl}>Learn</Link> | ||||||
| </Button> | ||||||
| </CardFooter> | ||||||
| </Card> | ||||||
| ) | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,40 @@ | ||
| import { getCourseDetail, getCourseId, listAvailableCourses } from "@/data/course" | ||
| import { | ||
| getCourseDetail, | ||
| getCourseId, | ||
| listAvailableCourses, | ||
| } from '@/data/course' | ||
| import ModuleCard from './module-card' | ||
|
|
||
| export async function generateStaticParams() { | ||
| const courses = await listAvailableCourses() | ||
| const courses = await listAvailableCourses() | ||
|
|
||
| return courses.map((course) => ({ | ||
| sourceLanguageCode: course.uiLanguage, | ||
| targetLanguageCode: course.languageCode, | ||
| })) | ||
| return courses.map((course) => ({ | ||
| sourceLanguageCode: course.uiLanguage, | ||
| targetLanguageCode: course.languageCode, | ||
| })) | ||
| } | ||
|
|
||
| type Props = { | ||
| params: { | ||
| sourceLanguageCode: string | ||
| targetLanguageCode: string | ||
| } | ||
| params: { | ||
| sourceLanguageCode: string | ||
| targetLanguageCode: string | ||
| } | ||
| } | ||
|
|
||
| export default async function CourseHomePage({params}: Props) { | ||
| const courseId = await getCourseId(params) | ||
| const detail = await getCourseDetail(courseId) | ||
| export default async function CourseHomePage({ params }: Props) { | ||
| const courseId = await getCourseId(params) | ||
| const detail = await getCourseDetail(courseId) | ||
|
|
||
| return <h1>{detail.targetLanguage.name}</h1> | ||
| return ( | ||
| <> | ||
| <h1>{detail.targetLanguage.name}</h1> | ||
| <ul className="flex space-y-6 flex-col p-6"> | ||
| {detail.modules.map((module) => ( | ||
| <li key={module.slug}> | ||
| <ModuleCard course={detail} module={module} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Pass // ✅ Better - Pure display component
type ModuleCardProps = {
course: CourseDetail
module: Module
coursePageUrl: string // Parent handles URL logic
} |
||
| </li> | ||
| ))} | ||
| </ul> | ||
| </> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| }, | ||
| "modules": [ | ||
| { | ||
| "slug": "basics", | ||
| "title": "Basics", | ||
| "skills": [ | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import path from 'node:path' | ||
|
|
||
| export function getAbsoluteCoursePath(jsonPath: string) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Use default export since the file contains only a single function. // ✅ Better - Default export for single function module
export default function getAbsoluteCoursePath(jsonPath: string) {
return path.join(process.cwd(), 'src', 'courses', jsonPath)
} |
||
| return path.join(process.cwd(), 'src', 'courses', jsonPath) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue: Generic
Propstype should be renamed toModuleCardPropsfor better searchability, IDE support, and maintainability. Follows industry standards and makes refactoring easier.