Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/git-providers/search-repositories-query.ts
2501 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useQuery } from "@tanstack/react-query";
8
import { useCurrentOrg } from "../organizations/orgs-query";
9
import { useDebounce } from "../../hooks/use-debounce";
10
import { scmClient } from "../../service/public-api";
11
12
export const useSearchRepositories = ({ searchString, limit }: { searchString: string; limit: number }) => {
13
// This disables the search behavior when flag is disabled
14
const { data: org } = useCurrentOrg();
15
const debouncedSearchString = useDebounce(searchString);
16
17
return useQuery(
18
["search-repositories", { organizationId: org?.id || "", searchString: debouncedSearchString, limit }],
19
async () => {
20
const { repositories } = await scmClient.searchRepositories({
21
searchString,
22
limit,
23
});
24
return repositories;
25
},
26
{
27
enabled: !!org && debouncedSearchString.trim().length > 0,
28
// Need this to keep previous results while we wait for a new search to complete since debouncedSearchString changes and updates the key
29
keepPreviousData: true,
30
// We intentionally don't want to trigger refetches here to avoid a loading state side effect of focusing
31
refetchOnWindowFocus: false,
32
refetchOnReconnect: false,
33
},
34
);
35
};
36
37