1- import { FC , useCallback , useState } from 'react'
1+ import { FC , useCallback , useEffect , useState } from 'react'
22import classNames from 'classnames'
33
44import { Button , ContentLayout , LinkButton , LoadingCircles } from '~/libs/ui'
@@ -17,6 +17,9 @@ import styles from './SearchResultsPage.module.scss'
1717const SearchResultsPage : FC = ( ) => {
1818 const [ showSkillsModal , setShowSkillsModal ] = useState ( false )
1919
20+ const [ currentPage , setCurrentPage ] = useState ( 1 )
21+ const itemsPerPage = 10
22+
2023 const [ skills , setSkills ] = useUrlQuerySearchParms ( 'q' )
2124 const {
2225 loading,
@@ -25,6 +28,27 @@ const SearchResultsPage: FC = () => {
2528 hasNext,
2629 total,
2730 } : InfiniteTalentMatchesResposne = useInfiniteTalentMatches ( skills )
31+ const paginatedMatches = matches . slice ( 0 , currentPage * itemsPerPage )
32+
33+ useEffect ( ( ) => {
34+ const handleScroll : ( ) => void = ( ) => {
35+ const scrollY = window . scrollY
36+ const visibleHeight = window . innerHeight
37+ const fullHeight = document . body . scrollHeight
38+ const footerElem = document . getElementById ( 'footer-nav-el' )
39+ const footerHeight = ( footerElem && footerElem . offsetHeight ) || 650
40+ if ( scrollY + visibleHeight >= fullHeight - ( footerHeight + 100 ) ) {
41+ // Scroll near bottom
42+ setCurrentPage ( prev => {
43+ const maxPages = Math . ceil ( matches . length / itemsPerPage )
44+ return prev < maxPages ? prev + 1 : prev
45+ } )
46+ }
47+ }
48+
49+ window . addEventListener ( 'scroll' , handleScroll )
50+ return ( ) => window . removeEventListener ( 'scroll' , handleScroll )
51+ } , [ matches ] )
2852
2953 const toggleSkillsModal = useCallback ( ( ) => setShowSkillsModal ( s => ! s ) , [ ] )
3054
@@ -100,7 +124,7 @@ const SearchResultsPage: FC = () => {
100124 ) }
101125 </ div >
102126 < div className = { styles . resultsWrap } >
103- { matches . map ( member => (
127+ { paginatedMatches . map ( member => (
104128 < TalentCard
105129 queriedSkills = { skills }
106130 member = { member }
0 commit comments