/* eslint-disable @typescript-eslint/no-unused-vars */ 'use client'; import { useState, useEffect } from 'react'; import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Button } from '@/components/ui/button'; import { Tabs, TabsContent } from '@/components/ui/tabs'; import { AlbumArtwork } from '@/app/components/album-artwork'; import { ArtistIcon } from '@/app/components/artist-icon'; import { useNavidrome } from '@/app/components/NavidromeContext'; import { getNavidromeAPI, Album } from '@/lib/navidrome'; import { useAudioPlayer } from '@/app/components/AudioPlayerContext'; import { Shuffle } from 'lucide-react'; import Loading from '@/app/components/loading'; export default function BrowsePage() { const { artists, isLoading: contextLoading } = useNavidrome(); const { shuffleAllAlbums } = useAudioPlayer(); const [albums, setAlbums] = useState([]); const [currentPage, setCurrentPage] = useState(0); const [isLoadingAlbums, setIsLoadingAlbums] = useState(false); const [hasMoreAlbums, setHasMoreAlbums] = useState(true); const albumsPerPage = 84; const api = getNavidromeAPI(); const loadAlbums = async (page: number, append: boolean = false) => { try { setIsLoadingAlbums(true); const offset = page * albumsPerPage; // Use alphabeticalByName to get all albums in alphabetical order const newAlbums = await api.getAlbums('alphabeticalByName', albumsPerPage, offset); if (append) { setAlbums(prev => [...prev, ...newAlbums]); } else { setAlbums(newAlbums); } // If we got fewer albums than requested, we've reached the end setHasMoreAlbums(newAlbums.length === albumsPerPage); } catch (error) { console.error('Failed to load albums:', error); } finally { setIsLoadingAlbums(false); } }; useEffect(() => { loadAlbums(0); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Infinite scroll handler useEffect(() => { const handleScroll = (e: Event) => { const target = e.target as HTMLElement; if (!target || isLoadingAlbums || !hasMoreAlbums) return; const { scrollTop, scrollHeight, clientHeight } = target; const threshold = 200; // Load more when 200px from bottom if (scrollHeight - scrollTop - clientHeight < threshold) { loadMore(); } }; const scrollArea = document.querySelector('[data-radix-scroll-area-viewport]'); if (scrollArea) { scrollArea.addEventListener('scroll', handleScroll); return () => scrollArea.removeEventListener('scroll', handleScroll); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoadingAlbums, hasMoreAlbums, currentPage]); const loadMore = () => { if (isLoadingAlbums || !hasMoreAlbums) return; const nextPage = currentPage + 1; setCurrentPage(nextPage); loadAlbums(nextPage, true); }; if (contextLoading) { return ; } return (
<>

Artists

the people who make the music

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

Browse Albums

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

{albums.map((album) => ( ))}
{hasMoreAlbums && (
)} {!hasMoreAlbums && albums.length > 0 && (

All albums loaded ({albums.length} total)

)}
); }