diff --git a/app/layout.tsx b/app/layout.tsx index cb7f459..d31bbec 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -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({ diff --git a/app/library/artists/page.tsx b/app/library/artists/page.tsx index d92ff2b..d556863 100644 --- a/app/library/artists/page.tsx +++ b/app/library/artists/page.tsx @@ -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() {

Artists

-
-
- {artists.map((artist) => ( - - ))} -
-
+ ) } diff --git a/app/library/songs/page.tsx b/app/library/songs/page.tsx new file mode 100644 index 0000000..9ddbf06 --- /dev/null +++ b/app/library/songs/page.tsx @@ -0,0 +1,6 @@ +import { SongsView } from "@/components/songs-view" +import { songs } from "@/lib/data" + +export default function Page() { + return +} diff --git a/components/album-card.tsx b/components/album-card.tsx index 08e604a..795b1fa 100644 --- a/components/album-card.tsx +++ b/components/album-card.tsx @@ -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 (
- - {album.cover ? ( - {album.title} - ) : ( - {album.title} - )} - +
+ + {album.cover ? ( + {album.title} + ) : ( + {album.title} + )} + + +
+ +
+ + + + + + + + + Add to Playlist + + + + + Play Next + + + + Play Last + + + + + Favorite + + + + +
+
+

{album.title}

diff --git a/components/artists-view.tsx b/components/artists-view.tsx new file mode 100644 index 0000000..6b4538a --- /dev/null +++ b/components/artists-view.tsx @@ -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 ( +
+ {artist.name} +
+ ) +} + +function ArtistListItem({ + artist, + isSelected, + onSelect, +}: { + artist: Artist + isSelected: boolean + onSelect: () => void +}) { + return ( + + ) +} + +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 ( +
+ +
+ {sortedArtists.map((artist) => ( + setSelectedId(artist.id)} + /> + ))} +
+
+ + + {selectedArtist ? ( +
+
+ + {selectedArtist.name} + + + +
+ + + +
+
+ +
+ {artistAlbums.length > 0 ? ( +
+ {artistAlbums.map((album) => ( + + ))} +
+ ) : ( +

+ No albums for this artist. +

+ )} +
+
+ ) : null} +
+
+ ) +} diff --git a/components/songs-view.tsx b/components/songs-view.tsx new file mode 100644 index 0000000..d5582cd --- /dev/null +++ b/components/songs-view.tsx @@ -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 ( + + + + + + + Add to Playlist + + + + + Play Next + + + + Play Last + + + + + Favorite + + + + + ) +} + +function SongCover({ song }: { song: Song }) { + return ( +
+ {song.album.title} +
+ +
+
+ ) +} + +function SongRow({ + song, + index, + isFavorite, + onToggleFavorite, +}: { + song: Song + index: number + isFavorite: boolean + onToggleFavorite: () => void +}) { + return ( + + +
+
+ +
+ + + {song.title} + {song.explicit ? ( + + E + + ) : null} + + +
+
+ + {song.artist.name} + + + {song.album.title} + + + {formatDuration(song.durationSeconds)} + +
+ ) +} + +export function SongsView({ songs }: { songs: Song[] }) { + const [sortKey, setSortKey] = React.useState("title") + const [sortDirection, setSortDirection] = + React.useState("asc") + const [favoriteIds, setFavoriteIds] = React.useState>( + () => 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 ( +
+
+

Songs

+ + + + + + Sort by + setSortKey(value as SortKey)} + > + Name + + Artist + + Album + + + Order + + setSortDirection(value as SortDirection) + } + > + + Ascending + + + Descending + + + + +
+ + +
+ + + + +
+ + + Name + + + +
+
+ + Artist + + + Album + + + Time + +
+
+ + {sortedSongs.map((song, index) => ( + toggleFavorite(song.id)} + /> + ))} + +
+
+
+
+ ) +} diff --git a/lib/data.ts b/lib/data.ts index 8507a20..d9a6c93 100644 --- a/lib/data.ts +++ b/lib/data.ts @@ -11,6 +11,15 @@ export type Album = { cover: string | null } +export type Song = { + id: string + title: string + artist: Artist + album: Pick + 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, + }, +]