Skip to content

Commit 3716b74

Browse files
committed
fix
1 parent 01ad830 commit 3716b74

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

frontend/src/components/pages/search/SearchPage.jsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useRef } from 'react';
22
import PropTypes from 'prop-types';
33
import { useLocation, useNavigate } from 'react-router-dom';
44
import 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,

0 commit comments

Comments
 (0)