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}
|
|
albums={albums}
|
|
artistId={artistIdFromPathname(pathname)}
|
|
onSelectArtist={selectArtist}
|
|
/>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|