generated from acm-ucr/acm-ucr-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from acm-ucr/dev
to main
- Loading branch information
Showing
21 changed files
with
406 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"use client"; | ||
|
||
import { useState, useEffect } from "react"; | ||
import Calendar from "./calendar/Calendar"; | ||
|
||
type CalendarEvent = { | ||
id: string; | ||
name: string; | ||
date: Date; | ||
location?: string; | ||
isAllDay: boolean; | ||
details?: string; | ||
title: string; | ||
}; | ||
|
||
type GoogleCalendarEvent = { | ||
id: string; | ||
summary: string; | ||
start: { | ||
dateTime?: string; | ||
date?: string; | ||
}; | ||
location?: string; | ||
description?: string; | ||
}; | ||
|
||
const Events = () => { | ||
const [currentMonth, setCurrentMonth] = useState(new Date()); | ||
const [events, setEvents] = useState<CalendarEvent[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const handleMonthChange = (newDate: Date) => { | ||
setCurrentMonth(newDate); | ||
}; | ||
|
||
useEffect(() => { | ||
const fetchGoogleCalendarEvents = async () => { | ||
setLoading(true); | ||
|
||
const startDate = new Date( | ||
currentMonth.getFullYear(), | ||
currentMonth.getMonth(), | ||
1, | ||
).toISOString(); | ||
const endDate = new Date( | ||
currentMonth.getFullYear(), | ||
currentMonth.getMonth() + 1, | ||
0, | ||
).toISOString(); | ||
|
||
try { | ||
const res = await fetch( | ||
`https://www.googleapis.com/calendar/v3/calendars/${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_EMAIL}/events?key=${process.env.NEXT_PUBLIC_GOOGLE_CALENDAR_API_KEY}&singleEvents=true&orderBy=startTime&timeMin=${startDate}&timeMax=${endDate}&maxResults=10`, | ||
); | ||
|
||
const data = await res.json(); | ||
|
||
console.log("API Response:", data); | ||
|
||
if (data.items) { | ||
const eventsData = data.items.map((event: GoogleCalendarEvent) => ({ | ||
id: event.id, | ||
name: event.summary, | ||
date: new Date(event.start.dateTime ?? event.start.date ?? ""), | ||
location: event.location, | ||
isAllDay: !event.start.dateTime, | ||
details: event.description, | ||
})); | ||
|
||
setEvents(eventsData); | ||
} else { | ||
console.error("No events found in the API response."); | ||
setEvents([]); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching events:", error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchGoogleCalendarEvents(); | ||
}, [currentMonth]); | ||
|
||
return ( | ||
<div className="flex min-h-screen flex-col items-center"> | ||
{loading ? ( | ||
<p className="text-center text-lg md:text-xl lg:text-2xl"> | ||
Loading events... | ||
</p> | ||
) : ( | ||
<Calendar | ||
currentMonth={currentMonth} | ||
events={events} | ||
onMonthChange={handleMonthChange} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import Events from "./Events"; | ||
|
||
const WrappedEvents = () => { | ||
return ( | ||
<div className="flex min-h-screen flex-col px-1 py-1"> | ||
<div className="w-full min-w-[300px] max-w-4xl rounded-lg p-4"> | ||
<Events /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WrappedEvents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import CustomHeader from "./CustomHeader"; | ||
import CustomToolbar from "./CustomToolbar"; | ||
import CustomEvents from "./CustomEvents"; | ||
|
||
interface Event { | ||
id: string; | ||
name: string; | ||
date: Date; | ||
location?: string; | ||
isAllDay: boolean; | ||
details?: string; | ||
title: string; | ||
} | ||
|
||
interface CalendarProps { | ||
currentMonth: Date; | ||
events: Event[]; | ||
onMonthChange: (date: Date) => void; | ||
} | ||
|
||
const Calendar = ({ currentMonth, events, onMonthChange }: CalendarProps) => { | ||
return ( | ||
<div className="relative mx-auto flex w-full max-w-4xl flex-col overflow-hidden rounded-3xl border-4 border-isa-dark-red bg-isa-beige-100 bg-opacity-80 p-5 text-center shadow-lg drop-shadow-md backdrop-blur-0"> | ||
<CustomHeader currentMonth={currentMonth} /> | ||
<CustomToolbar | ||
onMonthChange={onMonthChange} | ||
currentMonth={currentMonth} | ||
/> | ||
<div className="mt-4"> | ||
<CustomEvents currentMonth={currentMonth} events={events} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Calendar; |
Oops, something went wrong.