feat: hook it all up to the data
This commit is contained in:
41 files changed
+2447
-398
No files matched your search
@@ -0,0 +1,37 @@
|
||||
"use client"
|
||||
|
||||
import { useParams } from "next/navigation"
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumView } from "@/components/album-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import type { AlbumDetail } from "@/lib/data"
|
||||
|
||||
export default function Page() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const album = useQuery(api.library.browseAlbumDetail, {
|
||||
id: id as Id<"albums">,
|
||||
})
|
||||
|
||||
if (album === undefined) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<LibraryLoading />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (album === null) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<div className="flex flex-1 items-center justify-center pb-28">
|
||||
<p className="text-sm text-muted-foreground">Album not found.</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return <AlbumView album={album as AlbumDetail} />
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { serveCoverFile } from "@/lib/serve-cover"
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params
|
||||
|
||||
try {
|
||||
const album = await getConvexClient().query(api.library.getAlbum, {
|
||||
id: id as Id<"albums">,
|
||||
})
|
||||
return serveCoverFile(album?.cover)
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { getConvexClient } from "@/lib/convex-server"
|
||||
import { serveCoverFile } from "@/lib/serve-cover"
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params
|
||||
|
||||
try {
|
||||
const artist = await getConvexClient().query(api.library.getArtist, {
|
||||
id: id as Id<"artists">,
|
||||
})
|
||||
return serveCoverFile(artist?.cover)
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// import { api } from "@/convex/_generated/api"
|
||||
// import type { Id } from "@/convex/_generated/dataModel"
|
||||
// import { getConvexClient } from "@/lib/convex-server"
|
||||
import { PLACEHOLDER_PATH, serveCoverFile } from "@/lib/serve-cover"
|
||||
import fs from "node:fs/promises"
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
// const { id } = await params
|
||||
// try {
|
||||
// const album = await getConvexClient().query(api.library.getAlbum, {
|
||||
// id: id as Id<"albums">,
|
||||
// })
|
||||
// return serveCoverFile(album?.cover)
|
||||
// } catch {
|
||||
// return new Response("Not found", { status: 404 })
|
||||
// }
|
||||
|
||||
const placeholder = await fs.readFile(PLACEHOLDER_PATH)
|
||||
return new Response(placeholder, {
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
"use client"
|
||||
|
||||
import { useParams } from "next/navigation"
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { ArtistView } from "@/components/artist-view"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
|
||||
export default function Page() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const data = useQuery(api.library.browseArtistDetail, {
|
||||
id: id as Id<"artists">,
|
||||
})
|
||||
|
||||
if (data === undefined) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<LibraryLoading />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<div className="flex flex-1 items-center justify-center pb-28">
|
||||
<p className="text-sm text-muted-foreground">Artist not found.</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ArtistView
|
||||
artist={data.artist}
|
||||
albums={data.albums}
|
||||
recentlyAdded={data.recentlyAdded}
|
||||
recentlyPlayed={data.recentlyPlayed}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -80,6 +80,7 @@
|
||||
--sidebar-accent-foreground: oklch(0.216 0.006 56.043);
|
||||
--sidebar-border: oklch(0.923 0.003 48.717);
|
||||
--sidebar-ring: oklch(0.709 0.01 56.259);
|
||||
--media-menu-highlight: color-mix(in oklch, var(--primary) 32%, var(--popover));
|
||||
}
|
||||
|
||||
.dark {
|
||||
@@ -114,6 +115,17 @@
|
||||
--sidebar-accent-foreground: oklch(0.985 0.001 106.423);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.553 0.013 58.071);
|
||||
--media-menu-highlight: color-mix(in oklch, var(--primary) 58%, var(--popover));
|
||||
}
|
||||
|
||||
.media-context-menu-trigger[data-state="open"] {
|
||||
background-color: var(--media-menu-highlight) !important;
|
||||
color: var(--foreground) !important;
|
||||
}
|
||||
|
||||
.media-context-menu-trigger[data-state="open"]:hover {
|
||||
background-color: var(--media-menu-highlight) !important;
|
||||
color: var(--foreground) !important;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
|
||||
+14
-9
@@ -1,11 +1,13 @@
|
||||
import { Geist, Geist_Mono, Inter } from "next/font/google"
|
||||
|
||||
import "./globals.css"
|
||||
import { ConvexClientProvider } from "@/components/convex-client-provider"
|
||||
import { ThemeProvider } from "@/components/theme-provider"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
||||
import { AppSidebar } from "@/components/app-sidebar"
|
||||
import { PlayerBar } from "@/components/player-bar"
|
||||
import { Toaster } from "@/components/ui/sonner"
|
||||
import type { Metadata } from "next"
|
||||
|
||||
const inter = Inter({ subsets: ["latin"], variable: "--font-sans" })
|
||||
@@ -37,15 +39,18 @@ export default function RootLayout({
|
||||
)}
|
||||
>
|
||||
<body className={"overflow-x-hidden"}>
|
||||
<ThemeProvider>
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<SidebarInset>
|
||||
{children}
|
||||
<PlayerBar />
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
</ThemeProvider>
|
||||
<ConvexClientProvider>
|
||||
<ThemeProvider>
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<SidebarInset>
|
||||
{children}
|
||||
<PlayerBar />
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
</ConvexClientProvider>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
|
||||
@@ -1,20 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { albums } from "@/lib/data"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Albums</h1>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
{albums === undefined ? (
|
||||
<LibraryLoading />
|
||||
) : (
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,26 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { ArtistsView } from "@/components/artists-view"
|
||||
import { albums, artists } from "@/lib/data"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const artists = useQuery(api.library.browseArtists)
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Artists</h1>
|
||||
</header>
|
||||
|
||||
<ArtistsView artists={artists} albums={albums} />
|
||||
{artists === undefined || albums === undefined ? (
|
||||
<LibraryLoading />
|
||||
) : (
|
||||
<ArtistsView artists={artists} albums={albums} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { SongsView } from "@/components/songs-view"
|
||||
import { songs } from "@/lib/data"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const songs = useQuery(api.library.browseSongs)
|
||||
|
||||
if (songs === undefined) {
|
||||
return <LibraryLoading />
|
||||
}
|
||||
|
||||
return <SongsView songs={songs} />
|
||||
}
|
||||
+20
-3
@@ -1,9 +1,26 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { ContentCarousel } from "@/components/content-carousel"
|
||||
import { recentlyAdded, recentlyPlayed } from "@/lib/data"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const recentlyAdded = useQuery(api.library.browseRecentlyAdded)
|
||||
const recentlyPlayed = useQuery(api.library.browseAlbums)
|
||||
|
||||
if (recentlyAdded === undefined || recentlyPlayed === undefined) {
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Home</h1>
|
||||
</header>
|
||||
<LibraryLoading />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
@@ -15,12 +32,12 @@ export default function Page() {
|
||||
<ContentCarousel
|
||||
title="Recently Played"
|
||||
href="/recently-played"
|
||||
content={recentlyPlayed}
|
||||
content={recentlyPlayed.slice(0, 9)}
|
||||
/>
|
||||
<ContentCarousel
|
||||
title="Recently Added"
|
||||
href="/recently-added"
|
||||
content={recentlyAdded}
|
||||
content={recentlyAdded.slice(0, 9)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,20 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { albums } from "@/lib/data"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseRecentlyAdded)
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Recently Added</h1>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
{albums === undefined ? (
|
||||
<LibraryLoading />
|
||||
) : (
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,20 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import { useQuery } from "convex/react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { albums } from "@/lib/data"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export default function Page() {
|
||||
const albums = useQuery(api.library.browseAlbums)
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center gap-2 border-b px-4 py-3">
|
||||
<h1 className="text-lg font-semibold">Recently Played</h1>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
{albums === undefined ? (
|
||||
<LibraryLoading />
|
||||
) : (
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+98
-11
@@ -1,31 +1,118 @@
|
||||
"use client"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { albums } from "@/lib/data"
|
||||
import { useDeferredValue, useState } from "react"
|
||||
import { useQuery } from "convex/react"
|
||||
import { SearchIcon } from "lucide-react"
|
||||
|
||||
import { ContentCarousel } from "@/components/content-carousel"
|
||||
import { LibraryLoading } from "@/components/library-loading"
|
||||
import { SearchSongItem } from "@/components/search-song-item"
|
||||
import { placeholderPlaylists } from "@/lib/playlists"
|
||||
import { SearchTopResultCard, type TopResult } from "@/components/search-top-result-card"
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { Album, Artist, Song } from "@/lib/data"
|
||||
|
||||
export default function Page() {
|
||||
const [query, setQuery] = useState("")
|
||||
const deferredQuery = useDeferredValue(query.trim())
|
||||
const hasQuery = deferredQuery.length > 0
|
||||
|
||||
const results = useQuery(
|
||||
api.library.searchLibrary,
|
||||
hasQuery ? { query: deferredQuery } : "skip"
|
||||
)
|
||||
|
||||
const showPlaylists = hasQuery && results !== undefined
|
||||
const isSearching = hasQuery && results === undefined
|
||||
const hasLibraryResults =
|
||||
results &&
|
||||
(results.topResults.length > 0 ||
|
||||
results.artists.length > 0 ||
|
||||
results.albums.length > 0 ||
|
||||
results.songs.length > 0)
|
||||
const showResults = hasQuery && results !== undefined
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-around gap-2 border-b px-4 py-2">
|
||||
<div className="relative w-full max-w-md">
|
||||
<header className="flex items-center justify-center border-b px-4 py-3">
|
||||
<div className="relative w-full max-w-xl">
|
||||
<SearchIcon className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="search"
|
||||
data-slot="input"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Search"
|
||||
className="h-9 w-full min-w-0 rounded-full border border-input bg-input/30 pr-3 pl-9 text-sm text-foreground transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||
className="h-10 w-full min-w-0 rounded-full border border-input bg-input/30 pr-3 pl-9 text-sm text-foreground transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{albums.map((album) => (
|
||||
<AlbumCard key={album.id} album={album} />
|
||||
))}
|
||||
{isSearching ? (
|
||||
<LibraryLoading />
|
||||
) : !hasQuery ? (
|
||||
<div className="flex flex-1 items-center justify-center px-6 pb-28">
|
||||
<p className="text-center text-muted-foreground">
|
||||
Search for songs, albums, artists, and playlists in your library.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
) : !showResults ? null : (
|
||||
<div className="flex-1 overflow-y-auto p-6 pb-28">
|
||||
<div className="mx-auto flex max-w-6xl flex-col gap-10">
|
||||
{!hasLibraryResults && (
|
||||
<p className="text-muted-foreground">
|
||||
No library results for “{deferredQuery}”
|
||||
</p>
|
||||
)}
|
||||
|
||||
{results.topResults.length > 0 && (
|
||||
<section className="flex flex-col gap-4">
|
||||
<h2 className="text-xl font-bold tracking-tight">Top Results</h2>
|
||||
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{results.topResults.map((result) => (
|
||||
<SearchTopResultCard
|
||||
key={`${result.kind}-${result.item.id}`}
|
||||
result={result as TopResult}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{results.artists.length > 0 && (
|
||||
<ContentCarousel
|
||||
title="Artists"
|
||||
content={results.artists as Artist[]}
|
||||
/>
|
||||
)}
|
||||
|
||||
{results.albums.length > 0 && (
|
||||
<ContentCarousel
|
||||
title="Albums"
|
||||
content={results.albums as Album[]}
|
||||
/>
|
||||
)}
|
||||
|
||||
{results.songs.length > 0 && (
|
||||
<section className="flex flex-col gap-4">
|
||||
<h2 className="text-xl font-bold tracking-tight">Songs</h2>
|
||||
<div className="grid gap-x-6 gap-y-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{results.songs.map((song) => (
|
||||
<SearchSongItem key={song.id} song={song as Song} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{showPlaylists && (
|
||||
<ContentCarousel
|
||||
title="Playlists"
|
||||
content={placeholderPlaylists}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+17
-22
@@ -20,31 +20,23 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import type { Album } from "@/lib/data"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function AlbumCard({ album }: { album: Album }) {
|
||||
return (
|
||||
<div className="group flex flex-col gap-2">
|
||||
<div className="relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="group relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
|
||||
<Link
|
||||
className="absolute inset-0"
|
||||
href={"/library/album/" + album.id}
|
||||
href={"/album/" + album.id}
|
||||
>
|
||||
{album.cover ? (
|
||||
<Image
|
||||
src={album.cover}
|
||||
alt={album.title}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Image
|
||||
src="/placeholder-album.svg"
|
||||
alt={album.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
/>
|
||||
)}
|
||||
<Image
|
||||
src={albumCoverUrl(album.id)}
|
||||
alt={album.title}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
</Link>
|
||||
|
||||
<div className="pointer-events-none absolute inset-0 bg-black/0 transition-colors group-hover:bg-black/40" />
|
||||
@@ -96,11 +88,14 @@ export function AlbumCard({ album }: { album: Album }) {
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<Link href={"/library/album/" + album.id}>
|
||||
<Link href={"/album/" + album.id} className="hover:underline">
|
||||
<p className="truncate text-sm font-medium">{album.title}</p>
|
||||
</Link>
|
||||
<Link href={"/library/artist/" + album.artist.id}>
|
||||
<p className="truncate text-xs text-muted-foreground">
|
||||
<Link
|
||||
href={"/artist/" + album.artist.id}
|
||||
className="text-muted-foreground decoration-muted-foreground hover:underline"
|
||||
>
|
||||
<p className="truncate text-xs">
|
||||
{album.artist.name}
|
||||
</p>
|
||||
</Link>
|
||||
|
||||
@@ -0,0 +1,416 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { Play, Share2, Shuffle, Star } from "lucide-react"
|
||||
|
||||
import { FavoriteMediaButton } from "@/components/favorite-media-button"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import {
|
||||
MediaContextMenu,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { AlbumDetail, AlbumTrack } from "@/lib/data"
|
||||
import {
|
||||
getSelectionRangePositions,
|
||||
isInSelectionRange,
|
||||
ALBUM_TRACK_ROW,
|
||||
ALBUM_TRACK_TITLE,
|
||||
SelectionRangeHighlight,
|
||||
TRACK_LIST_CONTAINER,
|
||||
TrackRowActiveHighlight,
|
||||
TrackRowHoverHighlight,
|
||||
TRACK_ROW_PADDING,
|
||||
type SelectionRangePosition,
|
||||
} from "@/lib/selection-range-styles"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const remainingSeconds = seconds % 60
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
||||
}
|
||||
|
||||
function albumUrl(albumId: string) {
|
||||
return `${window.location.origin}/album/${albumId}`
|
||||
}
|
||||
|
||||
async function copyAlbumLink(albumId: string) {
|
||||
await navigator.clipboard.writeText(albumUrl(albumId))
|
||||
toast.success("Link Copied")
|
||||
}
|
||||
|
||||
function formatMetadata(genre: string | null, year: number | null): string | null {
|
||||
const parts: string[] = []
|
||||
if (genre) {
|
||||
parts.push(genre)
|
||||
}
|
||||
if (year) {
|
||||
parts.push(String(year))
|
||||
}
|
||||
return parts.length > 0 ? parts.join(" · ") : null
|
||||
}
|
||||
|
||||
function TrackRow({
|
||||
track,
|
||||
index,
|
||||
isActive,
|
||||
isSelected,
|
||||
selectionPosition,
|
||||
isFavorite,
|
||||
selectedCount,
|
||||
onSelect,
|
||||
onPointerDown,
|
||||
onToggleFavorite,
|
||||
onPrepareContextMenu,
|
||||
onMediaAction,
|
||||
}: {
|
||||
track: AlbumTrack
|
||||
index: number
|
||||
isActive: boolean
|
||||
isSelected: boolean
|
||||
selectionPosition: SelectionRangePosition
|
||||
isFavorite: boolean
|
||||
selectedCount: number
|
||||
onSelect: (event: React.MouseEvent) => void
|
||||
onPointerDown: (event: React.MouseEvent) => void
|
||||
onToggleFavorite: () => void
|
||||
onPrepareContextMenu: () => void
|
||||
onMediaAction: (action: MediaContextAction, trackId: string) => void
|
||||
}) {
|
||||
const displayTrack = track.track > 0 ? track.track : index + 1
|
||||
const inRange = isInSelectionRange(selectionPosition)
|
||||
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onMouseDown={onPointerDown}
|
||||
onClick={onSelect}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault()
|
||||
onSelect(event as unknown as React.MouseEvent)
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"group relative w-full cursor-pointer select-none py-2.5 text-left text-sm transition-colors",
|
||||
inRange && "text-primary-foreground"
|
||||
)}
|
||||
>
|
||||
<SelectionRangeHighlight position={selectionPosition} />
|
||||
{!inRange && isActive ? <TrackRowActiveHighlight /> : null}
|
||||
{!inRange && !isActive ? <TrackRowHoverHighlight /> : null}
|
||||
<div
|
||||
className={cn("relative z-10", ALBUM_TRACK_ROW, TRACK_ROW_PADDING)}
|
||||
>
|
||||
<div className="flex shrink-0 items-center gap-x-3">
|
||||
<div className="flex items-center justify-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className={cn(
|
||||
"size-8 opacity-0 transition-opacity group-hover:opacity-100",
|
||||
inRange
|
||||
? "text-primary-foreground hover:bg-white/15 hover:text-primary-foreground"
|
||||
: "text-primary hover:text-primary",
|
||||
(isFavorite || isActive || isSelected) && "opacity-100"
|
||||
)}
|
||||
aria-label={
|
||||
isFavorite
|
||||
? `Remove ${track.title} from favorites`
|
||||
: `Favorite ${track.title}`
|
||||
}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
onToggleFavorite()
|
||||
}}
|
||||
>
|
||||
<Star
|
||||
className={cn(
|
||||
"size-4",
|
||||
isFavorite && (inRange ? "fill-current" : "fill-primary")
|
||||
)}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center tabular-nums",
|
||||
inRange ? "text-primary-foreground" : "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{isActive ? (
|
||||
<Play
|
||||
className={cn(
|
||||
"size-4 fill-current",
|
||||
inRange ? "text-primary-foreground" : "text-primary"
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<span>{displayTrack}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<span className={ALBUM_TRACK_TITLE}>{track.title}</span>
|
||||
</div>
|
||||
|
||||
<div className="min-w-4 flex-1" />
|
||||
|
||||
<div className="flex shrink-0 items-center gap-x-3">
|
||||
<span
|
||||
className={cn(
|
||||
"text-right tabular-nums",
|
||||
inRange ? "text-primary-foreground" : "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{formatDuration(track.durationSeconds)}
|
||||
</span>
|
||||
|
||||
<MediaContextMenu
|
||||
label={`More options for ${track.title}`}
|
||||
selectedCount={selectedCount}
|
||||
onOpenMenu={onPrepareContextMenu}
|
||||
onAction={(action) => onMediaAction(action, track.id)}
|
||||
triggerClassName={cn(
|
||||
"size-8 shrink-0 transition-opacity",
|
||||
inRange
|
||||
? "text-primary-foreground opacity-100 hover:bg-white/15 hover:text-primary-foreground"
|
||||
: "opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function AlbumView({ album }: { album: AlbumDetail }) {
|
||||
const metadata = formatMetadata(album.genre, album.year)
|
||||
const [activeTrackId, setActiveTrackId] = React.useState(
|
||||
() => album.tracks[0]?.id ?? ""
|
||||
)
|
||||
const [isAlbumFavorite, setIsAlbumFavorite] = React.useState(false)
|
||||
const [favoriteIds, setFavoriteIds] = React.useState<Set<string>>(
|
||||
() => new Set()
|
||||
)
|
||||
|
||||
const {
|
||||
selectedIds,
|
||||
selectedCount,
|
||||
isSelected,
|
||||
handleSelect,
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(album.tracks)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() => getSelectionRangePositions(album.tracks.map((track) => track.id), selectedIds),
|
||||
[album.tracks, selectedIds]
|
||||
)
|
||||
|
||||
function toggleFavorite(trackId: string) {
|
||||
setFavoriteIds((current) => {
|
||||
const next = new Set(current)
|
||||
if (next.has(trackId)) {
|
||||
next.delete(trackId)
|
||||
} else {
|
||||
next.add(trackId)
|
||||
}
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
function handleMediaAction(
|
||||
action: MediaContextAction,
|
||||
fallbackTrackId?: string
|
||||
) {
|
||||
const targetIds =
|
||||
selectedIds.size > 0
|
||||
? Array.from(selectedIds)
|
||||
: fallbackTrackId
|
||||
? [fallbackTrackId]
|
||||
: activeTrackId
|
||||
? [activeTrackId]
|
||||
: []
|
||||
const count = targetIds.length
|
||||
|
||||
switch (action) {
|
||||
case "favorite":
|
||||
setFavoriteIds((current) => {
|
||||
const next = new Set(current)
|
||||
for (const id of targetIds) {
|
||||
next.add(id)
|
||||
}
|
||||
return next
|
||||
})
|
||||
toast.success(
|
||||
count > 1 ? `Favorited ${count} songs` : "Added to favorites"
|
||||
)
|
||||
break
|
||||
case "playlist":
|
||||
toast.success(
|
||||
count > 1
|
||||
? `Added ${count} songs to playlist`
|
||||
: "Added to playlist"
|
||||
)
|
||||
break
|
||||
case "play-next":
|
||||
toast.success(
|
||||
count > 1 ? `Queued ${count} songs to play next` : "Play next"
|
||||
)
|
||||
break
|
||||
case "play-last":
|
||||
toast.success(
|
||||
count > 1 ? `Queued ${count} songs to play last` : "Play last"
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function handleAlbumMediaAction(action: MediaContextAction) {
|
||||
const targetIds = album.tracks.map((track) => track.id)
|
||||
const count = targetIds.length
|
||||
|
||||
switch (action) {
|
||||
case "favorite":
|
||||
setIsAlbumFavorite(true)
|
||||
setFavoriteIds(new Set(targetIds))
|
||||
toast.success(`Favorited ${count} songs`)
|
||||
break
|
||||
case "playlist":
|
||||
toast.success(`Added ${count} songs to playlist`)
|
||||
break
|
||||
case "play-next":
|
||||
toast.success(`Queued ${count} songs to play next`)
|
||||
break
|
||||
case "play-last":
|
||||
toast.success(`Queued ${count} songs to play last`)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div className="flex items-center justify-end gap-1 px-6 pt-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Share album"
|
||||
onClick={() => copyAlbumLink(album.id)}
|
||||
>
|
||||
<Share2 />
|
||||
</Button>
|
||||
<MediaContextMenu
|
||||
label="More album options"
|
||||
selectedCount={album.tracks.length}
|
||||
onOpenMenu={() => {}}
|
||||
onAction={handleAlbumMediaAction}
|
||||
triggerClassName="size-8"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-8 px-6 pt-2 pb-8 sm:flex-row sm:items-end">
|
||||
<div className="relative mx-auto aspect-square w-full max-w-60 shrink-0 overflow-hidden rounded-lg ring-1 ring-foreground/10 sm:mx-0">
|
||||
<Image
|
||||
src={albumCoverUrl(album.id)}
|
||||
alt={album.title}
|
||||
fill
|
||||
sizes="240px"
|
||||
className="object-cover"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
||||
<div className="space-y-1 text-center sm:text-left">
|
||||
<p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
|
||||
Album
|
||||
</p>
|
||||
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
||||
{album.title}
|
||||
</h1>
|
||||
<Link
|
||||
href={"/artist/" + album.artist.id}
|
||||
className="inline-block text-lg font-semibold text-primary hover:underline"
|
||||
>
|
||||
{album.artist.name}
|
||||
</Link>
|
||||
{metadata ? (
|
||||
<p className="text-sm text-muted-foreground">{metadata}</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Shuffle album"
|
||||
>
|
||||
<Shuffle />
|
||||
</Button>
|
||||
<Button
|
||||
className="h-10 gap-2 rounded-full bg-foreground px-6 text-background hover:bg-foreground/90"
|
||||
aria-label={`Play ${album.title}`}
|
||||
>
|
||||
<Play className="fill-current" />
|
||||
Play
|
||||
</Button>
|
||||
<FavoriteMediaButton
|
||||
isFavorite={isAlbumFavorite}
|
||||
onToggle={() => setIsAlbumFavorite((current) => !current)}
|
||||
favoritedLabel={`Remove ${album.title} from favorites`}
|
||||
unfavoritedLabel={`Favorite ${album.title}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto w-full max-w-8/10">
|
||||
{album.tracks.length > 0 ? (
|
||||
album.tracks.map((track, index) => (
|
||||
<TrackRow
|
||||
key={track.id}
|
||||
track={track}
|
||||
index={index}
|
||||
isActive={track.id === activeTrackId}
|
||||
isSelected={isSelected(track.id)}
|
||||
selectionPosition={selectionPositions[index]}
|
||||
isFavorite={favoriteIds.has(track.id)}
|
||||
selectedCount={
|
||||
isSelected(track.id) && selectedCount > 0
|
||||
? selectedCount
|
||||
: 1
|
||||
}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={(event) => {
|
||||
handleSelect(track.id, index, event)
|
||||
setActiveTrackId(track.id)
|
||||
}}
|
||||
onToggleFavorite={() => toggleFavorite(track.id)}
|
||||
onPrepareContextMenu={() => prepareContextMenu(track.id)}
|
||||
onMediaAction={handleMediaAction}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<p className="px-6 py-8 text-sm text-muted-foreground">
|
||||
No tracks in this album.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { useTheme } from "next-themes"
|
||||
import * as React from "react"
|
||||
import { placeholderPlaylists } from "@/lib/playlists"
|
||||
|
||||
const browse = [
|
||||
{ title: "Home", path: "/", icon: House },
|
||||
@@ -43,11 +44,11 @@ const library = [
|
||||
|
||||
const playlists = [
|
||||
{ title: "All Playlists", path: "/playlists", icon: ListMusic },
|
||||
{ title: "Favorite Songs", path: "/playlist/Favorite Songs", icon: ListMusic },
|
||||
{ title: "Choir & Bands", path: "/playlist/Choir & Bands", icon: ListMusic },
|
||||
{ title: "Plays", path: "/playlist/Plays", icon: ListMusic },
|
||||
{ title: "Sea Shanties", path: "/playlist/Sea Shanties", icon: ListMusic },
|
||||
{ title: "Stay Civilized", path: "/playlist/Stay Civilized", icon: ListMusic },
|
||||
...placeholderPlaylists.map((playlist) => ({
|
||||
title: playlist.title,
|
||||
path: playlist.path,
|
||||
icon: ListMusic,
|
||||
})),
|
||||
]
|
||||
|
||||
export function AppSidebar() {
|
||||
|
||||
+10
-18
@@ -4,33 +4,25 @@ import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { Artist } from "@/lib/data"
|
||||
import { artistCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function ArtistCard({ artist }: { artist: Artist }) {
|
||||
return (
|
||||
<div className="group flex flex-col items-center gap-2">
|
||||
<Link
|
||||
className="relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-full ring-1 ring-foreground/10"
|
||||
href={"/library/artist/" + artist.id}
|
||||
href={"/artist/" + artist.id}
|
||||
>
|
||||
{artist.photo ? (
|
||||
<Image
|
||||
src={artist.photo}
|
||||
alt={artist.name}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Image
|
||||
src="/placeholder-album.svg"
|
||||
alt={artist.name}
|
||||
fill
|
||||
className="object-cover"
|
||||
/>
|
||||
)}
|
||||
<Image
|
||||
src={artistCoverUrl(artist.id)}
|
||||
alt={artist.name}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
</Link>
|
||||
<div className="min-w-0">
|
||||
<Link href={"/library/artist/" + artist.id}>
|
||||
<Link href={"/artist/" + artist.id} className="hover:underline">
|
||||
<p className="truncate text-center text-sm font-medium">
|
||||
{artist.name}
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import { Play, Shuffle } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
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 type { Album, Artist } from "@/lib/data"
|
||||
import {
|
||||
albumGridCarouselContentClassName,
|
||||
albumGridCarouselSlideClassName,
|
||||
albumGridClassName,
|
||||
} from "@/lib/album-grid-classes"
|
||||
import { artistCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function ArtistView({
|
||||
artist,
|
||||
albums,
|
||||
recentlyAdded,
|
||||
recentlyPlayed,
|
||||
}: {
|
||||
artist: Artist
|
||||
albums: Album[]
|
||||
recentlyAdded: Album[]
|
||||
recentlyPlayed: Album[]
|
||||
}) {
|
||||
const [isFavorite, setIsFavorite] = React.useState(false)
|
||||
|
||||
function handleMediaAction(action: MediaContextAction) {
|
||||
switch (action) {
|
||||
case "favorite":
|
||||
setIsFavorite(true)
|
||||
toast.success("Added artist to favorites")
|
||||
break
|
||||
case "playlist":
|
||||
toast.success("Added to playlist")
|
||||
break
|
||||
case "play-next":
|
||||
toast.success("Play next")
|
||||
break
|
||||
case "play-last":
|
||||
toast.success("Play last")
|
||||
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}`}
|
||||
>
|
||||
<Play className="size-5 fill-current" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="size-11 rounded-full"
|
||||
aria-label={`Shuffle ${artist.name}`}
|
||||
>
|
||||
<Shuffle className="size-4" />
|
||||
</Button>
|
||||
<FavoriteMediaButton
|
||||
isFavorite={isFavorite}
|
||||
onToggle={() => setIsFavorite((current) => !current)}
|
||||
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}
|
||||
triggerVariant="secondary"
|
||||
triggerClassName="size-11 rounded-full"
|
||||
triggerIconClassName="size-4"
|
||||
/>
|
||||
</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>
|
||||
)
|
||||
}
|
||||
+25
-17
@@ -3,24 +3,21 @@
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import {
|
||||
ChevronRightIcon,
|
||||
Play,
|
||||
Shuffle,
|
||||
Star,
|
||||
} from "lucide-react"
|
||||
import { ChevronRightIcon, Play, Shuffle } from "lucide-react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import { FavoriteMediaButton } from "@/components/favorite-media-button"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Album, Artist } from "@/lib/data"
|
||||
import { artistCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
function ArtistAvatar({ artist }: { artist: Artist }) {
|
||||
return (
|
||||
<div className="relative size-8 shrink-0 overflow-hidden rounded-full ring-1 ring-foreground/10">
|
||||
<Image
|
||||
src={artist.photo ?? "/placeholder-album.svg"}
|
||||
src={artistCoverUrl(artist.id)}
|
||||
alt={artist.name}
|
||||
fill
|
||||
className="object-cover"
|
||||
@@ -68,6 +65,9 @@ export function ArtistsView({
|
||||
const [selectedId, setSelectedId] = React.useState(
|
||||
() => sortedArtists[0]?.id ?? ""
|
||||
)
|
||||
const [favoriteIds, setFavoriteIds] = React.useState<Set<string>>(
|
||||
() => new Set()
|
||||
)
|
||||
|
||||
const selectedArtist = sortedArtists.find(
|
||||
(artist) => artist.id === selectedId
|
||||
@@ -94,8 +94,8 @@ export function ArtistsView({
|
||||
<div className="pb-28">
|
||||
<div className="flex min-w-0 items-center justify-between gap-4 border-b px-6 py-4">
|
||||
<Link
|
||||
href={`/artists/${selectedArtist.id}`}
|
||||
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight"
|
||||
href={`/artist/${selectedArtist.id}`}
|
||||
className="group inline-flex min-w-0 flex-1 items-center gap-1 text-xl font-bold tracking-tight hover:underline"
|
||||
>
|
||||
<span className="min-w-0 truncate">{selectedArtist.name}</span>
|
||||
<ChevronRightIcon className="size-5 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
@@ -113,14 +113,22 @@ export function ArtistsView({
|
||||
>
|
||||
<Shuffle />
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="icon"
|
||||
className="rounded-full"
|
||||
aria-label="Favorite"
|
||||
>
|
||||
<Star />
|
||||
</Button>
|
||||
<FavoriteMediaButton
|
||||
isFavorite={favoriteIds.has(selectedArtist.id)}
|
||||
onToggle={() =>
|
||||
setFavoriteIds((current) => {
|
||||
const next = new Set(current)
|
||||
if (next.has(selectedArtist.id)) {
|
||||
next.delete(selectedArtist.id)
|
||||
} else {
|
||||
next.add(selectedArtist.id)
|
||||
}
|
||||
return next
|
||||
})
|
||||
}
|
||||
favoritedLabel={`Remove ${selectedArtist.name} from favorites`}
|
||||
unfavoritedLabel={`Favorite ${selectedArtist.name}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import Link from "next/link"
|
||||
import { ChevronRightIcon } from "lucide-react"
|
||||
|
||||
import { AlbumCard } from "@/components/album-card"
|
||||
import type { Album, Artist } from "@/lib/data"
|
||||
import type { Album, Artist, Playlist } from "@/lib/data"
|
||||
import {
|
||||
Carousel,
|
||||
CarouselContent,
|
||||
@@ -12,26 +12,48 @@ import {
|
||||
CarouselNext,
|
||||
CarouselPrevious,
|
||||
} from "@/components/ui/carousel"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ArtistCard } from "./artist-card"
|
||||
import { PlaylistCard } from "./playlist-card"
|
||||
|
||||
function CarouselCard({ item }: { item: Album | Artist | Playlist }) {
|
||||
if ("owner" in item) {
|
||||
return <PlaylistCard playlist={item} />
|
||||
}
|
||||
if ("artist" in item) {
|
||||
return <AlbumCard album={item} />
|
||||
}
|
||||
return <ArtistCard artist={item} />
|
||||
}
|
||||
|
||||
export function ContentCarousel({
|
||||
title,
|
||||
href,
|
||||
content,
|
||||
className,
|
||||
slideClassName = "basis-1/2 pl-4 sm:basis-1/3 md:basis-1/4 lg:basis-1/5 xl:basis-1/6",
|
||||
carouselContentClassName,
|
||||
}: {
|
||||
title: string
|
||||
href: string
|
||||
content: (Album | Artist)[]
|
||||
href?: string
|
||||
content: (Album | Artist | Playlist)[]
|
||||
className?: string
|
||||
slideClassName?: string
|
||||
carouselContentClassName?: string
|
||||
}) {
|
||||
return (
|
||||
<section className="flex flex-col gap-4">
|
||||
<Link
|
||||
href={href}
|
||||
className="group inline-flex w-fit items-center gap-1 text-xl font-bold tracking-tight"
|
||||
>
|
||||
{title}
|
||||
<ChevronRightIcon className="size-5 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
<section className={cn("flex min-w-0 flex-col gap-4", className)}>
|
||||
{href ? (
|
||||
<Link
|
||||
href={href}
|
||||
className="group inline-flex w-fit items-center gap-1 text-xl font-bold tracking-tight"
|
||||
>
|
||||
{title}
|
||||
<ChevronRightIcon className="size-5 text-muted-foreground transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
) : (
|
||||
<h2 className="text-xl font-bold tracking-tight">{title}</h2>
|
||||
)}
|
||||
|
||||
<Carousel
|
||||
opts={{
|
||||
@@ -40,25 +62,20 @@ export function ContentCarousel({
|
||||
containScroll: false,
|
||||
slidesToScroll: 5,
|
||||
}}
|
||||
className=""
|
||||
className="relative min-w-0"
|
||||
>
|
||||
<CarouselContent className="w-full">
|
||||
{content.map((card) => (
|
||||
<CarouselItem
|
||||
key={card.id}
|
||||
className="basis-1/2 pl-4 sm:basis-1/3 md:basis-1/4 lg:basis-1/5 xl:basis-1/6"
|
||||
>
|
||||
{"artist" in card ? (
|
||||
<AlbumCard album={card as Album} />
|
||||
) : (
|
||||
<ArtistCard artist={card as Artist} />
|
||||
)}
|
||||
<CarouselContent
|
||||
className={cn("w-full", carouselContentClassName)}
|
||||
>
|
||||
{content.map((item) => (
|
||||
<CarouselItem key={item.id} className={slideClassName}>
|
||||
<CarouselCard item={item} />
|
||||
</CarouselItem>
|
||||
))}
|
||||
</CarouselContent>
|
||||
<div className="absolute top-1/2 flex w-1/2 -translate-y-1/2 justify-between sm:w-2/3 md:w-3/4 lg:w-4/5 xl:w-5/6">
|
||||
<CarouselPrevious className="relative -left-4 h-16 w-6 bg-primary/90 opacity-0 hover:opacity-100 disabled:opacity-0" />
|
||||
<CarouselNext className="relative -right-2 h-16 w-6 bg-primary/90 opacity-0 hover:opacity-100 disabled:opacity-0" />
|
||||
<div className="pointer-events-none absolute top-1/2 flex w-1/2 -translate-y-1/2 justify-between sm:w-2/3 md:w-3/4 lg:w-4/5 xl:w-5/6">
|
||||
<CarouselPrevious className="relative -left-4 h-16 w-6 bg-primary/90 opacity-0 pointer-events-none hover:pointer-events-auto hover:opacity-100 disabled:pointer-events-none disabled:opacity-0" />
|
||||
<CarouselNext className="relative -right-2 h-16 w-6 bg-primary/90 opacity-0 pointer-events-none hover:pointer-events-auto hover:opacity-100 disabled:pointer-events-none disabled:opacity-0" />
|
||||
</div>
|
||||
</Carousel>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
"use client"
|
||||
|
||||
import { ConvexProvider, ConvexReactClient } from "convex/react"
|
||||
|
||||
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!)
|
||||
|
||||
export function ConvexClientProvider({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return <ConvexProvider client={convex}>{children}</ConvexProvider>
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
"use client"
|
||||
|
||||
import { Star } from "lucide-react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
type FavoriteMediaButtonProps = {
|
||||
isFavorite: boolean
|
||||
onToggle: () => void
|
||||
favoritedLabel: string
|
||||
unfavoritedLabel: string
|
||||
className?: string
|
||||
iconClassName?: string
|
||||
}
|
||||
|
||||
export function FavoriteMediaButton({
|
||||
isFavorite,
|
||||
onToggle,
|
||||
favoritedLabel,
|
||||
unfavoritedLabel,
|
||||
className,
|
||||
iconClassName = "size-4",
|
||||
}: FavoriteMediaButtonProps) {
|
||||
return (
|
||||
<Button
|
||||
variant={isFavorite ? "default" : "secondary"}
|
||||
size="icon"
|
||||
className={cn(
|
||||
"rounded-full",
|
||||
!isFavorite &&
|
||||
"hover:bg-primary hover:text-primary-foreground hover:border-transparent",
|
||||
className
|
||||
)}
|
||||
aria-label={isFavorite ? favoritedLabel : unfavoritedLabel}
|
||||
aria-pressed={isFavorite}
|
||||
onClick={onToggle}
|
||||
>
|
||||
<Star className={cn(iconClassName, isFavorite && "fill-current")} />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
|
||||
export function LibraryLoading() {
|
||||
return (
|
||||
<div className="flex flex-1 items-center justify-center p-6 pb-28">
|
||||
<Spinner className="size-6 text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
ListEnd,
|
||||
ListPlus,
|
||||
ListStart,
|
||||
MoreHorizontal,
|
||||
Star,
|
||||
} from "lucide-react"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export type MediaContextAction = "playlist" | "play-next" | "play-last" | "favorite"
|
||||
|
||||
function actionLabel(base: string, selectedCount: number) {
|
||||
return selectedCount > 1 ? `${base} (${selectedCount})` : base
|
||||
}
|
||||
|
||||
export function MediaContextMenuItems({
|
||||
selectedCount,
|
||||
onAction,
|
||||
}: {
|
||||
selectedCount: number
|
||||
onAction: (action: MediaContextAction) => void
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<DropdownMenuItem
|
||||
className="justify-between"
|
||||
onClick={() => onAction("playlist")}
|
||||
>
|
||||
{actionLabel("Add to Playlist", selectedCount)}
|
||||
<ListPlus />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="justify-between"
|
||||
onClick={() => onAction("play-next")}
|
||||
>
|
||||
{actionLabel("Play Next", selectedCount)}
|
||||
<ListStart />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="justify-between"
|
||||
onClick={() => onAction("play-last")}
|
||||
>
|
||||
{actionLabel("Play Last", selectedCount)}
|
||||
<ListEnd />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="justify-between"
|
||||
onClick={() => onAction("favorite")}
|
||||
>
|
||||
{actionLabel("Favorite", selectedCount)}
|
||||
<Star />
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function MediaContextMenu({
|
||||
label,
|
||||
selectedCount,
|
||||
onOpenMenu,
|
||||
onAction,
|
||||
triggerClassName,
|
||||
triggerVariant = "ghost",
|
||||
triggerIconClassName = "size-4",
|
||||
align = "end",
|
||||
}: {
|
||||
label: string
|
||||
selectedCount: number
|
||||
onOpenMenu: () => void
|
||||
onAction: (action: MediaContextAction) => void
|
||||
triggerClassName?: string
|
||||
triggerVariant?: "ghost" | "secondary"
|
||||
triggerIconClassName?: string
|
||||
align?: "start" | "end"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenu
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
onOpenMenu()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant={triggerVariant}
|
||||
size="icon"
|
||||
className={cn("media-context-menu-trigger", triggerClassName)}
|
||||
aria-label={label}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<MoreHorizontal className={triggerIconClassName} />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align={align} className="w-48">
|
||||
<MediaContextMenuItems
|
||||
selectedCount={selectedCount}
|
||||
onAction={onAction}
|
||||
/>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
"use client"
|
||||
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { Playlist } from "@/lib/data"
|
||||
import { albumCoverUrl, playlistCoverUrl } from "@/lib/cover-urls"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ListEnd, ListPlus, ListStart, MoreHorizontal, Play, Star } from "lucide-react"
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||
|
||||
export function PlaylistCard({ playlist }: { playlist: Playlist }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="group relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
|
||||
<Link className="absolute inset-0" href={"/playlist/" + playlist.id}>
|
||||
<Image
|
||||
src={playlistCoverUrl(playlist.id)}
|
||||
alt={playlist.title}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
||||
className="object-cover"
|
||||
/>
|
||||
</Link>
|
||||
|
||||
<div className="pointer-events-none absolute inset-0 bg-black/0 transition-colors group-hover:bg-black/40" />
|
||||
|
||||
<div className="absolute inset-x-0 bottom-0 z-10 flex items-center justify-between p-2 opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<Button
|
||||
size="icon-sm"
|
||||
className="rounded-full"
|
||||
aria-label={`Play ${playlist.title}`}
|
||||
onClick={(event) => event.preventDefault()}
|
||||
>
|
||||
<Play className="fill-current" />
|
||||
</Button>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="rounded-full text-white hover:bg-white/20 hover:text-white"
|
||||
aria-label={`More options for ${playlist.title}`}
|
||||
onClick={(event) => event.preventDefault()}
|
||||
>
|
||||
<MoreHorizontal />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Add to Playlist
|
||||
<ListPlus />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Play Next
|
||||
<ListStart />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Play Last
|
||||
<ListEnd />
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<Link href={"/playlist/" + playlist.id} className="hover:underline">
|
||||
<p className="truncate text-sm font-medium">{playlist.title}</p>
|
||||
</Link>
|
||||
<p className="truncate text-xs text-muted-foreground decoration-muted-foreground">
|
||||
{playlist.owner}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client"
|
||||
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import {
|
||||
MediaContextMenu,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import type { Song } from "@/lib/data"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
|
||||
export function SearchSongItem({ song }: { song: Song }) {
|
||||
function handleAction(action: MediaContextAction) {
|
||||
switch (action) {
|
||||
case "playlist":
|
||||
toast.success("Added to playlist")
|
||||
break
|
||||
case "play-next":
|
||||
toast.success("Playing next")
|
||||
break
|
||||
case "play-last":
|
||||
toast.success("Added to queue")
|
||||
break
|
||||
case "favorite":
|
||||
toast.success("Added to favorites")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="group flex items-center gap-3 rounded-lg px-1 py-1.5 transition-colors hover:bg-muted/50">
|
||||
<Link
|
||||
href={`/album/${song.album.id}`}
|
||||
className="relative size-11 shrink-0 overflow-hidden rounded ring-1 ring-foreground/10"
|
||||
>
|
||||
<Image
|
||||
src={albumCoverUrl(song.album.id)}
|
||||
alt={song.album.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
/>
|
||||
</Link>
|
||||
|
||||
<div className="min-w-0 flex-1">
|
||||
<Link href={`/album/${song.album.id}`} className="hover:underline">
|
||||
<p className="truncate text-sm font-medium">{song.title}</p>
|
||||
</Link>
|
||||
<Link
|
||||
href={`/artist/${song.artist.id}`}
|
||||
className="text-muted-foreground hover:text-foreground hover:underline"
|
||||
>
|
||||
<p className="truncate text-sm">{song.artist.name}</p>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<MediaContextMenu
|
||||
label={`More options for ${song.title}`}
|
||||
selectedCount={1}
|
||||
onOpenMenu={() => {}}
|
||||
onAction={handleAction}
|
||||
triggerClassName="size-8 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 data-[state=open]:opacity-100"
|
||||
triggerVariant="ghost"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
"use client"
|
||||
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
|
||||
import type { Album, Artist, Song } from "@/lib/data"
|
||||
import { albumCoverUrl, artistCoverUrl } from "@/lib/cover-urls"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export type TopResult =
|
||||
| { kind: "song"; item: Song }
|
||||
| { kind: "album"; item: Album }
|
||||
| { kind: "artist"; item: Artist }
|
||||
|
||||
function resultHref(result: TopResult) {
|
||||
switch (result.kind) {
|
||||
case "song":
|
||||
return `/album/${result.item.album.id}`
|
||||
case "album":
|
||||
return `/album/${result.item.id}`
|
||||
case "artist":
|
||||
return `/artist/${result.item.id}`
|
||||
}
|
||||
}
|
||||
|
||||
function resultImage(result: TopResult) {
|
||||
switch (result.kind) {
|
||||
case "song":
|
||||
return {
|
||||
src: albumCoverUrl(result.item.album.id),
|
||||
alt: result.item.album.title,
|
||||
rounded: false,
|
||||
}
|
||||
case "album":
|
||||
return {
|
||||
src: albumCoverUrl(result.item.id),
|
||||
alt: result.item.title,
|
||||
rounded: false,
|
||||
}
|
||||
case "artist":
|
||||
return {
|
||||
src: artistCoverUrl(result.item.id),
|
||||
alt: result.item.name,
|
||||
rounded: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resultTitle(result: TopResult) {
|
||||
switch (result.kind) {
|
||||
case "song":
|
||||
return result.item.title
|
||||
case "album":
|
||||
return result.item.title
|
||||
case "artist":
|
||||
return result.item.name
|
||||
}
|
||||
}
|
||||
|
||||
function resultSubtitle(result: TopResult) {
|
||||
switch (result.kind) {
|
||||
case "song":
|
||||
return `Song • ${result.item.artist.name}`
|
||||
case "album":
|
||||
return `Album • ${result.item.artist.name}`
|
||||
case "artist":
|
||||
return "Artist"
|
||||
}
|
||||
}
|
||||
|
||||
export function SearchTopResultCard({ result }: { result: TopResult }) {
|
||||
const image = resultImage(result)
|
||||
|
||||
return (
|
||||
<Link
|
||||
href={resultHref(result)}
|
||||
className="group flex items-center gap-3 rounded-xl bg-muted/40 p-2 transition-colors hover:bg-muted/70"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"relative size-14 shrink-0 overflow-hidden ring-1 ring-foreground/10",
|
||||
image.rounded ? "rounded-full" : "rounded-md"
|
||||
)}
|
||||
>
|
||||
<Image src={image.src} alt={image.alt} fill className="object-cover" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate font-medium">{resultTitle(result)}</p>
|
||||
<p className="truncate text-sm text-muted-foreground">
|
||||
{resultSubtitle(result)}
|
||||
</p>
|
||||
<p className="mt-0.5 text-[10px] font-medium tracking-wide text-muted-foreground uppercase">
|
||||
From Your Library
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
+266
-118
@@ -2,27 +2,25 @@
|
||||
|
||||
import * as React from "react"
|
||||
import Image from "next/image"
|
||||
import {
|
||||
ArrowUpDown,
|
||||
ListEnd,
|
||||
ListPlus,
|
||||
ListStart,
|
||||
MoreHorizontal,
|
||||
Play,
|
||||
Star,
|
||||
} from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { ArrowUpDown, Play, Star } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import {
|
||||
MediaContextMenu,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import {
|
||||
Table,
|
||||
@@ -34,12 +32,25 @@ import {
|
||||
} from "@/components/ui/table"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Song } from "@/lib/data"
|
||||
import { albumCoverUrl } from "@/lib/cover-urls"
|
||||
import {
|
||||
getSelectionRangePositions,
|
||||
isInSelectionRange,
|
||||
ALBUM_TRACK_TITLE,
|
||||
SongsSelectionRangeHighlight,
|
||||
SongsTrackRowHoverHighlight,
|
||||
TRACK_ROW_PADDING,
|
||||
type SelectionRangePosition,
|
||||
} from "@/lib/selection-range-styles"
|
||||
|
||||
type SortKey = "title" | "artist" | "album"
|
||||
type SortDirection = "asc" | "desc"
|
||||
|
||||
const songRowLayout =
|
||||
"flex w-full items-center gap-x-4"
|
||||
const nameColumnLayout =
|
||||
"grid grid-cols-[2rem_2.5rem_minmax(0,1fr)_2rem] items-center gap-x-2"
|
||||
"grid grid-cols-[2rem_2.5rem_minmax(0,10rem)] items-center gap-x-2"
|
||||
const songColumnClass = "w-36 shrink-0 truncate"
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
@@ -47,49 +58,16 @@ function formatDuration(seconds: number): string {
|
||||
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
||||
}
|
||||
|
||||
function SongContextMenu({ song }: { song: Song }) {
|
||||
function SongCover({ song, inRange }: { song: Song; inRange: boolean }) {
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="size-8 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 data-[state=open]:opacity-100"
|
||||
aria-label={`More options for ${song.title}`}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<MoreHorizontal className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-48">
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Add to Playlist
|
||||
<ListPlus />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Play Next
|
||||
<ListStart />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Play Last
|
||||
<ListEnd />
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="justify-between">
|
||||
Favorite
|
||||
<Star />
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
|
||||
function SongCover({ song }: { song: Song }) {
|
||||
return (
|
||||
<div className="relative size-10 shrink-0 overflow-hidden rounded ring-1 ring-foreground/10">
|
||||
<div
|
||||
className={cn(
|
||||
"relative size-10 shrink-0 overflow-hidden rounded ring-1",
|
||||
inRange ? "ring-white/25" : "ring-foreground/10"
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
src={song.album.cover ?? "/placeholder-album.svg"}
|
||||
src={albumCoverUrl(song.album.id)}
|
||||
alt={song.album.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
@@ -99,7 +77,10 @@ function SongCover({ song }: { song: Song }) {
|
||||
size="icon-sm"
|
||||
className="size-7 rounded-full opacity-0 transition-opacity group-hover:opacity-100"
|
||||
aria-label={`Play ${song.title}`}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onClick={(event) => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}}
|
||||
>
|
||||
<Play className="size-3 fill-current" />
|
||||
</Button>
|
||||
@@ -111,68 +92,142 @@ function SongCover({ song }: { song: Song }) {
|
||||
function SongRow({
|
||||
song,
|
||||
index,
|
||||
isSelected,
|
||||
selectionPosition,
|
||||
isFavorite,
|
||||
selectedCount,
|
||||
onSelect,
|
||||
onPointerDown,
|
||||
onToggleFavorite,
|
||||
onPrepareContextMenu,
|
||||
onMediaAction,
|
||||
}: {
|
||||
song: Song
|
||||
index: number
|
||||
isSelected: boolean
|
||||
selectionPosition: SelectionRangePosition
|
||||
isFavorite: boolean
|
||||
selectedCount: number
|
||||
onSelect: (event: React.MouseEvent) => void
|
||||
onPointerDown: (event: React.MouseEvent) => void
|
||||
onToggleFavorite: () => void
|
||||
onPrepareContextMenu: () => void
|
||||
onMediaAction: (action: MediaContextAction, songId: string) => void
|
||||
}) {
|
||||
const inRange = isInSelectionRange(selectionPosition)
|
||||
const linkClass = inRange
|
||||
? "text-primary-foreground hover:text-primary-foreground/80 hover:underline"
|
||||
: "text-muted-foreground hover:text-foreground hover:underline"
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
className={cn(
|
||||
"group border-none hover:bg-muted/60",
|
||||
index % 2 === 1 && "bg-muted/25"
|
||||
)}
|
||||
onMouseDown={onPointerDown}
|
||||
onClick={onSelect}
|
||||
className="group cursor-pointer select-none border-none hover:bg-transparent"
|
||||
>
|
||||
<TableCell className="max-w-0 py-2 pl-6 pr-2">
|
||||
<div className={nameColumnLayout}>
|
||||
<div className="flex items-center justify-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className={cn(
|
||||
"size-8 text-primary opacity-0 transition-opacity group-hover:opacity-100",
|
||||
isFavorite && "opacity-100"
|
||||
)}
|
||||
aria-label={
|
||||
isFavorite
|
||||
? `Remove ${song.title} from favorites`
|
||||
: `Favorite ${song.title}`
|
||||
}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
onToggleFavorite()
|
||||
}}
|
||||
>
|
||||
<Star className={cn("size-4", isFavorite && "fill-primary")} />
|
||||
</Button>
|
||||
</div>
|
||||
<SongCover song={song} />
|
||||
<span className="truncate font-normal">
|
||||
{song.title}
|
||||
{song.explicit ? (
|
||||
<span
|
||||
className="ml-1.5 inline-flex size-3.5 shrink-0 items-center justify-center rounded-sm bg-muted-foreground/20 text-[9px] font-semibold leading-none text-muted-foreground"
|
||||
aria-label="Explicit"
|
||||
>
|
||||
E
|
||||
<TableCell colSpan={4} className="p-0">
|
||||
<div
|
||||
className={cn(
|
||||
"relative py-2",
|
||||
inRange && "text-primary-foreground"
|
||||
)}
|
||||
>
|
||||
<SongsSelectionRangeHighlight position={selectionPosition} />
|
||||
{!inRange ? <SongsTrackRowHoverHighlight /> : null}
|
||||
<div
|
||||
className={cn("relative z-10", songRowLayout, TRACK_ROW_PADDING)}
|
||||
>
|
||||
<div className={nameColumnLayout}>
|
||||
<div className="flex items-center justify-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className={cn(
|
||||
"size-8 opacity-0 transition-opacity group-hover:opacity-100",
|
||||
inRange
|
||||
? "text-primary-foreground hover:bg-white/15 hover:text-primary-foreground"
|
||||
: "text-primary hover:text-primary",
|
||||
(isFavorite || isSelected) && "opacity-100"
|
||||
)}
|
||||
aria-label={
|
||||
isFavorite
|
||||
? `Remove ${song.title} from favorites`
|
||||
: `Favorite ${song.title}`
|
||||
}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
onToggleFavorite()
|
||||
}}
|
||||
>
|
||||
<Star
|
||||
className={cn(
|
||||
"size-4",
|
||||
isFavorite && (inRange ? "fill-current" : "fill-primary")
|
||||
)}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
<SongCover song={song} inRange={inRange} />
|
||||
<span className={ALBUM_TRACK_TITLE}>
|
||||
{song.title}
|
||||
{song.explicit ? (
|
||||
<span
|
||||
className={cn(
|
||||
"ml-1.5 inline-flex size-3.5 shrink-0 items-center justify-center rounded-sm text-[9px] font-semibold leading-none",
|
||||
inRange
|
||||
? "bg-white/20 text-primary-foreground"
|
||||
: "bg-muted-foreground/20 text-muted-foreground"
|
||||
)}
|
||||
aria-label="Explicit"
|
||||
>
|
||||
E
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<SongContextMenu song={song} />
|
||||
</div>
|
||||
<div className={songColumnClass}>
|
||||
<Link
|
||||
href={"/artist/" + song.artist.id}
|
||||
className={linkClass}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
{song.artist.name}
|
||||
</Link>
|
||||
</div>
|
||||
<div className={songColumnClass}>
|
||||
<Link
|
||||
href={"/album/" + song.album.id}
|
||||
className={linkClass}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
{song.album.title}
|
||||
</Link>
|
||||
</div>
|
||||
<div className="min-w-4 flex-1" />
|
||||
<span
|
||||
className={cn(
|
||||
"shrink-0 text-right tabular-nums",
|
||||
inRange ? "text-primary-foreground" : "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{formatDuration(song.durationSeconds)}
|
||||
</span>
|
||||
<MediaContextMenu
|
||||
label={`More options for ${song.title}`}
|
||||
selectedCount={selectedCount}
|
||||
align="end"
|
||||
onOpenMenu={onPrepareContextMenu}
|
||||
onAction={(action) => onMediaAction(action, song.id)}
|
||||
triggerClassName={cn(
|
||||
"size-8 shrink-0 transition-opacity",
|
||||
inRange
|
||||
? "text-primary-foreground opacity-100 hover:bg-white/15 hover:text-primary-foreground"
|
||||
: "opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="max-w-0 truncate py-2 text-muted-foreground">
|
||||
{song.artist.name}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-0 truncate py-2 text-muted-foreground">
|
||||
{song.album.title}
|
||||
</TableCell>
|
||||
<TableCell className="py-2 pr-6 text-right tabular-nums text-muted-foreground">
|
||||
{formatDuration(song.durationSeconds)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
}
|
||||
@@ -207,6 +262,25 @@ export function SongsView({ songs }: { songs: Song[] }) {
|
||||
return sorted
|
||||
}, [songs, sortKey, sortDirection])
|
||||
|
||||
const {
|
||||
selectedIds,
|
||||
selectedCount,
|
||||
isSelected,
|
||||
handleSelect,
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
} = useTrackSelection(sortedSongs)
|
||||
|
||||
const selectionPositions = React.useMemo(
|
||||
() =>
|
||||
getSelectionRangePositions(
|
||||
sortedSongs.map((song) => song.id),
|
||||
selectedIds
|
||||
),
|
||||
[sortedSongs, selectedIds]
|
||||
)
|
||||
|
||||
function toggleFavorite(songId: string) {
|
||||
setFavoriteIds((current) => {
|
||||
const next = new Set(current)
|
||||
@@ -219,6 +293,48 @@ export function SongsView({ songs }: { songs: Song[] }) {
|
||||
})
|
||||
}
|
||||
|
||||
function handleMediaAction(action: MediaContextAction, fallbackSongId?: string) {
|
||||
const targetIds =
|
||||
selectedIds.size > 0
|
||||
? Array.from(selectedIds)
|
||||
: fallbackSongId
|
||||
? [fallbackSongId]
|
||||
: []
|
||||
const count = targetIds.length
|
||||
|
||||
switch (action) {
|
||||
case "favorite":
|
||||
setFavoriteIds((current) => {
|
||||
const next = new Set(current)
|
||||
for (const id of targetIds) {
|
||||
next.add(id)
|
||||
}
|
||||
return next
|
||||
})
|
||||
toast.success(
|
||||
count > 1 ? `Favorited ${count} songs` : "Added to favorites"
|
||||
)
|
||||
break
|
||||
case "playlist":
|
||||
toast.success(
|
||||
count > 1
|
||||
? `Added ${count} songs to playlist`
|
||||
: "Added to playlist"
|
||||
)
|
||||
break
|
||||
case "play-next":
|
||||
toast.success(
|
||||
count > 1 ? `Queued ${count} songs to play next` : "Play next"
|
||||
)
|
||||
break
|
||||
case "play-last":
|
||||
toast.success(
|
||||
count > 1 ? `Queued ${count} songs to play last` : "Play last"
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-svh flex-col">
|
||||
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
|
||||
@@ -260,30 +376,49 @@ export function SongsView({ songs }: { songs: Song[] }) {
|
||||
</DropdownMenu>
|
||||
</header>
|
||||
|
||||
{selectedCount > 1 ? (
|
||||
<p
|
||||
className={cn(
|
||||
TRACK_ROW_PADDING,
|
||||
"border-b py-2 text-xs text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
{selectedCount} songs selected
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="pb-28">
|
||||
<div
|
||||
className="w-full pb-28"
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
clearSelection()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="border-none hover:bg-transparent">
|
||||
<TableHead className="h-9 pl-6 pr-2">
|
||||
<div className={nameColumnLayout}>
|
||||
<span aria-hidden />
|
||||
<span className="text-xs font-normal text-muted-foreground">
|
||||
Name
|
||||
<TableHead colSpan={4} className="h-9 p-0 font-normal">
|
||||
<div className={cn(songRowLayout, TRACK_ROW_PADDING)}>
|
||||
<div className={nameColumnLayout}>
|
||||
<span aria-hidden />
|
||||
<span aria-hidden />
|
||||
<span className="text-xs text-muted-foreground">Name</span>
|
||||
</div>
|
||||
<span className={cn(songColumnClass, "text-xs text-muted-foreground")}>
|
||||
Artist
|
||||
</span>
|
||||
<span aria-hidden />
|
||||
<span aria-hidden />
|
||||
<span className={cn(songColumnClass, "text-xs text-muted-foreground")}>
|
||||
Album
|
||||
</span>
|
||||
<div className="min-w-4 flex-1" />
|
||||
<span className="shrink-0 text-right text-xs text-muted-foreground">
|
||||
Time
|
||||
</span>
|
||||
<span className="size-8 shrink-0" aria-hidden />
|
||||
</div>
|
||||
</TableHead>
|
||||
<TableHead className="h-9 px-2 text-xs font-normal text-muted-foreground">
|
||||
Artist
|
||||
</TableHead>
|
||||
<TableHead className="h-9 px-2 text-xs font-normal text-muted-foreground">
|
||||
Album
|
||||
</TableHead>
|
||||
<TableHead className="h-9 w-16 pr-6 text-right text-xs font-normal text-muted-foreground">
|
||||
Time
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -292,8 +427,21 @@ export function SongsView({ songs }: { songs: Song[] }) {
|
||||
key={song.id}
|
||||
song={song}
|
||||
index={index}
|
||||
isSelected={isSelected(song.id)}
|
||||
selectionPosition={selectionPositions[index]}
|
||||
isFavorite={favoriteIds.has(song.id)}
|
||||
selectedCount={
|
||||
isSelected(song.id) && selectedCount > 0
|
||||
? selectedCount
|
||||
: 1
|
||||
}
|
||||
onPointerDown={handlePointerDown}
|
||||
onSelect={(event) => {
|
||||
handleSelect(song.id, index, event)
|
||||
}}
|
||||
onToggleFavorite={() => toggleFavorite(song.id)}
|
||||
onPrepareContextMenu={() => prepareContextMenu(song.id)}
|
||||
onMediaAction={handleMediaAction}
|
||||
/>
|
||||
))}
|
||||
</TableBody>
|
||||
|
||||
@@ -9,6 +9,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
position="top-center"
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
|
||||
+4
-1
@@ -122,7 +122,10 @@ export const updateLibrary = action({
|
||||
`Unknown Song (${Date.now().toString(10)})`,
|
||||
files: { [codec]: song },
|
||||
album: dbAlbum._id,
|
||||
artist: dbArtist._id,
|
||||
artist:
|
||||
metadata.common.artist?.[0] ??
|
||||
metadata.common.artists?.[0] ??
|
||||
dbArtist.name,
|
||||
albumArtist: dbArtist._id,
|
||||
length: metadata.format.duration || 0,
|
||||
track: metadata.common.track.no || 0,
|
||||
|
||||
@@ -1,5 +1,343 @@
|
||||
import { mutation, query } from "./_generated/server"
|
||||
import { v } from "convex/values"
|
||||
import type { Doc, Id } from "./_generated/dataModel"
|
||||
import type { QueryCtx } from "./_generated/server"
|
||||
|
||||
type BrowseArtist = {
|
||||
id: Id<"artists">
|
||||
name: string
|
||||
photo: string | null
|
||||
}
|
||||
|
||||
type BrowseAlbum = {
|
||||
id: Id<"albums">
|
||||
title: string
|
||||
artist: BrowseArtist
|
||||
cover: string | null
|
||||
}
|
||||
|
||||
type BrowseSong = {
|
||||
id: Id<"songs">
|
||||
title: string
|
||||
artist: BrowseArtist
|
||||
album: Pick<BrowseAlbum, "id" | "title" | "cover">
|
||||
durationSeconds: number
|
||||
}
|
||||
|
||||
async function loadArtistMap(ctx: QueryCtx) {
|
||||
const artists = await ctx.db.query("artists").collect()
|
||||
return new Map(artists.map((artist) => [artist._id, artist]))
|
||||
}
|
||||
|
||||
function toBrowseArtist(artist: Doc<"artists">): BrowseArtist {
|
||||
return {
|
||||
id: artist._id,
|
||||
name: artist.name,
|
||||
photo: artist.cover,
|
||||
}
|
||||
}
|
||||
|
||||
function toBrowseAlbum(
|
||||
album: Doc<"albums">,
|
||||
artist: Doc<"artists">
|
||||
): BrowseAlbum {
|
||||
return {
|
||||
id: album._id,
|
||||
title: album.name,
|
||||
artist: toBrowseArtist(artist),
|
||||
cover: album.cover,
|
||||
}
|
||||
}
|
||||
|
||||
function toBrowseSong(
|
||||
song: Doc<"songs">,
|
||||
album: Doc<"albums">,
|
||||
albumArtist: Doc<"artists">
|
||||
): BrowseSong {
|
||||
return {
|
||||
id: song._id,
|
||||
title: song.name,
|
||||
artist: {
|
||||
id: albumArtist._id,
|
||||
name: albumArtist.name,
|
||||
photo: albumArtist.cover,
|
||||
},
|
||||
album: {
|
||||
id: album._id,
|
||||
title: album.name,
|
||||
cover: album.cover,
|
||||
},
|
||||
durationSeconds: Math.round(song.length),
|
||||
}
|
||||
}
|
||||
|
||||
export const browseAlbums = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const artistMap = await loadArtistMap(ctx)
|
||||
const albums = await ctx.db.query("albums").collect()
|
||||
|
||||
return albums
|
||||
.flatMap((album) => {
|
||||
const artist = artistMap.get(album.artist)
|
||||
return artist ? [toBrowseAlbum(album, artist)] : []
|
||||
})
|
||||
.sort((a, b) => a.title.localeCompare(b.title))
|
||||
},
|
||||
})
|
||||
|
||||
export const browseArtists = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const artists = await ctx.db.query("artists").collect()
|
||||
return artists
|
||||
.map(toBrowseArtist)
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
},
|
||||
})
|
||||
|
||||
export const browseSongs = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const artistMap = await loadArtistMap(ctx)
|
||||
const albums = await ctx.db.query("albums").collect()
|
||||
const albumMap = new Map(albums.map((album) => [album._id, album]))
|
||||
const songs = await ctx.db.query("songs").collect()
|
||||
|
||||
return songs
|
||||
.flatMap((song) => {
|
||||
const album = albumMap.get(song.album)
|
||||
const albumArtist = artistMap.get(song.albumArtist)
|
||||
if (!album || !albumArtist) {
|
||||
return []
|
||||
}
|
||||
return [toBrowseSong(song, album, albumArtist)]
|
||||
})
|
||||
.sort((a, b) => a.title.localeCompare(b.title))
|
||||
},
|
||||
})
|
||||
|
||||
type BrowseAlbumTrack = {
|
||||
id: Id<"songs">
|
||||
title: string
|
||||
track: number
|
||||
durationSeconds: number
|
||||
}
|
||||
|
||||
type BrowseAlbumDetail = BrowseAlbum & {
|
||||
year: number | null
|
||||
genre: string | null
|
||||
tracks: BrowseAlbumTrack[]
|
||||
}
|
||||
|
||||
export const browseAlbumDetail = query({
|
||||
args: { id: v.id("albums") },
|
||||
handler: async (ctx, args): Promise<BrowseAlbumDetail | null> => {
|
||||
const album = await ctx.db.get("albums", args.id)
|
||||
if (!album) {
|
||||
return null
|
||||
}
|
||||
|
||||
const artist = await ctx.db.get("artists", album.artist)
|
||||
if (!artist) {
|
||||
return null
|
||||
}
|
||||
|
||||
const songs = await ctx.db
|
||||
.query("songs")
|
||||
.withIndex("by_album", (q) => q.eq("album", args.id))
|
||||
.collect()
|
||||
|
||||
songs.sort((a, b) => {
|
||||
if (a.track !== b.track) {
|
||||
return a.track - b.track
|
||||
}
|
||||
return a.name.localeCompare(b.name)
|
||||
})
|
||||
|
||||
const primarySong = songs[0]
|
||||
|
||||
return {
|
||||
...toBrowseAlbum(album, artist),
|
||||
year: primarySong?.year ?? null,
|
||||
genre: primarySong?.genres[0] ?? null,
|
||||
tracks: songs.map((song) => ({
|
||||
id: song._id,
|
||||
title: song.name,
|
||||
track: song.track,
|
||||
durationSeconds: Math.round(song.length),
|
||||
})),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const browseArtistDetail = query({
|
||||
args: { id: v.id("artists") },
|
||||
handler: async (ctx, args) => {
|
||||
const artist = await ctx.db.get("artists", args.id)
|
||||
if (!artist) {
|
||||
return null
|
||||
}
|
||||
|
||||
const albums = await ctx.db
|
||||
.query("albums")
|
||||
.withIndex("by_artist", (q) => q.eq("artist", args.id))
|
||||
.collect()
|
||||
|
||||
const recentlyAdded = [...albums]
|
||||
.sort((a, b) => b._creationTime - a._creationTime)
|
||||
.map((album) => toBrowseAlbum(album, artist))
|
||||
|
||||
const recentlyPlayed = [...albums]
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map((album) => toBrowseAlbum(album, artist))
|
||||
|
||||
return {
|
||||
artist: toBrowseArtist(artist),
|
||||
albums: recentlyPlayed,
|
||||
recentlyAdded,
|
||||
recentlyPlayed,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
function matchScore(text: string, query: string): number {
|
||||
const lower = text.toLowerCase()
|
||||
if (lower === query) {
|
||||
return 100
|
||||
}
|
||||
if (lower.startsWith(query)) {
|
||||
return 80
|
||||
}
|
||||
if (lower.split(/\s+/).some((word) => word.startsWith(query))) {
|
||||
return 60
|
||||
}
|
||||
if (lower.includes(query)) {
|
||||
return 40
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type SearchTopResult =
|
||||
| { kind: "song"; item: BrowseSong; score: number }
|
||||
| { kind: "album"; item: BrowseAlbum; score: number }
|
||||
| { kind: "artist"; item: BrowseArtist; score: number }
|
||||
|
||||
export const searchLibrary = query({
|
||||
args: { query: v.string() },
|
||||
handler: async (ctx, args) => {
|
||||
const queryText = args.query.trim().toLowerCase()
|
||||
if (!queryText) {
|
||||
return {
|
||||
topResults: [] as Array<
|
||||
| { kind: "song"; item: BrowseSong }
|
||||
| { kind: "album"; item: BrowseAlbum }
|
||||
| { kind: "artist"; item: BrowseArtist }
|
||||
>,
|
||||
artists: [] as BrowseArtist[],
|
||||
albums: [] as BrowseAlbum[],
|
||||
songs: [] as BrowseSong[],
|
||||
}
|
||||
}
|
||||
|
||||
const artistMap = await loadArtistMap(ctx)
|
||||
const albums = await ctx.db.query("albums").collect()
|
||||
const albumMap = new Map(albums.map((album) => [album._id, album]))
|
||||
const songs = await ctx.db.query("songs").collect()
|
||||
|
||||
const artistResults: SearchTopResult[] = [...artistMap.values()]
|
||||
.map((artist) => ({
|
||||
kind: "artist" as const,
|
||||
item: toBrowseArtist(artist),
|
||||
score: matchScore(artist.name, queryText),
|
||||
}))
|
||||
.filter((result) => result.score > 0)
|
||||
.sort((a, b) => b.score - a.score || a.item.name.localeCompare(b.item.name))
|
||||
|
||||
const albumResults: SearchTopResult[] = albums
|
||||
.flatMap((album) => {
|
||||
const artist = artistMap.get(album.artist)
|
||||
if (!artist) {
|
||||
return []
|
||||
}
|
||||
const score = Math.max(
|
||||
matchScore(album.name, queryText),
|
||||
matchScore(artist.name, queryText)
|
||||
)
|
||||
if (score === 0) {
|
||||
return []
|
||||
}
|
||||
return [
|
||||
{
|
||||
kind: "album" as const,
|
||||
item: toBrowseAlbum(album, artist),
|
||||
score,
|
||||
},
|
||||
]
|
||||
})
|
||||
.sort(
|
||||
(a, b) =>
|
||||
b.score - a.score || a.item.title.localeCompare(b.item.title)
|
||||
)
|
||||
|
||||
const songResults: SearchTopResult[] = songs
|
||||
.flatMap((song) => {
|
||||
const album = albumMap.get(song.album)
|
||||
const albumArtist = artistMap.get(song.albumArtist)
|
||||
if (!album || !albumArtist) {
|
||||
return []
|
||||
}
|
||||
const score = Math.max(
|
||||
matchScore(song.name, queryText),
|
||||
matchScore(song.artist, queryText),
|
||||
matchScore(album.name, queryText),
|
||||
matchScore(albumArtist.name, queryText)
|
||||
)
|
||||
if (score === 0) {
|
||||
return []
|
||||
}
|
||||
return [
|
||||
{
|
||||
kind: "song" as const,
|
||||
item: toBrowseSong(song, album, albumArtist),
|
||||
score,
|
||||
},
|
||||
]
|
||||
})
|
||||
.sort(
|
||||
(a, b) =>
|
||||
b.score - a.score || a.item.title.localeCompare(b.item.title)
|
||||
)
|
||||
|
||||
const topResults = [...songResults, ...albumResults, ...artistResults]
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, 6)
|
||||
.map(({ kind, item }) => ({ kind, item }))
|
||||
|
||||
return {
|
||||
topResults,
|
||||
artists: artistResults.map((result) => result.item),
|
||||
albums: albumResults.map((result) => result.item),
|
||||
songs: songResults.map((result) => result.item),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const browseRecentlyAdded = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const artistMap = await loadArtistMap(ctx)
|
||||
const albums = await ctx.db.query("albums").collect()
|
||||
|
||||
return albums
|
||||
.flatMap((album) => {
|
||||
const artist = artistMap.get(album.artist)
|
||||
return artist ? [{ album, artist, addedAt: album._creationTime }] : []
|
||||
})
|
||||
.sort((a, b) => b.addedAt - a.addedAt)
|
||||
.map(({ album, artist }) => toBrowseAlbum(album, artist))
|
||||
},
|
||||
})
|
||||
|
||||
export const getArtists = query({
|
||||
args: {},
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
|
||||
type Selectable = { id: string }
|
||||
|
||||
export function useTrackSelection<T extends Selectable>(items: T[]) {
|
||||
const [selectedIds, setSelectedIds] = React.useState<Set<string>>(
|
||||
() => new Set()
|
||||
)
|
||||
const anchorIndexRef = React.useRef<number | null>(null)
|
||||
|
||||
const isSelected = React.useCallback(
|
||||
(id: string) => selectedIds.has(id),
|
||||
[selectedIds]
|
||||
)
|
||||
|
||||
const handlePointerDown = React.useCallback((event: React.MouseEvent) => {
|
||||
if (event.shiftKey) {
|
||||
event.preventDefault()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleSelect = React.useCallback(
|
||||
(id: string, index: number, event: React.MouseEvent) => {
|
||||
if (event.shiftKey || event.metaKey || event.ctrlKey) {
|
||||
event.preventDefault()
|
||||
window.getSelection()?.removeAllRanges()
|
||||
}
|
||||
|
||||
if (event.metaKey || event.ctrlKey) {
|
||||
setSelectedIds((current) => {
|
||||
const next = new Set(current)
|
||||
if (next.has(id)) {
|
||||
next.delete(id)
|
||||
} else {
|
||||
next.add(id)
|
||||
}
|
||||
return next
|
||||
})
|
||||
anchorIndexRef.current = index
|
||||
return
|
||||
}
|
||||
|
||||
if (event.shiftKey && anchorIndexRef.current !== null) {
|
||||
const start = Math.min(anchorIndexRef.current, index)
|
||||
const end = Math.max(anchorIndexRef.current, index)
|
||||
setSelectedIds(
|
||||
new Set(items.slice(start, end + 1).map((item) => item.id))
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
setSelectedIds(new Set([id]))
|
||||
anchorIndexRef.current = index
|
||||
},
|
||||
[items]
|
||||
)
|
||||
|
||||
const prepareContextMenu = React.useCallback((id: string) => {
|
||||
setSelectedIds((current) => {
|
||||
if (current.has(id)) {
|
||||
return current
|
||||
}
|
||||
return new Set([id])
|
||||
})
|
||||
}, [])
|
||||
|
||||
const clearSelection = React.useCallback(() => {
|
||||
setSelectedIds(new Set())
|
||||
anchorIndexRef.current = null
|
||||
}, [])
|
||||
|
||||
return {
|
||||
selectedIds,
|
||||
selectedCount: selectedIds.size,
|
||||
isSelected,
|
||||
handleSelect,
|
||||
handlePointerDown,
|
||||
prepareContextMenu,
|
||||
clearSelection,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/** Shared layout for album grids and carousel slides (gap-x-6 = 1.5rem). */
|
||||
export const albumGridClassName =
|
||||
"grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6"
|
||||
|
||||
/** Slide width matches one cell of `albumGridClassName` inside an `@container` ancestor. */
|
||||
export const albumGridCarouselSlideClassName =
|
||||
"w-[calc((100cqw-1.5rem)/2)] shrink-0 grow-0 basis-auto pl-6 sm:w-[calc((100cqw-3rem)/3)] md:w-[calc((100cqw-4.5rem)/4)] lg:w-[calc((100cqw-6rem)/5)] xl:w-[calc((100cqw-7.5rem)/6)]"
|
||||
|
||||
export const albumGridCarouselContentClassName = "-ml-6"
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ConvexHttpClient } from "convex/browser"
|
||||
|
||||
let client: ConvexHttpClient | null = null
|
||||
|
||||
export function getConvexClient() {
|
||||
if (!client) {
|
||||
client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!)
|
||||
}
|
||||
return client
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export function artistCoverUrl(artistId: string) {
|
||||
return `/api/artist/${artistId}/cover`
|
||||
}
|
||||
|
||||
export function albumCoverUrl(albumId: string) {
|
||||
return `/api/album/${albumId}/cover`
|
||||
}
|
||||
|
||||
export function playlistCoverUrl(playlistId: string) {
|
||||
return `/api/playlist/${playlistId}/cover`
|
||||
}
|
||||
+17
-144
@@ -20,149 +20,22 @@ export type Song = {
|
||||
explicit?: boolean
|
||||
}
|
||||
|
||||
export const albums: Album[] = [
|
||||
{ id: "live-from-the-hollywood-bowl", title: "Live from the Hollywood Bowl", artist: { id: "ajr", name: "AJR", photo: null }, cover: null },
|
||||
{ id: "ends-of-the-earth", title: "Ends of the Earth", artist: { id: "the-longest-johns", name: "The Longest Johns", photo: null }, cover: null },
|
||||
{ id: "the-parting-glass-single", title: "The Parting Glass - Single", artist: { id: "the-ramparts", name: "The Ramparts", photo: null }, cover: null },
|
||||
{ id: "fairytale-of-new-york-single", title: "Fairytale of New York - Single", artist: { id: "the-ramparts", name: "The Ramparts", photo: null }, cover: null },
|
||||
{ id: "the-rocky-road-to-dublin-single", title: "The Rocky Road to Dublin - Single", artist: { id: "the-ramparts", name: "The Ramparts", photo: null }, cover: null },
|
||||
{ id: "1778-ep", title: "1778 - EP", artist: { id: "the-wellermen", name: "The Wellermen", photo: null }, cover: null },
|
||||
{ id: "the-high-kings", title: "The High Kings", artist: { id: "the-high-kings", name: "The High Kings", photo: null }, cover: null },
|
||||
{ id: "the-fall-off", title: "The Fall-Off", artist: { id: "j-cole", name: "J. Cole", photo: null }, cover: null },
|
||||
{ id: "enchanted-isle", title: "Enchanted Isle", artist: { id: "voces8", name: "VOCES8", photo: null }, cover: null },
|
||||
{ id: "unknown-album", title: "Unknown Album", artist: { id: "unknown-artist", name: "Unknown Artist", photo: null }, cover: null },
|
||||
{ id: "song-of-durin-complete-edition", title: "Song of Durin (Complete Edition)", artist: { id: "clamavi-de-profundis", name: "Clamavi De Profundis", photo: null }, cover: null },
|
||||
{ id: "sid-meiers-civilization-v-soundtrack", title: "Sid Meier's Civilization V (Soundtrack)", artist: { id: "geoff-knorr-michael-curran", name: "Geoff Knorr & Michael Curran", photo: null }, cover: null },
|
||||
{ id: "the-last-goodbye-single", title: "The Last Goodbye - Single", artist: { id: "seth-staton-watkins", name: "Seth Staton Watkins", photo: null }, cover: null },
|
||||
{ id: "do-you-hear-the-people-sing-single", title: "Do You Hear the People Sing? - Single", artist: { id: "seth-staton-watkins-aaron-dolan", name: "Seth Staton Watkins & Aaron Dolan", photo: null }, cover: null },
|
||||
{ id: "fiddlers-green-single", title: "Fiddler's Green - Single", artist: { id: "seth-staton-watkins", name: "Seth Staton Watkins", photo: null }, cover: null },
|
||||
{ id: "the-orange-and-the-green-single", title: "The Orange and the Green - Single", artist: { id: "seth-staton-watkins", name: "Seth Staton Watkins", photo: null }, cover: null },
|
||||
{ id: "horse-soldier-horse-soldier-single", title: "Horse Soldier, Horse Soldier - Single", artist: { id: "seth-staton-watkins", name: "Seth Staton Watkins", photo: null }, cover: null },
|
||||
{ id: "my-mother-told-me-feat-3lake-single", title: "My Mother Told Me (feat. 3lake) - Single", artist: { id: "seth-staton-watkins", name: "Seth Staton Watkins", photo: null }, cover: null },
|
||||
]
|
||||
export type Playlist = {
|
||||
id: string
|
||||
title: string
|
||||
owner: string
|
||||
cover: string | null
|
||||
}
|
||||
|
||||
export const recentlyPlayed: Album[] = albums.slice(0, 9)
|
||||
export type AlbumTrack = {
|
||||
id: string
|
||||
title: string
|
||||
track: number
|
||||
durationSeconds: number
|
||||
}
|
||||
|
||||
export const recentlyAdded: Album[] = albums.slice(10)
|
||||
|
||||
export const artists: Artist[] = Array.from(
|
||||
new Map(albums.map((album) => [album.artist.id, album.artist])).values()
|
||||
)
|
||||
|
||||
export const songs: Song[] = [
|
||||
{
|
||||
id: "aaron-burr-sir",
|
||||
title: "Aaron Burr, Sir",
|
||||
artist: { id: "lin-manuel-miranda", name: "Lin-Manuel Miranda, Original Broadway Cast of Hamilton, Leslie Odom, Jr. & Original Broadway Cast of Hamilton", photo: null },
|
||||
album: { id: "hamilton-obcr", title: "Hamilton (Original Broadway Cast Recording)", cover: null },
|
||||
durationSeconds: 156,
|
||||
},
|
||||
{
|
||||
id: "actually-romantic",
|
||||
title: "Actually Romantic",
|
||||
artist: { id: "taylor-swift", name: "Taylor Swift", photo: null },
|
||||
album: { id: "the-life-of-a-showgirl", title: "The Life of a Showgirl", cover: null },
|
||||
durationSeconds: 163,
|
||||
explicit: true,
|
||||
},
|
||||
{
|
||||
id: "adagio-in-g-major",
|
||||
title: "Adagio in G Major",
|
||||
artist: { id: "voces8-paul-van-nevel", name: "VOCES8, Paul Van Nevel & L'Arpeggiata", photo: null },
|
||||
album: { id: "enchanted-isle", title: "Enchanted Isle", cover: null },
|
||||
durationSeconds: 219,
|
||||
},
|
||||
{
|
||||
id: "after-all",
|
||||
title: "After All",
|
||||
artist: { id: "ed-sheeran", name: "Ed Sheeran", photo: null },
|
||||
album: { id: "play", title: "Play", cover: null },
|
||||
durationSeconds: 210,
|
||||
},
|
||||
{
|
||||
id: "afire-love",
|
||||
title: "Afire Love",
|
||||
artist: { id: "ed-sheeran", name: "Ed Sheeran", photo: null },
|
||||
album: { id: "x", title: "x", cover: null },
|
||||
durationSeconds: 314,
|
||||
},
|
||||
{
|
||||
id: "again-lil-tecca",
|
||||
title: "Again",
|
||||
artist: { id: "lil-tecca", name: "Lil Tecca", photo: null },
|
||||
album: { id: "we-love-you-tecca-2-deluxe", title: "We Love You Tecca 2 (Deluxe)", cover: null },
|
||||
durationSeconds: 170,
|
||||
},
|
||||
{
|
||||
id: "again-fetty-wap",
|
||||
title: "Again (feat. XXXTENTACION)",
|
||||
artist: { id: "fetty-wap", name: "Fetty Wap", photo: null },
|
||||
album: { id: "again-feat-xxxtentacion", title: "Again (feat. XXXTENTACION) - Single", cover: null },
|
||||
durationSeconds: 302,
|
||||
},
|
||||
{
|
||||
id: "a-hard-days-night",
|
||||
title: "A Hard Day's Night",
|
||||
artist: { id: "the-beatles", name: "The Beatles", photo: null },
|
||||
album: { id: "a-hard-days-night", title: "A Hard Day's Night", cover: null },
|
||||
durationSeconds: 149,
|
||||
},
|
||||
{
|
||||
id: "aint-no-sunshine",
|
||||
title: "Ain't No Sunshine",
|
||||
artist: { id: "bill-withers", name: "Bill Withers", photo: null },
|
||||
album: { id: "just-as-i-am", title: "Just As I Am", cover: null },
|
||||
durationSeconds: 124,
|
||||
},
|
||||
{
|
||||
id: "airplanes-pt-ii",
|
||||
title: "Airplanes, Pt. II (feat. Hayley Williams of Paramore)",
|
||||
artist: { id: "b-o-b", name: "Hayley Williams, B.o.B & Eminem", photo: null },
|
||||
album: { id: "bob-presents-adventures", title: "B.o.B Presents: The Adventures of Bobby Ray", cover: null },
|
||||
durationSeconds: 319,
|
||||
explicit: true,
|
||||
},
|
||||
{
|
||||
id: "aja",
|
||||
title: "Aja",
|
||||
artist: { id: "ajr", name: "AJR", photo: null },
|
||||
album: { id: "live-from-the-hollywood-bowl", title: "Live from the Hollywood Bowl", cover: null },
|
||||
durationSeconds: 172,
|
||||
},
|
||||
{
|
||||
id: "all-you-need-is-love",
|
||||
title: "All You Need Is Love",
|
||||
artist: { id: "the-beatles", name: "The Beatles", photo: null },
|
||||
album: { id: "beatles-1", title: "1", cover: null },
|
||||
durationSeconds: 228,
|
||||
},
|
||||
{
|
||||
id: "ends-of-the-earth",
|
||||
title: "Ends of the Earth",
|
||||
artist: { id: "the-longest-johns", name: "The Longest Johns", photo: null },
|
||||
album: { id: "ends-of-the-earth", title: "Ends of the Earth", cover: null },
|
||||
durationSeconds: 245,
|
||||
},
|
||||
{
|
||||
id: "the-parting-glass",
|
||||
title: "The Parting Glass",
|
||||
artist: { id: "the-ramparts", name: "The Ramparts", photo: null },
|
||||
album: { id: "the-parting-glass-single", title: "The Parting Glass - Single", cover: null },
|
||||
durationSeconds: 198,
|
||||
},
|
||||
{
|
||||
id: "song-of-durin",
|
||||
title: "Song of Durin",
|
||||
artist: { id: "clamavi-de-profundis", name: "Clamavi De Profundis", photo: null },
|
||||
album: { id: "song-of-durin-complete-edition", title: "Song of Durin (Complete Edition)", cover: null },
|
||||
durationSeconds: 412,
|
||||
},
|
||||
{
|
||||
id: "babysitter",
|
||||
title: "Babysitter (feat. Ari Lennox)",
|
||||
artist: { id: "j-cole", name: "J. Cole", photo: null },
|
||||
album: { id: "the-fall-off", title: "The Fall-Off", cover: null },
|
||||
durationSeconds: 267,
|
||||
explicit: true,
|
||||
},
|
||||
]
|
||||
export type AlbumDetail = Album & {
|
||||
year: number | null
|
||||
genre: string | null
|
||||
tracks: AlbumTrack[]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { Playlist } from "@/lib/data"
|
||||
|
||||
export const placeholderPlaylists: Playlist[] = [
|
||||
{
|
||||
id: "favorite-songs",
|
||||
title: "Favorite Songs",
|
||||
owner: "Joshua Higgins",
|
||||
cover: null,
|
||||
},
|
||||
{
|
||||
id: "choir-bands",
|
||||
title: "Choir & Bands",
|
||||
owner: "Joshua Higgins",
|
||||
cover: null,
|
||||
},
|
||||
{ id: "plays", title: "Plays", owner: "Joshua Higgins", cover: null },
|
||||
{
|
||||
id: "sea-shanties",
|
||||
title: "Sea Shanties",
|
||||
owner: "Joshua Higgins",
|
||||
cover: null,
|
||||
},
|
||||
{
|
||||
id: "stay-civilized",
|
||||
title: "Stay Civilized",
|
||||
owner: "Joshua Higgins",
|
||||
cover: null,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,158 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export type SelectionRangePosition = "none" | "only" | "start" | "middle" | "end"
|
||||
|
||||
export function getSelectionRangePositions(
|
||||
itemIds: string[],
|
||||
selectedIds: Set<string>
|
||||
): SelectionRangePosition[] {
|
||||
const positions: SelectionRangePosition[] = itemIds.map((id) =>
|
||||
selectedIds.has(id) ? "only" : "none"
|
||||
)
|
||||
|
||||
let index = 0
|
||||
while (index < itemIds.length) {
|
||||
if (!selectedIds.has(itemIds[index])) {
|
||||
index++
|
||||
continue
|
||||
}
|
||||
|
||||
const start = index
|
||||
while (index < itemIds.length && selectedIds.has(itemIds[index])) {
|
||||
index++
|
||||
}
|
||||
|
||||
const end = index - 1
|
||||
const count = end - start + 1
|
||||
|
||||
for (let position = start; position <= end; position++) {
|
||||
if (count === 1) {
|
||||
positions[position] = "only"
|
||||
} else if (position === start) {
|
||||
positions[position] = "start"
|
||||
} else if (position === end) {
|
||||
positions[position] = "end"
|
||||
} else {
|
||||
positions[position] = "middle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return positions
|
||||
}
|
||||
|
||||
export function selectionHighlightRadiusClass(
|
||||
position: SelectionRangePosition
|
||||
) {
|
||||
switch (position) {
|
||||
case "only":
|
||||
return "rounded-lg"
|
||||
case "start":
|
||||
return "rounded-t-lg"
|
||||
case "end":
|
||||
return "rounded-b-lg"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
export const TRACK_ROW_HIGHLIGHT_INSET = "absolute inset-y-0 left-2 right-2"
|
||||
|
||||
export function SelectionRangeHighlight({
|
||||
position,
|
||||
}: {
|
||||
position: SelectionRangePosition
|
||||
}) {
|
||||
if (position === "none") {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none bg-primary",
|
||||
TRACK_ROW_HIGHLIGHT_INSET,
|
||||
selectionHighlightRadiusClass(position)
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Inset rounded hover background matching the selection pill shape. */
|
||||
export function TrackRowHoverHighlight() {
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none rounded-lg bg-muted/60 opacity-0 transition-opacity group-hover:opacity-100",
|
||||
TRACK_ROW_HIGHLIGHT_INSET
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Inset rounded background for the active (now playing) row. */
|
||||
export function TrackRowActiveHighlight() {
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none rounded-lg bg-muted/60",
|
||||
TRACK_ROW_HIGHLIGHT_INSET
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Shared horizontal padding for track rows — same when selected or not. */
|
||||
export const TRACK_ROW_PADDING = "pl-8 pr-10"
|
||||
|
||||
/** Centers the track list in the main content area. */
|
||||
export const TRACK_LIST_CONTAINER = "mx-auto w-full max-w-3xl"
|
||||
|
||||
/** Full-width highlight for library song rows (no horizontal inset). */
|
||||
export const SONGS_ROW_HIGHLIGHT_INSET = "absolute inset-0"
|
||||
|
||||
export function SongsSelectionRangeHighlight({
|
||||
position,
|
||||
}: {
|
||||
position: SelectionRangePosition
|
||||
}) {
|
||||
if (position === "none") {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none bg-primary",
|
||||
SONGS_ROW_HIGHLIGHT_INSET
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Full-width hover background for library song rows (not rounded). */
|
||||
export function SongsTrackRowHoverHighlight() {
|
||||
return (
|
||||
<div
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"pointer-events-none bg-muted/60 opacity-0 transition-opacity group-hover:opacity-100",
|
||||
SONGS_ROW_HIGHLIGHT_INSET
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Album track row: leading columns + spacer + duration & menu on the right. */
|
||||
export const ALBUM_TRACK_ROW =
|
||||
"flex w-full items-center gap-x-3"
|
||||
|
||||
export const ALBUM_TRACK_TITLE = "max-w-40 min-w-0 truncate font-normal"
|
||||
|
||||
export function isInSelectionRange(position: SelectionRangePosition) {
|
||||
return position !== "none"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import fs from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
|
||||
export const PLACEHOLDER_PATH = path.join(process.cwd(), "public/placeholder-album.svg")
|
||||
|
||||
const MIME_TYPES: Record<string, string> = {
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".webp": "image/webp",
|
||||
".gif": "image/gif",
|
||||
".svg": "image/svg+xml",
|
||||
}
|
||||
|
||||
function contentTypeFor(filePath: string) {
|
||||
return MIME_TYPES[path.extname(filePath).toLowerCase()] ?? "application/octet-stream"
|
||||
}
|
||||
|
||||
export async function serveCoverFile(coverPath: string | null | undefined) {
|
||||
if (coverPath) {
|
||||
try {
|
||||
const data = await fs.readFile(coverPath)
|
||||
return new Response(data, {
|
||||
headers: {
|
||||
"Content-Type": contentTypeFor(coverPath),
|
||||
"Cache-Control": "public, max-age=86400, immutable",
|
||||
},
|
||||
})
|
||||
} catch {
|
||||
// Fall through to placeholder when the file is missing on disk.
|
||||
}
|
||||
}
|
||||
|
||||
const placeholder = await fs.readFile(PLACEHOLDER_PATH)
|
||||
return new Response(placeholder, {
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -2,4 +2,12 @@ import type { NextConfig } from "next"
|
||||
|
||||
const nextConfig: NextConfig = {}
|
||||
|
||||
module.exports = {
|
||||
images: {
|
||||
dangerouslyAllowSVG: true,
|
||||
contentDispositionType: "attachment",
|
||||
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
|
||||
},
|
||||
}
|
||||
|
||||
export default nextConfig
|
||||
Reference in new issue
Block a user