@@ -12,12 +12,14 @@ interface BooksListProps {
1212 onBookClick : ( book : Book ) => void ;
1313 enableLazyLoading ?: boolean ;
1414 enableInfiniteScroll ?: boolean ;
15+ searchQuery ?: string ;
1516}
1617
17- export default function BooksList ( {
18- onBookClick,
19- enableLazyLoading = true ,
20- enableInfiniteScroll = true
18+ export default function BooksList ( {
19+ onBookClick,
20+ enableLazyLoading = true ,
21+ enableInfiniteScroll = true ,
22+ searchQuery = ''
2123} : BooksListProps ) {
2224 const [ books , setBooks ] = useState < Book [ ] > ( [ ] ) ;
2325 const [ authors , setAuthors ] = useState < Author [ ] > ( [ ] ) ;
@@ -54,7 +56,10 @@ export default function BooksList({
5456 if ( filters . publisher ) params . publisher = filters . publisher ;
5557 if ( filters . ordering ) params . ordering = filters . ordering ;
5658
57- const response = await booksApi . getBooks ( params ) ;
59+ // Use search API if there's a non-empty search query, otherwise use regular books API
60+ const response = searchQuery && searchQuery . trim ( )
61+ ? await booksApi . searchBooks ( { ...params , search : searchQuery . trim ( ) } )
62+ : await booksApi . getBooks ( params ) ;
5863
5964 if ( isLoadMore ) {
6065 setBooks ( prev => [ ...prev , ...response . results ] ) ;
@@ -95,7 +100,7 @@ export default function BooksList({
95100
96101 useEffect ( ( ) => {
97102 loadBooks ( ) ;
98- } , [ filters . author , filters . category , filters . publisher , filters . ordering ] ) ;
103+ } , [ filters . author , filters . category , filters . publisher , filters . ordering , searchQuery ] ) ;
99104
100105 const handleAuthorChange = ( author : string ) => {
101106 const authorValue = author === 'all' ? '' : author ;
0 commit comments