"use client" import * as React from "react" import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command" import { Search, Music, MapPin, Calendar, Users, Globe, LayoutDashboard, Library, Star, History, ArrowRight } from "lucide-react" import { useRouter } from "next/navigation" import { getApiUrl } from "@/lib/api-config" import { Badge } from "@/components/ui/badge" export function SearchDialog() { const [open, setOpen] = React.useState(false) const [query, setQuery] = React.useState("") const [loading, setLoading] = React.useState(false) const [results, setResults] = React.useState({ songs: [], venues: [], tours: [], groups: [], users: [], nicknames: [], performances: [], }) const router = useRouter() React.useEffect(() => { const down = (e: KeyboardEvent) => { if (e.key === "k" && (e.metaKey || e.ctrlKey)) { e.preventDefault() setOpen((open) => !open) } } document.addEventListener("keydown", down) return () => document.removeEventListener("keydown", down) }, []) React.useEffect(() => { if (query.length < 2) { setResults({ songs: [], venues: [], tours: [], groups: [], users: [], nicknames: [], performances: [] }) return } setLoading(true) const timer = setTimeout(() => { fetch(`${getApiUrl()}/search/?q=${query}`) .then(res => res.json()) .then(data => { setResults(data) setLoading(false) }) .catch(err => { console.error(err) setLoading(false) }) }, 300) return () => clearTimeout(timer) }, [query]) const handleSelect = (url: string) => { setOpen(false) router.push(url) } return ( <> {loading ? (
Searching...
) : ( query.length >= 2 ? "No results found." : "Type at least 2 characters..." )}
{query.length < 2 && ( handleSelect("/shows")}> Browse Shows handleSelect("/leaderboards")}> Leaderboards handleSelect("/songs")}> Song Catalog handleSelect("/venues")}> Venues )} {results.songs?.length > 0 && ( {results.songs.map((song: any) => ( handleSelect(`/songs/${song.slug}`)}>
{song.title} {song.original_artist && ( Original by {song.original_artist} )}
))}
)} {results.venues?.length > 0 && ( {results.venues.map((venue: any) => ( handleSelect(`/venues/${venue.slug}`)}>
{venue.name} {venue.city}, {venue.state}
))}
)} {results.tours?.length > 0 && ( {results.tours.map((tour: any) => ( handleSelect(`/tours/${tour.slug}`)}> {tour.name} ))} )} {results.performances?.length > 0 && ( {results.performances.map((perf: any) => ( handleSelect(`/shows/${perf.show?.slug}`)}>
{perf.song?.title || "Unknown Song"} {perf.show?.date} • {perf.notes}
Performance
))}
)} {results.nicknames?.length > 0 && ( {results.nicknames.map((nickname: any) => ( handleSelect(`/shows/${nickname.performance?.show?.slug}`)}>
{nickname.nickname} ({nickname.performance?.song?.title} - {nickname.performance?.show?.date})
))}
)} {results.users?.length > 0 && ( {results.users.map((user: any) => ( handleSelect(`/profile/${user.id}`)}> {user.username || user.email.split('@')[0]} ))} )}
) }