'use client'; import { useCallback, useEffect } from 'react'; import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Button } from '@/components/ui/button'; import { AlbumArtwork } from '@/app/components/album-artwork'; import { ArtistIcon } from '@/app/components/artist-icon'; import { useNavidrome } from '@/app/components/NavidromeContext'; import { useAudioPlayer } from '@/app/components/AudioPlayerContext'; import { useProgressiveAlbumLoading } from '@/hooks/use-progressive-album-loading'; import { Shuffle, ArrowDown, RefreshCcw, Loader2 } from 'lucide-react'; import Loading from '@/app/components/loading'; import { useInView } from 'react-intersection-observer'; export default function BrowsePage() { const { artists: allArtists, isLoading: contextLoading } = useNavidrome(); // Filter to only show album artists (artists with at least one album) const artists = allArtists.filter(artist => artist.albumCount && artist.albumCount > 0); const { shuffleAllAlbums } = useAudioPlayer(); // Use our progressive loading hook const { albums, isLoading, hasMore, loadMoreAlbums, refreshAlbums } = useProgressiveAlbumLoading('alphabeticalByName'); // Infinite scroll with intersection observer const { ref, inView } = useInView({ threshold: 0.1, triggerOnce: false }); // Load more albums when the load more sentinel comes into view useEffect(() => { if (inView && hasMore && !isLoading) { loadMoreAlbums(); } }, [inView, hasMore, isLoading, loadMoreAlbums]); // Pull-to-refresh simulation const handleRefresh = useCallback(() => { refreshAlbums(); }, [refreshAlbums]); if (contextLoading) { return ; } return (

Browse Artists

the people who make the music

{artists.map((artist, index) => ( ))}

Browse Albums

Browse the full collection of albums ({albums.length} loaded).

{albums.map((album, index) => ( ))}
{/* Load more sentinel */} {hasMore && (
)} {!hasMore && albums.length > 0 && (

All albums loaded ({albums.length} total)

)} {albums.length === 0 && !isLoading && (

No albums found

Try refreshing or check your connection

)}
); }