"use client" import { useEffect, useState } from "react" import { getApiUrl } from "@/lib/api-config" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import Link from "next/link" import { Map, Calendar } from "lucide-react" interface Tour { id: number name: string slug: string start_date: string end_date: string show_count: number } export default function ToursPage() { const [tours, setTours] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { fetch(`${getApiUrl()}/tours/?limit=200`) .then(res => res.json()) .then(data => { // Sort by start date descending const sorted = data.sort((a: Tour, b: Tour) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime() ) setTours(sorted) }) .catch(console.error) .finally(() => setLoading(false)) }, []) // Group tours by year const toursByYear = tours.reduce((acc, tour) => { const year = new Date(tour.start_date).getFullYear() if (!acc[year]) acc[year] = [] acc[year].push(tour) return acc }, {} as Record) const years = Object.keys(toursByYear).map(Number).sort((a, b) => b - a) if (loading) return
Loading tours...
return (

Tours

Follow the band across the country, tour by tour.

{years.map(year => (

{year}

{toursByYear[year].map((tour) => ( {tour.name} {tour.show_count} shows

{new Date(tour.start_date).toLocaleDateString("en-US", { month: "short", day: "numeric" })} {" - "} {new Date(tour.end_date).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })}

))}
))}
) }