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