import { Suspense } from "react"; import SearchBar from "@/components/SearchBar"; import SongResult from "@/components/SongResult"; import { searchSongs as searchSongsDB } from "@/lib/db/client"; import { searchSongs as searchMB } from "@/lib/musicbrainz/client"; import { upsertSong } from "@/lib/db/client"; interface PageProps { searchParams: { q?: string }; } async function SearchResults({ q }: { q: string }) { // Try local DB first let songs = await searchSongsDB(q, 20); // If sparse results, hit MusicBrainz and cache locally if (songs.length < 3) { try { const mbResults = await searchMB(q, 20); for (const s of mbResults) { await upsertSong({ mbid: s.mbid, title: s.title, artist: s.artist, duration_seconds: s.duration_seconds, acousticbrainz_bpm: null, acousticbrainz_time_sig_num: null, source: "musicbrainz", }); } songs = await searchSongsDB(q, 20); } catch { // MusicBrainz unavailable — fall through with local results } } if (songs.length === 0) { return (
No results for “{q}”. Try a different search.
); } return (Find a song, download a click track. Built for cover bands.