'use client'; import React, { useEffect, useState } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { Music, Users, Disc, ListMusic, Heart, Play } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { getNavidromeAPI } from '@/lib/navidrome'; import NavidromeAPI from '@/lib/navidrome'; import { useAudioPlayer } from '@/app/components/AudioPlayerContext'; import { useIsMobile } from '@/hooks/use-mobile'; interface Album { id: string; name: string; artist: string; artistId?: string; coverArt?: string; year?: number; songCount: number; } interface LibraryStats { albums: number; artists: number; songs: number; playlists: number; } export default function LibraryPage() { const [recentAlbums, setRecentAlbums] = useState([]); const [stats, setStats] = useState({ albums: 0, artists: 0, songs: 0, playlists: 0 }); const [loading, setLoading] = useState(true); const [api, setApi] = useState(null); const { playAlbum } = useAudioPlayer(); const isMobile = useIsMobile(); useEffect(() => { const loadLibraryData = async () => { try { const navidromeApi = getNavidromeAPI(); if (!navidromeApi) { console.error('Navidrome API not available'); return; } setApi(navidromeApi); // Load recent albums const albumsData = await navidromeApi.getAlbums('newest', 4, 0); setRecentAlbums(albumsData || []); // Load library stats const [allAlbums, allArtists, allPlaylists] = await Promise.all([ navidromeApi.getAlbums('alphabeticalByName', 1, 0), // Just to get count navidromeApi.getArtists(), navidromeApi.getPlaylists() ]); setStats({ albums: allAlbums?.length || 0, artists: allArtists?.length || 0, songs: 0, // We don't have a direct method for this playlists: allPlaylists?.length || 0 }); } catch (error) { console.error('Failed to load library data:', error); } finally { setLoading(false); } }; loadLibraryData(); }, []); const handlePlayAlbum = async (album: Album) => { try { await playAlbum(album.id); } catch (error) { console.error('Failed to play album:', error); } }; const libraryLinks = [ { href: '/library/albums', label: 'Albums', icon: Disc, description: 'Browse all albums', count: stats.albums }, { href: '/library/artists', label: 'Artists', icon: Users, description: 'Discover artists', count: stats.artists }, { href: '/library/songs', label: 'Songs', icon: Music, description: 'All your music', count: stats.songs }, { href: '/library/playlists', label: 'Playlists', icon: ListMusic, description: 'Your playlists', count: stats.playlists }, { href: '/favorites', label: 'Favorites', icon: Heart, description: 'Starred music', count: 0 } ]; if (loading) { return (

Your Library

{/* Loading skeleton for library links */}

Browse

{[...Array(5)].map((_, i) => (
))}
{/* Loading skeleton for recent albums */}

Recently Added

{[...Array(4)].map((_, i) => (
))}
); } return (

Your Library

{/* Library Navigation - Always at top */}
{/*

Browse

*/}
{libraryLinks.map((link) => { const Icon = link.icon; return (

{link.label}

{link.description}

{link.count > 0 && (
{link.count}
)}
); })}
{/* Recently Added Albums - At bottom on mobile, after Browse on desktop */}

Recently Added

{recentAlbums.map((album) => (
{album.name} {!isMobile && ( )}

{album.name}

e.stopPropagation()} > {album.artist} {/* {album.year && (

{album.year}

)} */}
))}
); }