import React, { useState } from 'react'; import { IonSearchbar, IonModal, IonHeader, IonToolbar, IonTitle, IonButton, IonIcon, IonContent } from '@ionic/react'; import { close, list } from 'ionicons/icons'; import { InfiniteScrollList, SongItem, ListItem } from '../../components/common'; import { useArtists } from '../../hooks'; import { useAppSelector } from '../../redux'; import { selectSongs } from '../../redux'; import { debugLog } from '../../utils/logger'; const Artists: React.FC = () => { const { artists, searchTerm, hasMore, loadMore, handleSearchChange, getSongsByArtist, getSongCountByArtist, handleAddToQueue, handleToggleFavorite, } = useArtists(); const songs = useAppSelector(selectSongs); const songsCount = Object.keys(songs).length; const [selectedArtist, setSelectedArtist] = useState(null); // Debug logging debugLog('Artists component - artists count:', artists.length); debugLog('Artists component - selected artist:', selectedArtist); debugLog('Artists component - songs count:', songsCount); debugLog('Artists component - search term:', searchTerm); const handleArtistClick = (artist: string) => { setSelectedArtist(artist); }; const handleCloseArtistSongs = () => { setSelectedArtist(null); }; const selectedArtistSongs = selectedArtist ? getSongsByArtist(selectedArtist) : []; // Render artist item for InfiniteScrollList const renderArtistItem = (artist: string) => ( handleArtistClick(artist)} /> ); return ( <>
{/* Search Input */} handleSearchChange(e.detail.value || '')} debounce={300} showClearButton="focus" />
{/* Artists List */} items={artists} isLoading={songsCount === 0} hasMore={hasMore} onLoadMore={loadMore} renderItem={renderArtistItem} emptyTitle={searchTerm ? "No artists found" : "No artists available"} emptyMessage={searchTerm ? "Try adjusting your search terms" : "Artists will appear here once songs are loaded"} loadingTitle="Loading artists..." loadingMessage="Please wait while songs are being loaded from the database" /> {/* Artist Songs Modal */} Songs by {selectedArtist}
{selectedArtistSongs.map((song) => ( handleAddToQueue(song)} onToggleFavorite={() => handleToggleFavorite(song)} /> ))}
); }; export default Artists;