Whole-library and favorites queries return lists split into chunks of at most 8,192 values, and search keeps the top 500 per section. Favorite writes and song detail lookups read whole ranges instead of one id at a time, and large unfavorites finish in scheduled batches, so they stay under Convex's 4,096 reads per function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
"use client"
|
|
|
|
import { usePathname } from "next/navigation"
|
|
import { useCallback } from "react"
|
|
|
|
import { ArtistsView } from "@/components/artists-view"
|
|
import { ArtistsSkeleton, PageHeader } from "@/components/library-skeletons"
|
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
|
|
const ARTISTS_PATH = "/library/artists"
|
|
|
|
function artistIdFromPathname(pathname: string) {
|
|
const [, id] = pathname.slice(ARTISTS_PATH.length).split("/")
|
|
return id ? decodeURIComponent(id) : undefined
|
|
}
|
|
|
|
export function ArtistsPage() {
|
|
const pathname = usePathname()
|
|
const artists = useCachedQuery(api.library.browseArtists)
|
|
const albums = useCachedQuery(api.library.browseAlbums)
|
|
|
|
const selectArtist = useCallback((artistId: string) => {
|
|
window.history.pushState(null, "", `${ARTISTS_PATH}/${artistId}`)
|
|
}, [])
|
|
|
|
return (
|
|
<div className="flex h-svh flex-col">
|
|
<PageHeader title="Artists" />
|
|
|
|
{artists === undefined || albums === undefined ? (
|
|
<ArtistsSkeleton />
|
|
) : (
|
|
<ArtistsView
|
|
artists={artists.flat()}
|
|
albums={albums.flat()}
|
|
artistId={artistIdFromPathname(pathname)}
|
|
onSelectArtist={selectArtist}
|
|
/>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|