Skip to content

Commit

Permalink
refactor(event): events list
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Apr 3, 2024
1 parent df460d4 commit 920d8ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
26 changes: 15 additions & 11 deletions src/app/events/Events.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 (
<section className={`${className} space-y-8`}>
{upcomingEvents.length > 0 && (
{UPCOMING_EVENTS.length > 0 && (
<>
<Title>{'Upcoming Events'}</Title>
{upcomingEvents.map((event, i) => (
<Title>Upcoming Events</Title>
{UPCOMING_EVENTS.map((event, i) => (
<EventCard key={i} index={i} event={event} />
))}
</>
)}

{pastEvents.length > 0 && (
{PAST_EVENTS.length > 0 && (
<>
<Title>{'Past Events'}</Title>
{pastEvents.map((event, i) => (
<EventCard key={i} index={i} event={event} isPastEvent={true} />
<Title>Past Events</Title>
{PAST_EVENTS.map((event, i) => (
<EventCard key={i} index={i} event={event} isPastEvent />
))}
</>
)}
Expand Down
23 changes: 0 additions & 23 deletions src/utils/get-events-date.ts

This file was deleted.

0 comments on commit 920d8ee

Please sign in to comment.