feat: artists & songs pages, album card hovers, so many hovers now

This commit is contained in:
joshuafhiggins committed 2026-06-02 00:30:21 -04:00 Verified
1 parent e85453174e
commit ac46032c92
7 files changed
+674 -31

No files matched your search

-1
View File
@@ -18,7 +18,6 @@ const fontMono = Geist_Mono({
export const metadata: Metadata = {
title: "oTunes",
description: "Our Music",
// keywords: ["Next.js", "React", "SEO"],
}
export default function RootLayout({
+3 -9
View File
@@ -1,5 +1,5 @@
import { ArtistCard } from "@/components/artist-card"
import { artists } from "@/lib/data"
import { ArtistsView } from "@/components/artists-view"
import { albums, artists } from "@/lib/data"
export default function Page() {
return (
@@ -8,13 +8,7 @@ export default function Page() {
<h1 className="text-lg font-semibold">Artists</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">
{artists.map((artist) => (
<ArtistCard key={artist.id} artist={artist} />
))}
</div>
</div>
<ArtistsView artists={artists} albums={albums} />
</div>
)
}
+6
View File
@@ -0,0 +1,6 @@
import { SongsView } from "@/components/songs-view"
import { songs } from "@/lib/data"
export default function Page() {
return <SongsView songs={songs} />
}
+87 -21
View File
@@ -2,33 +2,99 @@
import Image from "next/image"
import Link from "next/link"
import {
ListEnd,
ListPlus,
ListStart,
MoreHorizontal,
Play,
Star,
} from "lucide-react"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import type { Album } from "@/lib/data"
export function AlbumCard({ album }: { album: Album }) {
return (
<div className="group flex flex-col gap-2">
<Link
className="relative flex aspect-square items-center justify-center overflow-hidden rounded-lg ring-1 ring-foreground/10"
href={"/library/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"
/>
)}
</Link>
<div className="relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
<Link
className="absolute inset-0"
href={"/library/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"
/>
)}
</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 ${album.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 ${album.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>
<DropdownMenuSeparator />
<DropdownMenuItem className="justify-between">
Favorite
<Star />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="min-w-0">
<Link href={"/library/album/" + album.id}>
<p className="truncate text-sm font-medium">{album.title}</p>
+146
View File
@@ -0,0 +1,146 @@
"use client"
import * as React from "react"
import Image from "next/image"
import Link from "next/link"
import {
ChevronRightIcon,
MoreHorizontal,
Play,
Shuffle,
Star,
} from "lucide-react"
import { AlbumCard } from "@/components/album-card"
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"
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"}
alt={artist.name}
fill
className="object-cover"
/>
</div>
)
}
function ArtistListItem({
artist,
isSelected,
onSelect,
}: {
artist: Artist
isSelected: boolean
onSelect: () => void
}) {
return (
<button
type="button"
onClick={onSelect}
className={cn(
"flex w-full min-w-0 items-center gap-3 overflow-hidden px-4 py-2.5 text-left text-sm transition-colors",
isSelected ? "bg-primary text-primary-foreground" : "hover:bg-muted/50"
)}
>
<ArtistAvatar artist={artist} />
<span className="min-w-0 flex-1 truncate font-medium">{artist.name}</span>
</button>
)
}
export function ArtistsView({
artists,
albums,
}: {
artists: Artist[]
albums: Album[]
}) {
const sortedArtists = React.useMemo(
() => [...artists].sort((a, b) => a.name.localeCompare(b.name)),
[artists]
)
const [selectedId, setSelectedId] = React.useState(
() => sortedArtists[0]?.id ?? ""
)
const selectedArtist = sortedArtists.find(
(artist) => artist.id === selectedId
)
const artistAlbums = albums.filter((album) => album.artist.id === selectedId)
return (
<div className="flex min-h-0 flex-1">
<ScrollArea className="w-72 shrink-0 border-r">
<div className="w-full pb-28">
{sortedArtists.map((artist) => (
<ArtistListItem
key={artist.id}
artist={artist}
isSelected={artist.id === selectedId}
onSelect={() => setSelectedId(artist.id)}
/>
))}
</div>
</ScrollArea>
<ScrollArea className="min-w-0 flex-1">
{selectedArtist ? (
<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"
>
<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" />
</Link>
<div className="flex shrink-0 items-center gap-2">
<Button size="icon" className="rounded-full" aria-label="Play">
<Play className="fill-current" />
</Button>
<Button
variant="secondary"
size="icon"
className="rounded-full"
aria-label="Shuffle"
>
<Shuffle />
</Button>
<Button
variant="secondary"
size="icon"
className="rounded-full"
aria-label="Favorite"
>
<Star />
</Button>
</div>
</div>
<div className="p-6">
{artistAlbums.length > 0 ? (
<div className="grid grid-cols-2 gap-x-6 gap-y-8 sm:grid-cols-3 lg:grid-cols-4">
{artistAlbums.map((album) => (
<AlbumCard key={album.id} album={album} />
))}
</div>
) : (
<p className="text-sm text-muted-foreground">
No albums for this artist.
</p>
)}
</div>
</div>
) : null}
</ScrollArea>
</div>
)
}
+305
View File
@@ -0,0 +1,305 @@
"use client"
import * as React from "react"
import Image from "next/image"
import {
ArrowUpDown,
ListEnd,
ListPlus,
ListStart,
MoreHorizontal,
Play,
Star,
} from "lucide-react"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { ScrollArea } from "@/components/ui/scroll-area"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { cn } from "@/lib/utils"
import type { Song } from "@/lib/data"
type SortKey = "title" | "artist" | "album"
type SortDirection = "asc" | "desc"
const nameColumnLayout =
"grid grid-cols-[2rem_2.5rem_minmax(0,1fr)_2rem] items-center gap-x-2"
function formatDuration(seconds: number): string {
const minutes = Math.floor(seconds / 60)
const remainingSeconds = seconds % 60
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
}
function SongContextMenu({ song }: { song: Song }) {
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">
<Image
src={song.album.cover ?? "/placeholder-album.svg"}
alt={song.album.title}
fill
className="object-cover"
/>
<div className="absolute inset-0 flex items-center justify-center bg-black/0 transition-colors group-hover:bg-black/40">
<Button
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()}
>
<Play className="size-3 fill-current" />
</Button>
</div>
</div>
)
}
function SongRow({
song,
index,
isFavorite,
onToggleFavorite,
}: {
song: Song
index: number
isFavorite: boolean
onToggleFavorite: () => void
}) {
return (
<TableRow
className={cn(
"group border-none hover:bg-muted/60",
index % 2 === 1 && "bg-muted/25"
)}
>
<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
</span>
) : null}
</span>
<SongContextMenu song={song} />
</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>
)
}
export function SongsView({ songs }: { songs: Song[] }) {
const [sortKey, setSortKey] = React.useState<SortKey>("title")
const [sortDirection, setSortDirection] =
React.useState<SortDirection>("asc")
const [favoriteIds, setFavoriteIds] = React.useState<Set<string>>(
() => new Set()
)
const sortedSongs = React.useMemo(() => {
const sorted = [...songs].sort((a, b) => {
let comparison = 0
switch (sortKey) {
case "title":
comparison = a.title.localeCompare(b.title)
break
case "artist":
comparison = a.artist.name.localeCompare(b.artist.name)
break
case "album":
comparison = a.album.title.localeCompare(b.album.title)
break
}
return sortDirection === "asc" ? comparison : -comparison
})
return sorted
}, [songs, sortKey, sortDirection])
function toggleFavorite(songId: string) {
setFavoriteIds((current) => {
const next = new Set(current)
if (next.has(songId)) {
next.delete(songId)
} else {
next.add(songId)
}
return next
})
}
return (
<div className="flex h-svh flex-col">
<header className="flex items-center justify-between gap-2 border-b px-4 py-3">
<h1 className="text-lg font-semibold">Songs</h1>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon-sm" aria-label="Sort songs">
<ArrowUpDown className="size-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44">
<DropdownMenuLabel>Sort by</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={sortKey}
onValueChange={(value) => setSortKey(value as SortKey)}
>
<DropdownMenuRadioItem value="title">Name</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="artist">
Artist
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="album">Album</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
<DropdownMenuSeparator />
<DropdownMenuLabel>Order</DropdownMenuLabel>
<DropdownMenuRadioGroup
value={sortDirection}
onValueChange={(value) =>
setSortDirection(value as SortDirection)
}
>
<DropdownMenuRadioItem value="asc">
Ascending
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="desc">
Descending
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
</header>
<ScrollArea className="min-h-0 flex-1">
<div className="pb-28">
<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
</span>
<span aria-hidden />
<span 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>
{sortedSongs.map((song, index) => (
<SongRow
key={song.id}
song={song}
index={index}
isFavorite={favoriteIds.has(song.id)}
onToggleFavorite={() => toggleFavorite(song.id)}
/>
))}
</TableBody>
</Table>
</div>
</ScrollArea>
</div>
)
}
+127
View File
@@ -11,6 +11,15 @@ export type Album = {
cover: string | null
}
export type Song = {
id: string
title: string
artist: Artist
album: Pick<Album, "id" | "title" | "cover">
durationSeconds: number
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 },
@@ -39,3 +48,121 @@ 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,
},
]