diff --git a/src/app/events/Events.tsx b/src/app/events/Events.tsx index 3e7bd9d8..e19227c0 100644 --- a/src/app/events/Events.tsx +++ b/src/app/events/Events.tsx @@ -1,6 +1,5 @@ import FancyRectangle from '@/components/FancyRectangle'; import { EVENTS, type Event } from '@/data/events'; -import { getUpcomingEvents, getPastEvents } from '@/utils/get-events-date'; import Image from 'next/image'; import { FiClock, FiMapPin } from 'react-icons/fi'; @@ -76,26 +75,31 @@ function EventCard({ ); } +const getEventDate = (event: Event) => { + return new Date( + `${event.date.year} ${event.date.month} ${event.date.day} ${event.date.endTime}` + ); +}; +const CURRENT_DATE = new Date(); +const UPCOMING_EVENTS = EVENTS.filter((event) => getEventDate(event) >= CURRENT_DATE); +const PAST_EVENTS = EVENTS.filter((event) => getEventDate(event) < CURRENT_DATE); export default function Events({ className }: { className?: string }) { - const upcomingEvents = getUpcomingEvents(EVENTS); - const pastEvents = getPastEvents(EVENTS); - return (
- {upcomingEvents.length > 0 && ( + {UPCOMING_EVENTS.length > 0 && ( <> - {'Upcoming Events'} - {upcomingEvents.map((event, i) => ( + Upcoming Events + {UPCOMING_EVENTS.map((event, i) => ( ))} )} - {pastEvents.length > 0 && ( + {PAST_EVENTS.length > 0 && ( <> - {'Past Events'} - {pastEvents.map((event, i) => ( - + Past Events + {PAST_EVENTS.map((event, i) => ( + ))} )} diff --git a/src/utils/get-events-date.ts b/src/utils/get-events-date.ts deleted file mode 100644 index b6e40087..00000000 --- a/src/utils/get-events-date.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Event } from '@/data/events'; - -// Convert event date and return upcoming events -export function getUpcomingEvents(EVENTS: Event[]): Event[] { - const currentDate = new Date(); - return EVENTS.filter((event) => { - const eventDate = new Date( - `${event.date.year} ${event.date.month} ${event.date.day} ${event.date.endTime}` - ); - return eventDate >= currentDate; - }); -} - -// Convert event date and return past events with the most recent event first -export function getPastEvents(EVENTS: Event[]): Event[] { - const currentDate = new Date(); - return EVENTS.filter((event) => { - const eventDate = new Date( - `${event.date.year} ${event.date.month} ${event.date.day} ${event.date.endTime}` - ); - return eventDate < currentDate; - }).reverse(); -}