Skip to content

Commit

Permalink
switch to debounced query
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobjeevan committed Jan 11, 2025
1 parent 04b8c10 commit 06dba7b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/hooks/useOrganizationLevel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { useEffect, useMemo } from "react";
import { useEffect, useMemo, useState } from "react";

import useDebouncedState from "@/hooks/useDebouncedState";
import { FilterState } from "@/hooks/useFilters";

import query from "@/Utils/request/query";
Expand All @@ -25,17 +24,11 @@ export function useOrganizationLevel({
onChange,
getParentId,
}: UseOrganizationLevelProps) {
const [levelSearch, setLevelSearch] = useDebouncedState("", 500);
const [levelSearch, setLevelSearch] = useState("");

const { data: availableOrgs } = useQuery<{ results: Organization[] }>({
queryKey: ["organizations-available", getParentId(index), levelSearch],
queryFn: query(organizationApi.getPublicOrganizations, {
queryParams: {
...(index > 0 && { parent: getParentId(index) }),
...(index === 0 && { level_cache: 1 }),
name: levelSearch || undefined,
},
}),
queryKey: ["organizations-available", getParentId(index)],
queryFn: query.debounced(organizationApi.getPublicOrganizations),
enabled:
!skip &&
index <= selectedLevels.length &&
Expand Down

0 comments on commit 06dba7b

Please sign in to comment.