diff --git a/packages/frontend/src/components/PaginatedSongList.tsx b/packages/frontend/src/components/PaginatedSongList.tsx index 1409177..112ad0c 100644 --- a/packages/frontend/src/components/PaginatedSongList.tsx +++ b/packages/frontend/src/components/PaginatedSongList.tsx @@ -120,6 +120,7 @@ export const PaginatedSongList: React.FC = memo(({ const [localSearchQuery, setLocalSearchQuery] = useState(searchQuery); const observerRef = useRef(null); const loadingRef = useRef(null); + const scrollContainerRef = useRef(null); // Debounce search to prevent excessive API calls const debouncedSearchQuery = useDebounce(localSearchQuery, 300); @@ -233,7 +234,10 @@ export const PaginatedSongList: React.FC = memo(({ onLoadMore(); } }, - { threshold: 0.1 } + { + threshold: 0.1, + rootMargin: '100px' // Start loading when 100px away from the bottom + } ); observerRef.current.observe(loadingRef.current); @@ -338,23 +342,29 @@ export const PaginatedSongList: React.FC = memo(({ {/* Scrollable Song List */} - + {songItems} {/* Loading indicator for infinite scroll */} {loading && ( - + )} {/* Intersection observer target */} -
+
{/* End of results message */} {!hasMore && songs.length > 0 && ( - + No more songs to load @@ -363,7 +373,7 @@ export const PaginatedSongList: React.FC = memo(({ {/* No results message */} {!loading && songs.length === 0 && ( - + {searchQuery ? 'No songs found matching your search' : 'No songs available'} diff --git a/packages/frontend/src/components/PlaylistManager.tsx b/packages/frontend/src/components/PlaylistManager.tsx index 56ac47d..9d56de5 100644 --- a/packages/frontend/src/components/PlaylistManager.tsx +++ b/packages/frontend/src/components/PlaylistManager.tsx @@ -77,7 +77,7 @@ const PlaylistItem: React.FC = ({ onPlaylistMove, allFolders, }) => { - const [isOpen, setIsOpen] = useState(true); + const [isOpen, setIsOpen] = useState(false); const indent = level * 10; if (node.type === 'folder') { diff --git a/packages/frontend/src/hooks/usePaginatedSongs.ts b/packages/frontend/src/hooks/usePaginatedSongs.ts index 18d968a..76f0cd1 100644 --- a/packages/frontend/src/hooks/usePaginatedSongs.ts +++ b/packages/frontend/src/hooks/usePaginatedSongs.ts @@ -100,7 +100,7 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => { // Search songs with debouncing const searchSongs = useCallback((query: string) => { setSearchQuery(query); - setSongs([]); + // Don't clear songs immediately - let the new search results replace them setHasMore(true); setCurrentPage(1); setError(null); @@ -134,7 +134,7 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => { if (currentPlaylistRef.current !== playlistName) { currentPlaylistRef.current = playlistName; if (!isInitialLoad) { - setSongs([]); + // Don't clear songs immediately - let the new playlist results replace them setHasMore(true); setCurrentPage(1); setSearchQuery(initialSearch);