Skip to content

Commit 41b8806

Browse files
Update SearchResults.tsx
1 parent 4f442f2 commit 41b8806

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

frontend/src/pages/search/SearchResults.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import ContentSearchResult from "../../components/search/ContentSearchResult";
77
import "../../styles/search/search.scss";
88

99
export default function SearchResults() {
10-
// Search parameters
1110
const [searchParams] = useSearchParams();
1211
const query = searchParams.get("query") || "";
13-
14-
// State for search results
1512
const [users, setUsers] = useState<SearchUser[]>([]);
1613
const [content, setContent] = useState<SearchContent[]>([]);
1714
const [offset, setOffset] = useState(0);
@@ -23,12 +20,10 @@ export default function SearchResults() {
2320
const fetchInProgress = useRef(false);
2421
const currentQuery = useRef("");
2522

26-
// Constants
2723
const USER_LIMIT = 10;
2824
const CONTENT_LIMIT = 20;
2925
const TOTAL_LIMIT = USER_LIMIT + CONTENT_LIMIT;
3026

31-
// Define fetchResults with useCallback to avoid dependency issues
3227
const fetchResults = useCallback(async () => {
3328
// Prevent duplicate calls and check valid query
3429
if (!query ||
@@ -56,8 +51,7 @@ export default function SearchResults() {
5651
if ((newUsers.length + newContent.length) < TOTAL_LIMIT) {
5752
setHasMore(false);
5853
}
59-
60-
// Use type-safe spread to combine previous and new results
54+
6155
setUsers(prev => [...prev, ...newUsers]);
6256
setContent(prev => [...prev, ...newContent]);
6357
setOffset(prev => prev + newUsers.length + newContent.length);
@@ -82,7 +76,7 @@ export default function SearchResults() {
8276
}
8377
}, [query]);
8478

85-
// Initial data fetch - only run once per query
79+
// Initial data fetch - only run once per query!!
8680
useEffect(() => {
8781
if (!initialFetchDone.current && query && query.length >= 3) {
8882
initialFetchDone.current = true;

0 commit comments

Comments
 (0)