Files
otunes/apps/web/components/artist-view.tsx
T
joshuafhiggins 73c7283d4d Add Expo mobile app and extract shared Convex package
- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library)
- Move Convex backend to @otunes/convex for web and mobile reuse
- Update web app imports and API routes to use shared package
2026-08-02 04:14:01 +00:00

181 lines
6.5 KiB
TypeScript

"use client"
import * as React from "react"
import Image from "next/image"
import { Play, Shuffle } from "lucide-react"
import { useConvex } from "convex/react"
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 { ContentCarousel } from "@/components/content-carousel"
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 {
albumGridCarouselContentClassName,
albumGridCarouselSlideClassName,
albumGridClassName,
} from "@/lib/album-grid-classes"
import { artistCoverUrl } from "@/lib/cover-urls"
export function ArtistView({
artist,
albums,
recentlyAdded,
recentlyPlayed,
}: {
artist: BrowseArtist
albums: BrowseAlbum[]
recentlyAdded: BrowseAlbum[]
recentlyPlayed: BrowseAlbum[]
}) {
const { isArtistFavorite, toggleArtistFavorite } = useFavorites()
const { openAddArtistToPlaylist } = useAddToPlaylist()
const { playArtist, playArtistShuffled } = usePlayback()
const { runQueueAction } = useQueueMediaActions()
const convex = useConvex()
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 convex.query(
api.playlists.getOrderedArtistSongIds,
{ artistId: artist.id as Id<"artists"> }
)
void runQueueAction(action, songIds)
break
}
}
}
return (
<div className="flex h-svh flex-col">
<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"
priority
/>
</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">
{recentlyPlayed.length > 0 || recentlyAdded.length > 0 ? (
<div className="grid grid-cols-2 gap-6">
{recentlyPlayed.length > 0 ? (
<ContentCarousel
title="Recently Played"
content={recentlyPlayed.slice(0, 9)}
slideClassName={albumGridCarouselSlideClassName}
carouselContentClassName={albumGridCarouselContentClassName}
/>
) : (
<div />
)}
{recentlyAdded.length > 0 ? (
<ContentCarousel
title="Recently Added"
content={recentlyAdded.slice(0, 9)}
slideClassName={albumGridCarouselSlideClassName}
carouselContentClassName={albumGridCarouselContentClassName}
/>
) : (
<div />
)}
</div>
) : null}
<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>
)
}