Skip to content

Commit e587ebf

Browse files
committed
feat: created programHorizontalList component and added to main page
1 parent 0bad25d commit e587ebf

File tree

4 files changed

+95
-55
lines changed

4 files changed

+95
-55
lines changed

src/app/api/program/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function GET(): Promise<NextResponse> {
1313
await connectDB();
1414

1515
try {
16-
const programs = await Program.find();
16+
const programs = await Program.find().sort({ date: 1 });
1717
return NextResponse.json({
1818
programs: programs,
1919
status: 200,

src/app/page.tsx

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,10 @@
11
import Image from "next/image";
22
import style from "./page.module.css";
3-
import ProgramCard from "@/components/Program";
4-
import connectDB from "@/database/db";
5-
import ProgramModel from "@/database/models/programSchema";
3+
import ProgramHorizontalList from "@/components/ProgramHorizontalList";
64

75
export const dynamic = "force-dynamic";
86

9-
type ProgramRecord = {
10-
imageURI: string;
11-
location: string;
12-
date: Date | string;
13-
duration: string;
14-
programName: string;
15-
programId: string;
16-
};
17-
18-
const formatProgramDate = (value: Date | string) => {
19-
const date = new Date(value);
20-
if (Number.isNaN(date.getTime())) {
21-
return "Date TBD";
22-
}
23-
24-
return date.toLocaleDateString("en-US", {
25-
month: "long",
26-
day: "numeric",
27-
year: "numeric",
28-
});
29-
};
30-
31-
const getPrograms = async (): Promise<ProgramRecord[]> => {
32-
try {
33-
await connectDB();
34-
return await ProgramModel.find().sort({ date: 1 }).lean<ProgramRecord[]>();
35-
} catch (error) {
36-
console.error("Error fetching programs for home page:", error);
37-
return [];
38-
}
39-
};
40-
417
export default async function Home() {
42-
const programs = await getPrograms();
43-
448
return (
459
<div className={style.pageContainer}>
4610
<header className={style.pageHeader}>
@@ -102,23 +66,7 @@ export default async function Home() {
10266

10367
<div className={style.programs}>
10468
<h2 className={style.sectionTitle}>Our Programs</h2>
105-
106-
<div className={style.programCards}>
107-
{programs.length > 0 ? (
108-
programs.map((program) => (
109-
<ProgramCard
110-
key={program.programId}
111-
image={program.imageURI}
112-
title={program.programName}
113-
location={program.location}
114-
date={formatProgramDate(program.date)}
115-
time={program.duration}
116-
/>
117-
))
118-
) : (
119-
<div className={style.programCard}>No programs available right now.</div>
120-
)}
121-
</div>
69+
<ProgramHorizontalList />
12270
</div>
12371

12472
<div className={style.pageFooter}>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import ProgramCard from "@/components/Program";
2+
import connectDB from "@/database/db";
3+
import ProgramModel from "@/database/models/programSchema";
4+
import style from "@/styles/ProgramHorizontalList.module.css";
5+
6+
type ProgramRecord = {
7+
imageURI: string;
8+
location: string;
9+
date: Date | string;
10+
duration: string;
11+
programName: string;
12+
programId: string;
13+
};
14+
15+
const formatProgramDate = (value: Date | string) => {
16+
const date = new Date(value);
17+
if (Number.isNaN(date.getTime())) {
18+
return "Date TBD";
19+
}
20+
21+
return date.toLocaleDateString("en-US", {
22+
month: "long",
23+
day: "numeric",
24+
year: "numeric",
25+
});
26+
};
27+
28+
const getPrograms = async (): Promise<ProgramRecord[]> => {
29+
try {
30+
await connectDB();
31+
return await ProgramModel.find().sort({ date: 1 }).lean<ProgramRecord[]>();
32+
} catch (error) {
33+
console.error("Error fetching programs for horizontal list:", error);
34+
return [];
35+
}
36+
};
37+
38+
const ProgramHorizontalList = async () => {
39+
const programs = await getPrograms();
40+
41+
if (programs.length === 0) {
42+
return <div className={style.emptyState}>No programs available right now.</div>;
43+
}
44+
45+
return (
46+
<div className={style.scrollFrame} aria-label="Programs">
47+
{programs.map((program) => (
48+
<div className={style.cardSlot} key={program.programId}>
49+
<ProgramCard
50+
image={program.imageURI}
51+
title={program.programName}
52+
location={program.location}
53+
date={formatProgramDate(program.date)}
54+
time={program.duration}
55+
/>
56+
</div>
57+
))}
58+
</div>
59+
);
60+
};
61+
62+
export default ProgramHorizontalList;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.scrollFrame {
2+
max-width: 1100px;
3+
margin: 48px auto 0;
4+
padding: 8px 4px 16px;
5+
display: grid;
6+
grid-auto-flow: column;
7+
grid-auto-columns: minmax(280px, 380px);
8+
gap: 24px;
9+
overflow-x: auto;
10+
overscroll-behavior-x: contain;
11+
scroll-snap-type: x mandatory;
12+
}
13+
14+
.cardSlot {
15+
scroll-snap-align: start;
16+
}
17+
18+
.emptyState {
19+
min-height: 280px;
20+
max-width: 1100px;
21+
margin: 48px auto 0;
22+
border-radius: 16px;
23+
background: #f1f5f9;
24+
display: grid;
25+
place-items: center;
26+
color: #4a5565;
27+
font-size: 18px;
28+
text-align: center;
29+
padding: 24px;
30+
}

0 commit comments

Comments
 (0)