Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
clairechabas committed Jan 13, 2025
1 parent f66b402 commit c6c3f00
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions packages/gitbook/src/components/Search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,26 @@ export const SearchResults = React.forwardRef(function SearchResults(

const language = useLanguage();
const trackEvent = useTrackEvent();

const debounceTimeout = React.useRef<Timer | null>(null);
const [results, setResults] = React.useState<ResultType[]>([]);
const [isLoading, setIsLoading] = React.useState(false);
// const [resultsState, setResultsState] = React.useState<{
// results: ResultType[];
// fetching: boolean;
// }>({ results: [], fetching: true });

const [cursor, setCursor] = React.useState<number | null>(null);
const refs = React.useRef<(null | HTMLAnchorElement)[]>([]);
const suggestedQuestionsRef = React.useRef<null | ResultType[]>(null);

const fetchResults = React.useCallback(
async (query: string, global: boolean, pointer?: any, revisionId?: any) => {
const fetchedResults = await (global
? searchAllSiteContent(query, pointer)
: searchSiteSpaceContent(query, pointer, revisionId));

return fetchedResults || [];
},
[]
);

React.useEffect(() => {
setIsLoading(true);

Expand Down Expand Up @@ -107,17 +116,28 @@ export const SearchResults = React.forwardRef(function SearchResults(
}

debounceTimeout.current = setTimeout(async () => {
const fetchedResults = await (global
? searchAllSiteContent(query, pointer)
: searchSiteSpaceContent(query, pointer, revisionId));
// const fetchedResults = await (global
// ? searchAllSiteContent(query, pointer)
// : searchSiteSpaceContent(query, pointer, revisionId));

// setResults(withAsk ? withQuestionResult(fetchedResults, query) : fetchedResults);
fetchResults(query, global, pointer, revisionId).then((fetchedResults) => {
setResults(withAsk ? withQuestionResult(fetchedResults, query) : fetchedResults);
setIsLoading(false);

// Track the event only when the query changes
trackEvent({
type: 'search_type_query',
query,
});
});

setResults(withAsk ? withQuestionResult(fetchedResults, query) : fetchedResults);
setIsLoading(false);

trackEvent({
type: 'search_type_query',
query,
});
// trackEvent({
// type: 'search_type_query',
// query,
// });
}, 350);

return () => {
Expand Down

0 comments on commit c6c3f00

Please sign in to comment.