Skip to content

Commit 10c14fe

Browse files
committed
implementted the EventCard and updated the main page.tsx
1 parent ede3a2e commit 10c14fe

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// src/app/components/CalendarGrid.tsx
2+
"use client";
3+
import React from "react";
4+
import { format, startOfMonth, endOfMonth, addDays } from "date-fns";
5+
import EventCard from "./EventCard";
6+
7+
interface CalendarGridProps {
8+
currentDate: Date;
9+
}
10+
11+
export default function CalendarGrid({ currentDate }: CalendarGridProps) {
12+
const start = startOfMonth(currentDate);
13+
const end = endOfMonth(currentDate);
14+
15+
const days = [];
16+
for (let day = start; day <= end; day = addDays(day, 1)) {
17+
days.push(
18+
<div
19+
key={day.toString()}
20+
className="flex flex-col items-center justify-center p-4 border border-gray-300 rounded-lg bg-white shadow-sm hover:shadow-lg transition-all duration-200"
21+
>
22+
<div className="text-lg font-medium text-gray-800">{format(day, "d")}</div>
23+
{/* Event cards will be displayed here */}
24+
<div className="mt-2 text-sm text-gray-600">
25+
<EventCard event={{ id: "1", title: "Sample Event", date: day.toISOString() }} />
26+
</div>
27+
</div>
28+
);
29+
}
30+
31+
return (
32+
<div className="grid grid-cols-7 gap-4 w-full max-w-2xl mt-6">
33+
{days}
34+
</div>
35+
);
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// src/app/components/EventCard.tsx
2+
import React from "react";
3+
4+
interface Event {
5+
id: string;
6+
title: string;
7+
date: string;
8+
description?: string;
9+
}
10+
11+
interface EventCardProps {
12+
event: Event;
13+
}
14+
15+
export default function EventCard({ event }: EventCardProps) {
16+
return (
17+
<div className="p-2 bg-blue-100 rounded-md shadow-md">
18+
<h3 className="text-sm font-semibold text-blue-800">{event.title}</h3>
19+
<p className="text-xs text-gray-700">{event.description || "No description"}</p>
20+
</div>
21+
);
22+
}

nextjs-calendar/src/app/components/EventForm.tsx

Whitespace-only changes.

nextjs-calendar/src/app/event/[id]/page.tsx

Whitespace-only changes.

nextjs-calendar/src/app/page.tsx

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1+
// src/app/page.tsx
12
"use client";
23
import React, { useState } from "react";
3-
import { format, startOfMonth, endOfMonth, addMonths, subMonths, addDays } from "date-fns";
4+
import { format, addMonths, subMonths } from "date-fns";
5+
import CalendarGrid from "./components/CalendarGrid";
46

57
export default function CalendarPage() {
6-
// State for the current date
78
const [currentDate, setCurrentDate] = useState(new Date());
89

9-
// Functions to navigate months
1010
const handlePrevMonth = () => setCurrentDate(subMonths(currentDate, 1));
1111
const handleNextMonth = () => setCurrentDate(addMonths(currentDate, 1));
1212

1313
return (
1414
<main className="flex flex-col items-center p-6 bg-gray-100 min-h-screen">
1515
<header className="flex justify-between items-center w-full max-w-2xl mb-8">
16-
<button
17-
onClick={handlePrevMonth}
18-
className="px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300"
19-
>
16+
<button onClick={handlePrevMonth} className="px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300">
2017
Previous
2118
</button>
2219
<h2 className="text-2xl font-semibold text-gray-800">{format(currentDate, "MMMM yyyy")}</h2>
23-
<button
24-
onClick={handleNextMonth}
25-
className="px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300"
26-
>
20+
<button onClick={handleNextMonth} className="px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300">
2721
Next
2822
</button>
2923
</header>
@@ -32,30 +26,3 @@ export default function CalendarPage() {
3226
</main>
3327
);
3428
}
35-
36-
function CalendarGrid({ currentDate }: { currentDate: Date }) {
37-
const start = startOfMonth(currentDate);
38-
const end = endOfMonth(currentDate);
39-
40-
const days = [];
41-
for (let day = start; day <= end; day = addDays(day, 1)) {
42-
days.push(
43-
<div
44-
key={day.toString()}
45-
className="flex flex-col items-center justify-center p-4 border border-gray-300 rounded-lg bg-white shadow-sm hover:shadow-lg transition-all duration-200"
46-
>
47-
<div className="text-lg font-medium text-gray-800">{format(day, "d")}</div>
48-
{/* Placeholder for events */}
49-
<div className="mt-2 text-sm text-gray-600">
50-
<p>Sample Event</p>
51-
</div>
52-
</div>
53-
);
54-
}
55-
56-
return (
57-
<div className="grid grid-cols-7 gap-4 w-full max-w-2xl mt-6">
58-
{days}
59-
</div>
60-
);
61-
}

0 commit comments

Comments
 (0)