mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
`/events` showed skeletons until a client-side request to the Luma events API finished, so the raw HTML had no upcoming events and every category count read zero. I moved the Luma fetch to the server next to the Notion and MDX loaders, so the HTML now includes the event list, and I set the page to revalidate every 5 minutes. **Changed:** - **Event list in the HTML**: I built `getLumaEvents` on the upstream fetch from `/api-v2/luma-events`, which I made shareable and gave a 10 s timeout, with the same public-only filter and mapping the client used. I removed the client fetch, the loading state and both skeletons. - **Luma failures**: on a missing API key, an upstream error or a timeout, `getLumaEvents` returns no Luma events and reports the error to Sentry, the same soft fallback the Notion loader uses, so neither the build nor a regeneration can fail on Luma. - **Dates without hydration mismatches**: I format each event's date and time in the event's own time zone on the server and the first client render (banner times carry the zone name, and the banner always shows the year). After hydration the page switches to the visitor's time zone, as before. **Note:** before JavaScript loads, visitors now see event-local times labeled with their zone where they used to see skeletons. If Luma is down during a regeneration, the page shows no Luma events until the next successful regeneration. ## To test Tested on the PR preview: - [x] Fetch `<preview-url>/api-v2/luma-events?after=<now>`, then fetch `<preview-url>/events` with a Chrome user agent, strip `<script>`, `<style>` and `<template>` elements and React's `<!-- -->` separators: expect every returned event name in the HTML, `All (N)` equal to the number of event cards (`h3.leading-snug`), and no `animate-pulse` skeletons (5/5 names, `All (5)` with 5 cards, 0 skeletons; a 6 PM Denver event groups under its own local date) - [x] Open `/events` in a browser outside UTC: expect no hydration errors in the console, banner times in local time without a zone label, and no request to `/api-v2/luma-events` (Asia/Singapore: none of either) - [x] Click a category filter, then All; search for a title word, then clear it; toggle On-demand: expect the list to narrow and restore as before, and the banner to hide on On-demand ## Linear - part of GROWTH-1416
168 lines
6.7 KiB
TypeScript
168 lines
6.7 KiB
TypeScript
'use client'
|
|
|
|
import { useEvents } from '~/app/events/context'
|
|
import { formatHosts, getEventTimeZone } from '~/lib/eventsUtils'
|
|
import { MapPinIcon, Rows3Icon, VideoIcon } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { Badge, Button, cn } from 'ui'
|
|
|
|
const CATEGORIES_FILTERS = [
|
|
{ name: 'All', value: 'all' },
|
|
{ name: 'Community Event', value: 'community' },
|
|
{ name: 'Meetup', value: 'meetup' },
|
|
{ name: 'Conference', value: 'conference' },
|
|
{ name: 'Workshop', value: 'workshop' },
|
|
{ name: 'Hackathon', value: 'hackathon' },
|
|
{ name: 'Webinar', value: 'webinar' },
|
|
]
|
|
|
|
export function EventList() {
|
|
const { filteredEvents, selectedCategories, isHydrated } = useEvents()
|
|
const isOnDemandView = selectedCategories.includes('on-demand')
|
|
|
|
const getCategoryLabel = (value: string) => {
|
|
const category = CATEGORIES_FILTERS.find((cat) => cat.value === value)
|
|
return category?.name || value
|
|
}
|
|
|
|
// Group events by date
|
|
const eventsByDate = filteredEvents.reduce(
|
|
(acc, event) => {
|
|
const eventDate = new Date(event.date).toLocaleDateString('en-US', {
|
|
weekday: 'long',
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
timeZone: getEventTimeZone(event.date, event.timezone, isHydrated),
|
|
})
|
|
|
|
if (!acc[eventDate]) {
|
|
acc[eventDate] = []
|
|
}
|
|
acc[eventDate].push(event)
|
|
return acc
|
|
},
|
|
{} as Record<string, typeof filteredEvents>
|
|
)
|
|
|
|
const hasEvents = Object.keys(eventsByDate).length > 0
|
|
const sortedDateGroups = Object.entries(eventsByDate).sort(([, eventsA], [, eventsB]) => {
|
|
if (!isOnDemandView) return 0
|
|
return new Date(eventsB[0].date).getTime() - new Date(eventsA[0].date).getTime()
|
|
})
|
|
|
|
return (
|
|
<div className="flex flex-col gap-y-8 min-h-72">
|
|
{sortedDateGroups.map(([date, events], index) => (
|
|
<div key={`group-${date}`} className="flex flex-col gap-y-2 relative">
|
|
<div
|
|
className={cn(
|
|
'absolute top-2 left-[-59px] rounded-full size-1.5',
|
|
index === 0 ? 'bg-brand-default size-2 left-[-60px]' : 'bg-foreground-muted'
|
|
)}
|
|
/>
|
|
|
|
<h3 className="text-foreground-light font-normal">{date}</h3>
|
|
|
|
<div className="flex flex-col gap-y-4">
|
|
{events.map((event, idx) => (
|
|
<div
|
|
key={`${idx}-${event.url}`}
|
|
className="bg-surface-100 border rounded-md p-3 flex justify-between items-start relative"
|
|
>
|
|
{event.url && (
|
|
<Link
|
|
className="inset-0 absolute"
|
|
href={event.disable_page_build ? event.url : event.path || event.url}
|
|
target={event.link?.target ?? '_self'}
|
|
rel={event.link?.target === '_blank' ? 'noopener noreferrer' : undefined}
|
|
title="Go to event page"
|
|
aria-hidden
|
|
/>
|
|
)}
|
|
|
|
<div className="flex flex-col gap-4 min-w-0 flex-1">
|
|
<div className="flex flex-col gap-2">
|
|
<h3 className="leading-snug">{event.title}</h3>
|
|
|
|
{event.end_date && (
|
|
<p className="text-xs text-foreground-light">
|
|
{new Date(event.date).toLocaleDateString('en-US', {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
timeZone: getEventTimeZone(event.date, event.timezone, isHydrated),
|
|
})}
|
|
{' - '}
|
|
{new Date(event.end_date).toLocaleDateString('en-US', {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
year: 'numeric',
|
|
timeZone: getEventTimeZone(event.end_date, event.timezone, isHydrated),
|
|
})}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
{event.categories?.includes('webinar') ? (
|
|
<div className="flex gap-2 items-center text-sm text-foreground-light">
|
|
<VideoIcon className="size-4 shrink-0" strokeWidth={1.5} />
|
|
Supabase Live
|
|
</div>
|
|
) : event.hosts.length > 0 ? (
|
|
<div className="flex gap-2 items-center text-sm text-foreground-light">
|
|
<div className="size-5 rounded-full border bg-linear-to-br from-background-surface-100 to-background-surface-200 relative">
|
|
{event.hosts[0]?.avatar_url && (
|
|
<img
|
|
src={event.hosts[0].avatar_url}
|
|
alt={event.hosts[0].name || 'Host image'}
|
|
className="absolute inset-0 w-full h-full object-cover rounded-full"
|
|
/>
|
|
)}
|
|
</div>
|
|
Hosted by {formatHosts(event.hosts).displayText}
|
|
</div>
|
|
) : event.source === 'notion' && event.location ? (
|
|
<div className="flex gap-2 items-center text-sm text-foreground-light">
|
|
<MapPinIcon className="size-4 shrink-0" strokeWidth={1.5} />
|
|
{event.location}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="flex flex-wrap items-center justify-end gap-2 shrink-0 relative z-10">
|
|
{event.meetingLink && (
|
|
<Button size="tiny" variant="secondary" asChild>
|
|
<Link href={event.meetingLink} target="_blank" rel="noopener noreferrer">
|
|
Meet with us
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
{event.onDemand && !isOnDemandView && <Badge variant="default">On-demand</Badge>}
|
|
{event.isSpeaking && <Badge variant="success">Speaking</Badge>}
|
|
{event.categories.slice(0, 3).map((tag, idx) => (
|
|
<Badge key={`tag-${idx}`}>{getCategoryLabel(tag)}</Badge>
|
|
))}
|
|
{event.categories.length > 3 && (
|
|
<Badge title={event.categories.slice(3).map(getCategoryLabel).join(', ')}>
|
|
+{event.categories.length - 3}
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
))}
|
|
|
|
{!hasEvents && (
|
|
<div className="self-center text-muted my-auto flex flex-col items-center gap-y-4">
|
|
<Rows3Icon className="size-8" />
|
|
<p className="">
|
|
{isOnDemandView ? 'No on-demand events found.' : 'Oops! No events found.'}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|