1
- import { FC , useCallback , useState } from 'react'
1
+ import { FC , useCallback , useEffect , useState } from 'react'
2
2
import classNames from 'classnames'
3
3
4
4
import { Button , ContentLayout , LinkButton , LoadingCircles } from '~/libs/ui'
@@ -17,6 +17,9 @@ import styles from './SearchResultsPage.module.scss'
17
17
const SearchResultsPage : FC = ( ) => {
18
18
const [ showSkillsModal , setShowSkillsModal ] = useState ( false )
19
19
20
+ const [ currentPage , setCurrentPage ] = useState ( 1 )
21
+ const itemsPerPage = 10
22
+
20
23
const [ skills , setSkills ] = useUrlQuerySearchParms ( 'q' )
21
24
const {
22
25
loading,
@@ -25,6 +28,27 @@ const SearchResultsPage: FC = () => {
25
28
hasNext,
26
29
total,
27
30
} : 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 ] )
28
52
29
53
const toggleSkillsModal = useCallback ( ( ) => setShowSkillsModal ( s => ! s ) , [ ] )
30
54
@@ -100,7 +124,7 @@ const SearchResultsPage: FC = () => {
100
124
) }
101
125
</ div >
102
126
< div className = { styles . resultsWrap } >
103
- { matches . map ( member => (
127
+ { paginatedMatches . map ( member => (
104
128
< TalentCard
105
129
queriedSkills = { skills }
106
130
member = { member }
0 commit comments