import { useEffect } from 'react' ; import { search , isPageExist , Entry } from '../../search-api' ; import { useStore , AppStatus , Item } from '../../store-provider' ; const GettingResults = ( ) => { const query = encodeURIComponent ( useStore ( state => state . globals . query ) ) ; const mirror = useStore ( state => state . globals . mirror ) || '' ; const currentPage = useStore ( state => state . globals . currentPage ) ; const searchReqPattern = useStore ( state => state . config ?. searchReqPattern ) || '' ; const pageSize = useStore ( state => state . config ?. pageSize ) || 25 ; const setEntries = useStore ( state => state . set . entries ) ; const setListBuffer = useStore ( state => state . set . listBuffer ) ; const setStatus = useStore ( state => state . set . status ) ; const setNextPage = useStore ( state => state . set . nextPage ) ; const setLastFailedAction = useStore ( state => state . set . lastFailedAction ) ; useEffect ( ( ) => { const doSearchRequest = async ( ) => { const results = await search ( searchReqPattern , mirror , query , currentPage , pageSize ) ; if ( results == null ) { setLastFailedAction ( ( ) => setStatus ( 'gettingResults' ) ) ; setStatus ( 'failed' ) ; return ; } const nextPage = await isPageExist ( searchReqPattern , mirror , query , currentPage + 1 , pageSize ) ; if ( nextPage == null ) { setLastFailedAction ( ( ) => setStatus ( 'gettingResults' ) ) ; setStatus ( 'failed' ) ; return ; } setNextPage ( nextPage ) ; setListBuffer ( [ ] ) ; setEntries ( results ) ; setStatus ( 'results' ) ; } ; doSearchRequest ( ) ; } , [ ] ) ; return null ; } ; export default GettingResults ;