Skip to content

Commit 8b0e8c4

Browse files
nmsnourai
authored andcommitted
refactor: optimize rendering logic in List and page
1 parent e62364a commit 8b0e8c4

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

src/app/learn/[type]/List.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ import { ChallengesCard } from './ChallengesCard';
2525
import { CourseCard } from './CourseCard';
2626
import { GrowPathCard } from './GrowPathCard';
2727

28-
export function List({type, data}) {
28+
const CardComponents = {
29+
courses: CourseCard,
30+
challenges: ChallengesCard,
31+
career_path: GrowPathCard,
32+
};
33+
34+
export function List({ type, data }) {
2935
const openFilter = useOpenFilter();
30-
// console.log(data, 'datadatadatadata')
36+
const CardComponent = CardComponents[type];
37+
3138
return (
3239
<div>
3340
<div
@@ -40,11 +47,7 @@ export function List({type, data}) {
4047
'3xl:grid-cols-5': !openFilter,
4148
})}
4249
>
43-
{type === 'courses' && data.list?.map(i => <CourseCard data={i} key={`open-courses-${i.base.course_series_id}`} />)}
44-
{type === 'challenges' &&
45-
data.list?.map(i => <ChallengesCard data={i} key={`Challenges-${i.base.course_series_id}`} />)}
46-
{type === 'career_path' &&
47-
data.list?.map(i => <GrowPathCard data={i} key={`GrowPathCard-${i.base.course_series_id}`} />)}
50+
{CardComponent && data.list?.map(i => <CardComponent data={i} key={`${type}-${i.base.course_series_id}`} />)}
4851
</div>
4952
<OPagination total={data.count} />
5053
</div>

src/app/learn/[type]/page.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,35 @@ import { Container } from './Container';
2525
import { ListSkeleton } from './ListSkeleton';
2626
// import { LearnNavBar } from './nav'
2727

28+
const titles = {
29+
courses: {
30+
title: 'Open Courses',
31+
desc: 'Selected open courses from technical skills to practical tasks, accessible to everyone with no cost!',
32+
},
33+
challenges: {
34+
title: 'Challenges',
35+
desc: 'Hands-on Bootcamp, Workshop or Hackerhouse, etc.',
36+
},
37+
career_path: {
38+
title: 'Career Path',
39+
desc: 'Learning paths designed for different levels of builder',
40+
},
41+
};
2842

2943
export default async function Page({ params, searchParams }) {
44+
const titleData = titles?.[params?.type];
45+
3046
return (
3147
<div>
3248
<div className="px-6">
33-
{params.type === 'courses' && (
34-
<Title
35-
title="Open Courses"
36-
desc="Selected open courses from technical skills to practical tasks, accessible to everyone with no cost!"
37-
// link="https://forms.gle/s2tDbixtdqTU8xbp9"
38-
// linkText="Click Here"
39-
/>
40-
)}
41-
{params.type === 'challenges' && (
42-
<Title
43-
title="Challenges"
44-
desc="Hands-on Bootcamp, Workshop or Hackerhouse, etc."
45-
// link="https://forms.gle/s2tDbixtdqTU8xbp9"
46-
// linkText="Click Here"
47-
/>
48-
)}
49-
{params.type === 'career_path' && (
50-
<Title
51-
title="Career Path"
52-
desc="Learning paths designed for different levels of builder"
53-
/>
54-
)}
49+
{titleData && <Title title={titleData.title} desc={titleData.desc} />}
5550
{/* <LearnNavBar /> */}
5651
<div className="relative flex max-md:overflow-x-hidden">
57-
<Filter type={params.type === 'courses' ? 'open_course' : params.type}>{params.type === 'challenges' && <ChallengesFilter />}</Filter>
52+
<Filter type={params.type === 'courses' ? 'open_course' : params.type}>
53+
{params.type === 'challenges' && <ChallengesFilter />}
54+
</Filter>
5855
<Suspense fallback={<ListSkeleton />}>
59-
<Container type={params.type} searchParams={searchParams} />
56+
<Container type={params.type} searchParams={searchParams} />
6057
</Suspense>
6158
</div>
6259
</div>

0 commit comments

Comments
 (0)