feat: enhance playlist and track display with cover art and improved layout
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import Image from 'next/image';
|
||||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Tabs, TabsContent } from "@/components/ui/tabs";
|
import { Tabs, TabsContent } from "@/components/ui/tabs";
|
||||||
@@ -8,9 +9,11 @@ import Loading from '@/app/components/loading';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { PlusCircledIcon } from "@radix-ui/react-icons";
|
import { PlusCircledIcon } from "@radix-ui/react-icons";
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { getNavidromeAPI } from '@/lib/navidrome';
|
||||||
|
|
||||||
const PlaylistsPage: React.FC = () => {
|
const PlaylistsPage: React.FC = () => {
|
||||||
const { playlists, isLoading, createPlaylist } = useNavidrome();
|
const { playlists, isLoading, createPlaylist } = useNavidrome();
|
||||||
|
const api = getNavidromeAPI();
|
||||||
|
|
||||||
const handleCreatePlaylist = async () => {
|
const handleCreatePlaylist = async () => {
|
||||||
const name = prompt('Enter playlist name:');
|
const name = prompt('Enter playlist name:');
|
||||||
@@ -49,39 +52,42 @@ const PlaylistsPage: React.FC = () => {
|
|||||||
<div className="relative">
|
<div className="relative">
|
||||||
<ScrollArea>
|
<ScrollArea>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 pb-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 pb-4">
|
||||||
{playlists.map((playlist) => (
|
{playlists.map((playlist) => {
|
||||||
<Link key={playlist.id} href={`/playlist/${playlist.id}`}>
|
const playlistCoverUrl = playlist.coverArt
|
||||||
<div className="p-4 rounded-lg border border-border hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer">
|
? api.getCoverArtUrl(playlist.coverArt, 200)
|
||||||
<div className="flex items-center space-x-4">
|
: '/default-user.jpg';
|
||||||
<div className="w-12 h-12 bg-muted rounded-md flex items-center justify-center">
|
|
||||||
<svg
|
return (
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
<Link key={playlist.id} href={`/playlist/${playlist.id}`}>
|
||||||
fill="none"
|
<div className="p-4 rounded-lg border border-border hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer h-32">
|
||||||
stroke="currentColor"
|
<div className="flex items-center space-x-4 h-full">
|
||||||
strokeLinecap="round"
|
<div className="w-12 h-12 bg-muted rounded-md overflow-hidden flex-shrink-0">
|
||||||
strokeLinejoin="round"
|
<Image
|
||||||
strokeWidth="2"
|
src={playlistCoverUrl}
|
||||||
className="h-6 w-6"
|
alt={playlist.name}
|
||||||
viewBox="0 0 24 24"
|
width={48}
|
||||||
>
|
height={48}
|
||||||
<path d="M21 15V6M18.5 18a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM12 12H3M16 6H3M12 18H3" />
|
className="w-full h-full object-cover"
|
||||||
</svg>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0 flex flex-col justify-center">
|
||||||
<p className="font-medium leading-none truncate">{playlist.name}</p>
|
<p className="font-medium leading-none truncate">{playlist.name}</p>
|
||||||
<p className="text-sm text-muted-foreground mt-1">
|
<p className="text-sm text-muted-foreground mt-1">
|
||||||
{playlist.songCount} songs
|
{playlist.songCount} songs
|
||||||
</p>
|
|
||||||
{playlist.comment && (
|
|
||||||
<p className="text-xs text-muted-foreground mt-1 truncate">
|
|
||||||
{playlist.comment}
|
|
||||||
</p>
|
</p>
|
||||||
)}
|
<div className="h-4 mt-1">
|
||||||
|
{playlist.comment && (
|
||||||
|
<p className="text-xs text-muted-foreground truncate">
|
||||||
|
{playlist.comment}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
</Link>
|
);
|
||||||
))}
|
})}
|
||||||
</div>
|
</div>
|
||||||
<ScrollBar orientation="horizontal" />
|
<ScrollBar orientation="horizontal" />
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useParams } from 'next/navigation';
|
import { useParams } from 'next/navigation';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
|
import Link from 'next/link';
|
||||||
import { Playlist, Song } from '@/lib/navidrome';
|
import { Playlist, Song } from '@/lib/navidrome';
|
||||||
import { useNavidrome } from '@/app/components/NavidromeContext';
|
import { useNavidrome } from '@/app/components/NavidromeContext';
|
||||||
import { useAudioPlayer } from '@/app/components/AudioPlayerContext';
|
import { useAudioPlayer } from '@/app/components/AudioPlayerContext';
|
||||||
import { Play, Heart, Plus } from 'lucide-react';
|
import { getNavidromeAPI } from '@/lib/navidrome';
|
||||||
|
import { Play, Heart, Plus, Clock, User, Disc } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import Loading from "@/app/components/loading";
|
import Loading from "@/app/components/loading";
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
|
||||||
export default function PlaylistPage() {
|
export default function PlaylistPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
@@ -17,7 +20,8 @@ export default function PlaylistPage() {
|
|||||||
const [tracklist, setTracklist] = useState<Song[]>([]);
|
const [tracklist, setTracklist] = useState<Song[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { getPlaylist } = useNavidrome();
|
const { getPlaylist } = useNavidrome();
|
||||||
const { playTrack, addToQueue } = useAudioPlayer();
|
const { playTrack, addToQueue, currentTrack } = useAudioPlayer();
|
||||||
|
const api = getNavidromeAPI();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPlaylist = async () => {
|
const fetchPlaylist = async () => {
|
||||||
@@ -45,11 +49,11 @@ export default function PlaylistPage() {
|
|||||||
const track = {
|
const track = {
|
||||||
id: song.id,
|
id: song.id,
|
||||||
name: song.title,
|
name: song.title,
|
||||||
url: '', // Will be set by the context
|
url: api.getStreamUrl(song.id),
|
||||||
artist: song.artist,
|
artist: song.artist,
|
||||||
album: song.album,
|
album: song.album,
|
||||||
duration: song.duration,
|
duration: song.duration,
|
||||||
coverArt: song.coverArt,
|
coverArt: song.coverArt ? api.getCoverArtUrl(song.coverArt, 300) : undefined,
|
||||||
albumId: song.albumId,
|
albumId: song.albumId,
|
||||||
artistId: song.artistId
|
artistId: song.artistId
|
||||||
};
|
};
|
||||||
@@ -60,21 +64,51 @@ export default function PlaylistPage() {
|
|||||||
const track = {
|
const track = {
|
||||||
id: song.id,
|
id: song.id,
|
||||||
name: song.title,
|
name: song.title,
|
||||||
url: '', // Will be set by the context
|
url: api.getStreamUrl(song.id),
|
||||||
artist: song.artist,
|
artist: song.artist,
|
||||||
album: song.album,
|
album: song.album,
|
||||||
duration: song.duration,
|
duration: song.duration,
|
||||||
coverArt: song.coverArt,
|
coverArt: song.coverArt ? api.getCoverArtUrl(song.coverArt, 300) : undefined,
|
||||||
albumId: song.albumId,
|
albumId: song.albumId,
|
||||||
artistId: song.artistId
|
artistId: song.artistId
|
||||||
};
|
};
|
||||||
addToQueue(track);
|
addToQueue(track);
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDuration = (seconds: number) => {
|
const handlePlayPlaylist = () => {
|
||||||
const minutes = Math.floor(seconds / 60);
|
if (tracklist.length === 0) return;
|
||||||
const secs = Math.floor(seconds % 60).toString().padStart(2, '0');
|
|
||||||
return `${minutes}:${secs}`;
|
// Convert all songs to tracks
|
||||||
|
const tracks = tracklist.map(song => ({
|
||||||
|
id: song.id,
|
||||||
|
name: song.title,
|
||||||
|
url: api.getStreamUrl(song.id),
|
||||||
|
artist: song.artist,
|
||||||
|
album: song.album,
|
||||||
|
duration: song.duration,
|
||||||
|
coverArt: song.coverArt ? api.getCoverArtUrl(song.coverArt, 300) : undefined,
|
||||||
|
albumId: song.albumId,
|
||||||
|
artistId: song.artistId
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Play the first track and add the rest to queue
|
||||||
|
if (tracks.length > 0) {
|
||||||
|
playTrack(tracks[0], true); // Enable autoplay
|
||||||
|
if (tracks.length > 1) {
|
||||||
|
// Add remaining tracks to queue
|
||||||
|
tracks.slice(1).forEach(track => addToQueue(track));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isCurrentlyPlaying = (song: Song): boolean => {
|
||||||
|
return currentTrack?.id === song.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDuration = (duration: number): string => {
|
||||||
|
const minutes = Math.floor(duration / 60);
|
||||||
|
const seconds = duration % 60;
|
||||||
|
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -92,64 +126,146 @@ export default function PlaylistPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get playlist cover art URL with fallback
|
||||||
|
const playlistCoverUrl = playlist.coverArt
|
||||||
|
? api.getCoverArtUrl(playlist.coverArt, 300)
|
||||||
|
: '/default-user.jpg';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full px-4 py-6 lg:px-8">
|
<div className="h-full px-4 py-6 lg:px-8">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex items-start gap-6">
|
<div className="flex items-start gap-6">
|
||||||
<div className="w-[300px] h-[300px] bg-muted rounded-md flex items-center justify-center">
|
<div className="w-[300px] h-[300px] bg-muted rounded-md overflow-hidden">
|
||||||
<Play className="h-16 w-16 text-muted-foreground" />
|
<Image
|
||||||
|
src={playlistCoverUrl}
|
||||||
|
alt={playlist.name}
|
||||||
|
width={300}
|
||||||
|
height={300}
|
||||||
|
className="w-full h-full object-cover"
|
||||||
|
priority
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center space-x-4">
|
||||||
<p className="text-3xl font-semibold tracking-tight">{playlist.name}</p>
|
<p className="text-3xl font-semibold tracking-tight">{playlist.name}</p>
|
||||||
</div>
|
</div>
|
||||||
{playlist.comment && (
|
{playlist.comment && (
|
||||||
<p className="text-lg text-muted-foreground">{playlist.comment}</p>
|
<p className="text-xl text-muted-foreground mt-0 mb-4">{playlist.comment}</p>
|
||||||
)}
|
)}
|
||||||
|
<Button className="px-5" onClick={() => handlePlayPlaylist()}>
|
||||||
|
<Play />
|
||||||
|
Play Playlist
|
||||||
|
</Button>
|
||||||
<div className="text-sm text-muted-foreground">
|
<div className="text-sm text-muted-foreground">
|
||||||
<p>{playlist.songCount} songs • {formatDuration(playlist.duration || 0)}</p>
|
<p>{playlist.songCount} songs • Duration: {formatDuration(playlist.duration || 0)}</p>
|
||||||
{playlist.public !== undefined && (
|
{playlist.public !== undefined && (
|
||||||
<p>{playlist.public ? 'Public' : 'Private'} playlist</p>
|
<p>{playlist.public ? 'Public' : 'Private'} playlist</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-4">
|
||||||
<Separator />
|
<Separator />
|
||||||
{tracklist.length > 0 ? (
|
<ScrollArea className="h-[calc(100vh-500px)]">
|
||||||
tracklist.map((song, index) => (
|
{tracklist.length === 0 ? (
|
||||||
<div key={song.id} className="py-2 flex justify-between items-center hover:bg-hover rounded-lg cursor-pointer" onClick={() => handlePlayClick(song)}>
|
<div className="text-center py-12">
|
||||||
<div className="flex items-center">
|
<p className="text-muted-foreground">This playlist is empty.</p>
|
||||||
<div className="mr-2 w-6 text-right">{index + 1}</div>
|
|
||||||
<div>
|
|
||||||
<p className="font-semibold text-lg flex items-center">
|
|
||||||
{song.title}
|
|
||||||
</p>
|
|
||||||
<p className="text-sm font-normal flex items-center">
|
|
||||||
<span className="text-gray-400">{song.artist}</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<p className="text-sm mr-4">{formatDuration(song.duration)}</p>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
handleAddToQueue(song);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Plus className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))
|
) : (
|
||||||
) : (
|
<div className="space-y-1">
|
||||||
<div className="text-center py-8">
|
{tracklist.map((song, index) => (
|
||||||
<p className="text-muted-foreground">This playlist is empty</p>
|
<div
|
||||||
</div>
|
key={song.id}
|
||||||
)}
|
className={`group flex items-center p-3 rounded-lg hover:bg-accent/50 cursor-pointer transition-colors ${
|
||||||
|
isCurrentlyPlaying(song) ? 'bg-accent/50 border-l-4 border-primary' : ''
|
||||||
|
}`}
|
||||||
|
onClick={() => handlePlayClick(song)}
|
||||||
|
>
|
||||||
|
{/* Track Number / Play Indicator */}
|
||||||
|
<div className="w-8 text-center text-sm text-muted-foreground mr-3">
|
||||||
|
{isCurrentlyPlaying(song) ? (
|
||||||
|
<div className="w-4 h-4 mx-auto">
|
||||||
|
<div className="w-full h-full bg-primary rounded-full animate-pulse" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="group-hover:hidden">{index + 1}</span>
|
||||||
|
<Play className="w-4 h-4 mx-auto hidden group-hover:block" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Album Art */}
|
||||||
|
<div className="w-12 h-12 mr-4 flex-shrink-0">
|
||||||
|
<Image
|
||||||
|
src={song.coverArt ? api.getCoverArtUrl(song.coverArt, 100) : '/default-user.jpg'}
|
||||||
|
alt={song.album}
|
||||||
|
width={48}
|
||||||
|
height={48}
|
||||||
|
className="w-full h-full object-cover rounded-md"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Song Info */}
|
||||||
|
<div className="flex-1 min-w-0 mr-4">
|
||||||
|
<div className="flex items-center gap-2 mb-1">
|
||||||
|
<p className={`font-semibold truncate ${
|
||||||
|
isCurrentlyPlaying(song) ? 'text-primary' : ''
|
||||||
|
}`}>
|
||||||
|
{song.title}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center text-sm text-muted-foreground space-x-4">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<User className="w-3 h-3" />
|
||||||
|
<Link
|
||||||
|
href={`/artist/${song.artistId}`}
|
||||||
|
className="truncate hover:text-primary hover:underline"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{song.artist}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
{song.album && (
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Disc className="w-3 h-3" />
|
||||||
|
<Link
|
||||||
|
href={`/album/${song.albumId}`}
|
||||||
|
className="truncate hover:text-primary hover:underline"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{song.album}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Duration */}
|
||||||
|
<div className="flex items-center text-sm text-muted-foreground mr-4">
|
||||||
|
<Clock className="w-3 h-3 mr-1" />
|
||||||
|
{formatDuration(song.duration)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Actions */}
|
||||||
|
<div className="flex items-center space-x-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleAddToQueue(song);
|
||||||
|
}}
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<Plus className="w-4 h-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</ScrollArea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user