This commit is contained in:
2025-06-19 02:09:24 +00:00
committed by GitHub
commit 717155ea22
78 changed files with 13145 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
'use client';
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { useState, useEffect } from 'react';
import { Separator } from "@/components/ui/separator";
import { Tabs, TabsContent } from "@/components/ui/tabs";
import { AlbumArtwork } from '@/app/components/album-artwork';
import { useNavidrome } from '@/app/components/NavidromeContext';
import { Album } from '@/lib/navidrome';
import Loading from '@/app/components/loading';
export default function Albumpage() {
const { albums, isLoading } = useNavidrome();
const [sortedAlbums, setSortedAlbums] = useState<Album[]>([]);
useEffect(() => {
if (albums.length > 0) {
// Sort albums alphabetically by name
const sorted = [...albums].sort((a, b) => a.name.localeCompare(b.name));
setSortedAlbums(sorted);
}
}, [albums]);
if (isLoading) {
return <Loading />;
}
return (
<div className="h-full px-4 py-6 lg:px-8">
<Tabs defaultValue="music" className="h-full space-y-6">
<TabsContent value="music" className="border-none p-0 outline-none">
<div className="flex items-center justify-between">
<div className="space-y-1">
<p className="text-2xl font-semibold tracking-tight">
Albums
</p>
<p className="text-sm text-muted-foreground">
All albums in your music library ({sortedAlbums.length} albums)
</p>
</div>
</div>
<Separator className="my-4" />
<div className="relative">
<ScrollArea>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4 pb-4">
{sortedAlbums.map((album) => (
<AlbumArtwork
key={album.id}
album={album}
className="w-full"
aspectRatio="square"
width={200}
height={200}
/>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</div>
</TabsContent>
</Tabs>
</div>
);
}

View File

@@ -0,0 +1,63 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
'use client';
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { useState, useEffect } from 'react';
import { Separator } from "@/components/ui/separator";
import { Tabs, TabsContent } from "@/components/ui/tabs";
import { ArtistIcon } from '@/app/components/artist-icon';
import { useNavidrome } from '@/app/components/NavidromeContext';
import { Artist } from '@/lib/navidrome';
import Loading from '@/app/components/loading';
export default function ArtistPage() {
const { artists, isLoading } = useNavidrome();
const [sortedArtists, setSortedArtists] = useState<Artist[]>([]);
useEffect(() => {
if (artists.length > 0) {
// Sort artists alphabetically by name
const sorted = [...artists].sort((a, b) => a.name.localeCompare(b.name));
setSortedArtists(sorted);
}
}, [artists]);
if (isLoading) {
return <Loading />;
}
return (
<div className="h-full px-4 py-6 lg:px-8">
<Tabs defaultValue="music" className="h-full space-y-6">
<TabsContent value="music" className="border-none p-0 outline-none">
<div className="flex items-center justify-between">
<div className="space-y-1">
<p className="text-2xl font-semibold tracking-tight">
Artists
</p>
<p className="text-sm text-muted-foreground">
All artists in your music library ({sortedArtists.length} artists)
</p>
</div>
</div>
<Separator className="my-4" />
<div className="relative">
<ScrollArea>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4 pb-4">
{sortedArtists.map((artist) => (
<ArtistIcon
key={artist.id}
artist={artist}
className="flex justify-center"
size={150}
/>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</div>
</TabsContent>
</Tabs>
</div>
);
}

View File

@@ -0,0 +1,95 @@
'use client';
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { Separator } from "@/components/ui/separator";
import { Tabs, TabsContent } from "@/components/ui/tabs";
import { useNavidrome } from '@/app/components/NavidromeContext';
import Loading from '@/app/components/loading';
import { Button } from '@/components/ui/button';
import { PlusCircledIcon } from "@radix-ui/react-icons";
import Link from 'next/link';
const PlaylistsPage: React.FC = () => {
const { playlists, isLoading, createPlaylist } = useNavidrome();
const handleCreatePlaylist = async () => {
const name = prompt('Enter playlist name:');
if (name) {
try {
await createPlaylist(name);
} catch (error) {
console.error('Failed to create playlist:', error);
}
}
};
if (isLoading) {
return <Loading />;
}
return (
<div className="h-full px-4 py-6 lg:px-8">
<Tabs defaultValue="music" className="h-full space-y-6">
<TabsContent value="music" className="border-none p-0 outline-none">
<div className="flex items-center justify-between">
<div className="space-y-1">
<p className="text-2xl font-semibold tracking-tight">
Playlists
</p>
<p className="text-sm text-muted-foreground">
Your custom playlists ({playlists.length} playlists)
</p>
</div>
<Button onClick={handleCreatePlaylist}>
<PlusCircledIcon className="mr-2 h-4 w-4" />
New Playlist
</Button>
</div>
<Separator className="my-4" />
<div className="relative">
<ScrollArea>
<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) => (
<Link key={playlist.id} href={`/playlist/${playlist.id}`}>
<div className="p-4 rounded-lg border border-border hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer">
<div className="flex items-center space-x-4">
<div className="w-12 h-12 bg-muted rounded-md flex items-center justify-center">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
className="h-6 w-6"
viewBox="0 0 24 24"
>
<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" />
</svg>
</div>
<div className="flex-1 min-w-0">
<p className="font-medium leading-none truncate">{playlist.name}</p>
<p className="text-sm text-muted-foreground mt-1">
{playlist.songCount} songs
</p>
{playlist.comment && (
<p className="text-xs text-muted-foreground mt-1 truncate">
{playlist.comment}
</p>
)}
</div>
</div>
</div>
</Link>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</div>
</TabsContent>
</Tabs>
</div>
);
};
export default PlaylistsPage;

294
app/library/songs/page.tsx Normal file
View File

@@ -0,0 +1,294 @@
'use client';
import React, { useEffect, useState } from 'react';
import Image from 'next/image';
import { useNavidrome } from '@/app/components/NavidromeContext';
import { useAudioPlayer } from '@/app/components/AudioPlayerContext';
import { Song } from '@/lib/navidrome';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Input } from '@/components/ui/input';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Search, Play, Plus, Clock, User, Disc } from 'lucide-react';
import Loading from '@/app/components/loading';
import { getNavidromeAPI } from '@/lib/navidrome';
type SortOption = 'title' | 'artist' | 'album' | 'year' | 'duration' | 'track';
type SortDirection = 'asc' | 'desc';
export default function SongsPage() {
const { getAllSongs } = useNavidrome();
const { playTrack, addToQueue, currentTrack } = useAudioPlayer();
const [songs, setSongs] = useState<Song[]>([]);
const [filteredSongs, setFilteredSongs] = useState<Song[]>([]);
const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState<SortOption>('title');
const [sortDirection, setSortDirection] = useState<SortDirection>('asc');
const api = getNavidromeAPI();
useEffect(() => {
const fetchSongs = async () => {
setLoading(true);
try {
const allSongs = await getAllSongs();
setSongs(allSongs);
setFilteredSongs(allSongs);
} catch (error) {
console.error('Failed to fetch songs:', error);
}
setLoading(false);
};
fetchSongs();
}, [getAllSongs]);
useEffect(() => {
let filtered = songs;
// Apply search filter
if (searchQuery.trim()) {
const query = searchQuery.toLowerCase();
filtered = songs.filter(song =>
song.title.toLowerCase().includes(query) ||
song.artist.toLowerCase().includes(query) ||
song.album.toLowerCase().includes(query)
);
}
// Apply sorting
filtered = [...filtered].sort((a, b) => {
let aValue: string | number;
let bValue: string | number;
switch (sortBy) {
case 'title':
aValue = a.title.toLowerCase();
bValue = b.title.toLowerCase();
break;
case 'artist':
aValue = a.artist.toLowerCase();
bValue = b.artist.toLowerCase();
break;
case 'album':
aValue = a.album.toLowerCase();
bValue = b.album.toLowerCase();
break;
case 'year':
aValue = a.year || 0;
bValue = b.year || 0;
break;
case 'duration':
aValue = a.duration;
bValue = b.duration;
break;
case 'track':
aValue = a.track || 0;
bValue = b.track || 0;
break;
default:
aValue = a.title.toLowerCase();
bValue = b.title.toLowerCase();
}
if (sortDirection === 'asc') {
return aValue < bValue ? -1 : aValue > bValue ? 1 : 0;
} else {
return aValue > bValue ? -1 : aValue < bValue ? 1 : 0;
}
});
setFilteredSongs(filtered);
}, [songs, searchQuery, sortBy, sortDirection]);
const handlePlaySong = (song: Song) => {
const track = {
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
};
playTrack(track);
};
const handleAddToQueue = (song: Song) => {
const track = {
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
};
addToQueue(track);
};
const formatDuration = (seconds: number): string => {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
};
const isCurrentlyPlaying = (song: Song): boolean => {
return currentTrack?.id === song.id;
};
if (loading) {
return <Loading />;
}
return (
<div className="h-full px-4 py-6 lg:px-8">
<div className="space-y-6">
{/* Header */}
<div className="space-y-2">
<h1 className="text-3xl font-semibold tracking-tight">Songs</h1>
<p className="text-sm text-muted-foreground">
{filteredSongs.length} of {songs.length} songs
</p>
</div>
{/* Search and Filters */}
<div className="flex flex-col sm:flex-row gap-4">
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground w-4 h-4" />
<Input
placeholder="Search songs, artists, or albums..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10"
/>
</div>
<div className="flex gap-2">
<Select value={sortBy} onValueChange={(value: SortOption) => setSortBy(value)}>
<SelectTrigger className="w-[140px]">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="title">Title</SelectItem>
<SelectItem value="artist">Artist</SelectItem>
<SelectItem value="album">Album</SelectItem>
<SelectItem value="year">Year</SelectItem>
<SelectItem value="duration">Duration</SelectItem>
<SelectItem value="track">Track #</SelectItem>
</SelectContent>
</Select>
<Button
variant="outline"
size="sm"
onClick={() => setSortDirection(sortDirection === 'asc' ? 'desc' : 'asc')}
>
{sortDirection === 'asc' ? '↑' : '↓'}
</Button>
</div>
</div>
<Separator />
{/* Songs List */}
<ScrollArea className="h-[calc(100vh-300px)]">
{filteredSongs.length === 0 ? (
<div className="text-center py-12">
<p className="text-muted-foreground">
{searchQuery ? 'No songs found matching your search.' : 'No songs available.'}
</p>
</div>
) : (
<div className="space-y-1">
{filteredSongs.map((song, index) => (
<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={() => handlePlaySong(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>
{song.year && (
<span className="text-xs text-muted-foreground bg-muted px-1.5 py-0.5 rounded">
{song.year}
</span>
)}
</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" />
<span className="truncate">{song.artist}</span>
</div>
<div className="flex items-center gap-1">
<Disc className="w-3 h-3" />
<span className="truncate">{song.album}</span>
</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>
);
}