File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
frontend/src/components/pages/search Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1- import React , { useState , useEffect } from 'react' ;
1+ import React , { useState , useEffect , useRef } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { useLocation , useNavigate } from 'react-router-dom' ;
44import axios from 'axios' ;
@@ -104,16 +104,20 @@ const SearchPage = ({ apiPrefix }) => {
104104 }
105105 } ;
106106
107- const handleLoadMore = ( ) => {
108- const currentScrollY = window . scrollY ;
107+ const [ loading , setLoading ] = useState ( false ) ;
108+ const scrollPosition = useRef ( 0 ) ;
109109
110+ const handleLoadMore = async ( ) => {
111+ scrollPosition . current = window . scrollY ;
112+ setLoading ( true ) ;
110113 setCurrentPage ( ( prevPage ) => prevPage + 1 ) ;
111-
112- setTimeout ( ( ) => {
113- window . scrollTo ( 0 , currentScrollY ) ;
114- } , 500 ) ;
115114 } ;
116115
116+ useEffect ( ( ) => {
117+ window . scrollTo ( 0 , scrollPosition . current ) ;
118+ setLoading ( false ) ;
119+ } , [ loading , searchResults ] ) ;
120+
117121 const applyInputFilters = ( ) => {
118122 setFilters ( ( prevFilters ) => ( {
119123 ...prevFilters ,
You can’t perform that action at this time.
0 commit comments