import { dateLocaleCode } from '@/lib/dateFnsI18n'; import { useMemo } from 'react'; import { Link } from 'react-router-dom'; import { Calendar, Users, Pencil, Megaphone, Plus, CalendarClock } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useSkateEvents } from '@/hooks/useSkateEvents'; import { useEventRsvps, eventCoord } from '@/hooks/useEventRsvps'; import { cn } from '@/lib/utils'; import type { SkateEvent } from '@/lib/types'; function formatWhen(ts: number): string { return new Date(ts * 1000).toLocaleDateString(dateLocaleCode(), { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', }); } /** A single hosted-event row with live RSVP counts + quick actions. */ function HostedEventRow({ event, isPast }: { event: SkateEvent; isPast: boolean }) { const { goingCount, tentativeCount } = useEventRsvps(eventCoord(event)); const to = `/event/${event.pubkey}/${event.identifier}`; return ( {/* Date chip */}
{new Date(event.start * 1000).toLocaleDateString(dateLocaleCode(), { month: 'short' })}
{new Date(event.start * 1000).getDate()}
{/* Info */}

{event.title}

{formatWhen(event.start)}

{goingCount} going {tentativeCount > 0 && ( {tentativeCount} interested )}
{/* Quick actions */}
); } /** * "Hosting" dashboard — the events the logged-in user created, split into * upcoming and past, each with live RSVP counts and quick edit/update actions. * The host's home base. */ export function HostingDashboard() { const { user } = useCurrentUser(); const { data: events, isLoading } = useSkateEvents(200); const now = Math.floor(Date.now() / 1000); const mine = useMemo(() => { if (!user || !events) return { upcoming: [], past: [] }; const owned = events.filter((e) => e.pubkey === user.pubkey); return { upcoming: owned.filter((e) => e.start >= now).sort((a, b) => a.start - b.start), past: owned.filter((e) => e.start < now).sort((a, b) => b.start - a.start), }; }, [user, events, now]); if (!user) { return (

Log in to see the events you're hosting.

); } if (isLoading) { return (
{[0, 1, 2].map((i) => ( ))}
); } const total = mine.upcoming.length + mine.past.length; if (total === 0) { return (

You're not hosting anything yet

Run a jam, comp or session. Create an event and skaters can RSVP, get updates, and roll through.

); } return (
{mine.upcoming.length > 0 && (

Upcoming · {mine.upcoming.length}

{mine.upcoming.map((e) => ( ))}
)} {mine.past.length > 0 && (

Past · {mine.past.length}

{mine.past.map((e) => ( ))}
)}
); }