-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add related events section on event page (#207) #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # src/pages/events/[id]/index.astro
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughA new RelatedEvents component is introduced to display up to 3 related events from the same city on event detail pages. The event page template is updated to compute related events during static path generation and render them in a responsive grid above the community section. Changes
Sequence DiagramsequenceDiagram
participant Build as Build Process
participant GetStatic as getStaticPaths()
participant Filter as Event Filter
participant Page as Event Page Template
participant RelatedEvents as RelatedEvents Component
Build->>GetStatic: Generate static paths for all events
GetStatic->>Filter: For each event, filter by same city
Filter->>Filter: Sort by date, take top 3
GetStatic->>Page: Pass event + relatedEvents in props
Page->>RelatedEvents: Render with currentEvent and relatedEvents
RelatedEvents->>RelatedEvents: Map to EventCard grid (3 columns)
RelatedEvents->>Page: Display "More Events in {City}" section
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/pages/events/[id]/index.astro (1)
51-61: Simplify redundant date filter and fix sort order to prioritize future events.Two issues in the related events logic:
Redundant date condition: The OR condition
(dayjs(e.data.date).isAfter(dayjs()) || dayjs(e.data.date).isAfter(dayjs().subtract(30, "day")))is redundant since any date after now is also after 30 days ago. This simplifies to just the second condition.Sort order prioritizes past events: The ascending date sort means past events appear before future events. For a user viewing an event page, upcoming events in the same city are more relevant than recent past events.
Apply this diff to simplify the filter and prioritize future events:
const relatedEvents = allEvents .filter( (e) => e.id !== event.id && event.data._computed.city?.id !== undefined && e.data._computed.city?.id === event.data._computed.city?.id && - (dayjs(e.data.date).isAfter(dayjs()) || - dayjs(e.data.date).isAfter(dayjs().subtract(30, "day"))), + dayjs(e.data.date).isAfter(dayjs().subtract(30, "day")), ) - .sort((a, b) => dayjs(a.data.date).diff(dayjs(b.data.date))) + .sort((a, b) => { + const now = dayjs(); + const aIsFuture = dayjs(a.data.date).isAfter(now); + const bIsFuture = dayjs(b.data.date).isAfter(now); + // Prioritize future events over past events + if (aIsFuture && !bIsFuture) return -1; + if (!aIsFuture && bIsFuture) return 1; + // Within same category, sort by date (ascending for future, descending for past) + return dayjs(a.data.date).diff(dayjs(b.data.date)); + }) .slice(0, 3);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/RelatedEvents/index.astro(1 hunks)src/pages/events/[id]/index.astro(2 hunks)
🔇 Additional comments (4)
src/components/RelatedEvents/index.astro (1)
1-29: LGTM! Clean implementation of the RelatedEvents component.The component correctly handles conditional rendering, checking both for the presence of related events and the city name before displaying. The use of
client:visibleon TiltedCard ensures progressive rendering, and the responsive grid layout adapts well across screen sizes.src/pages/events/[id]/index.astro (3)
44-44: LGTM!
74-74: LGTM!Props destructuring correctly updated to include
relatedEvents.
696-697: LGTM! Well-positioned component.The RelatedEvents component is appropriately placed before the JoinTheCommunity section, and the props are correctly passed.
From #286
Changes
Close: #207
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.