154 lines
5.6 KiB
TypeScript
154 lines
5.6 KiB
TypeScript
"use client"
|
|
|
|
import { PageHeader } from "@/components/library-skeletons"
|
|
import * as React from "react"
|
|
import Image from "next/image"
|
|
import { Play, Shuffle } from "lucide-react"
|
|
import { useConvex } from "convex/react"
|
|
|
|
import { useCacheScope } from "@/components/persistent-cache-provider"
|
|
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
|
import { useFavorites } from "@/components/favorites-provider"
|
|
import { usePlayback } from "@/components/playback-provider"
|
|
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
|
import { AlbumCard } from "@/components/album-card"
|
|
import { FavoriteMediaButton } from "@/components/favorite-media-button"
|
|
import {
|
|
MediaContextMenu,
|
|
type MediaContextAction,
|
|
} from "@/components/media-context-menu"
|
|
import { Button } from "@/components/ui/button"
|
|
import { ScrollArea } from "@/components/ui/scroll-area"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import type { BrowseAlbum, BrowseArtist } from "@otunes/convex/types"
|
|
import { albumGridClassName } from "@/lib/album-grid-classes"
|
|
import { artistCoverUrl } from "@/lib/cover-urls"
|
|
import { fetchCachedQuery } from "@otunes/convex/client/cached-query"
|
|
|
|
export function ArtistView({
|
|
artist,
|
|
albums,
|
|
}: {
|
|
artist: BrowseArtist
|
|
albums: BrowseAlbum[]
|
|
}) {
|
|
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
|
|
const { openAddArtistToPlaylist } = useAddToPlaylist()
|
|
const { playArtist, playArtistShuffled } = usePlayback()
|
|
const { runQueueAction } = useQueueMediaActions()
|
|
const convex = useConvex()
|
|
const cacheScope = useCacheScope()
|
|
|
|
async function handleMediaAction(action: MediaContextAction) {
|
|
switch (action) {
|
|
case "favorite":
|
|
void toggleArtistFavorite(artist.id as Id<"artists">)
|
|
break
|
|
case "playlist":
|
|
void openAddArtistToPlaylist(artist.id as Id<"artists">)
|
|
break
|
|
case "play-next":
|
|
case "play-last":
|
|
case "shuffle": {
|
|
const songIds = await fetchCachedQuery(
|
|
convex,
|
|
cacheScope,
|
|
api.playlists.getOrderedArtistSongIds,
|
|
{ artistId: artist.id as Id<"artists"> }
|
|
)
|
|
void runQueueAction(action, songIds)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex h-svh flex-col">
|
|
<PageHeader />
|
|
<ScrollArea className="min-h-0 flex-1">
|
|
<div className="pb-28">
|
|
<div className="flex min-w-0 items-center gap-4 px-6 pt-6 pb-8 sm:gap-6">
|
|
<div className="relative size-32 shrink-0 overflow-hidden rounded-full ring-1 ring-foreground/10 sm:size-40">
|
|
<Image
|
|
src={artistCoverUrl(artist.id)}
|
|
alt={artist.name}
|
|
fill
|
|
sizes="160px"
|
|
className="object-cover"
|
|
preload
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
|
<h1 className="min-w-0 truncate text-3xl font-bold tracking-tight sm:text-4xl lg:text-5xl">
|
|
{artist.name}
|
|
</h1>
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Button
|
|
size="icon"
|
|
className="size-11 rounded-full"
|
|
aria-label={`Play ${artist.name}`}
|
|
onClick={() => void playArtist(artist.id as Id<"artists">)}
|
|
>
|
|
<Play className="size-5 fill-current" />
|
|
</Button>
|
|
<Button
|
|
variant="secondary"
|
|
size="icon"
|
|
className="size-11 rounded-full"
|
|
aria-label={`Shuffle ${artist.name}`}
|
|
onClick={() =>
|
|
void playArtistShuffled(artist.id as Id<"artists">)
|
|
}
|
|
>
|
|
<Shuffle className="size-4" />
|
|
</Button>
|
|
<FavoriteMediaButton
|
|
isFavorite={isArtistFavorite(artist.id)}
|
|
onToggle={() =>
|
|
void toggleArtistFavorite(artist.id as Id<"artists">)
|
|
}
|
|
favoritedLabel={`Remove ${artist.name} from favorites`}
|
|
unfavoritedLabel={`Favorite ${artist.name}`}
|
|
className="size-11"
|
|
/>
|
|
<MediaContextMenu
|
|
label={`More options for ${artist.name}`}
|
|
selectedCount={albums.length}
|
|
onOpenMenu={() => {}}
|
|
onAction={handleMediaAction}
|
|
favorited={isArtistFavorite(artist.id)}
|
|
trackRowTrigger={false}
|
|
triggerVariant="secondary"
|
|
triggerClassName="size-11 rounded-full"
|
|
triggerIconClassName="size-4"
|
|
share={{ type: "artist", artistId: artist.id }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="@container flex flex-col gap-10 px-6">
|
|
<section className="flex flex-col gap-4">
|
|
<h2 className="text-xl font-bold tracking-tight">Albums</h2>
|
|
{albums.length > 0 ? (
|
|
<div className={albumGridClassName}>
|
|
{albums.map((album) => (
|
|
<AlbumCard key={album.id} album={album} />
|
|
))}
|
|
</div>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">
|
|
No albums for this artist.
|
|
</p>
|
|
)}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</ScrollArea>
|
|
</div>
|
|
)
|
|
}
|