Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

716 B
Raw Blame
import { skipToken, useQuery } from "@tanstack/react-query";
import globalSearch from "@/fetchers/search/global-search";

type SearchParams = {
  q: string;
  type?:
    | "all"
    | "tasks"
    | "projects"
    | "workspaces"
    | "comments"
    | "activities";
  workspaceId: string | undefined;
  projectId?: string;
  limit?: number;
};

function useGlobalSearch({ workspaceId, ...params }: SearchParams) {
  return useQuery({
    queryKey: ["search", { ...params, workspaceId }],
    queryFn: workspaceId
      ? () => globalSearch({ ...params, workspaceId })
      : skipToken,
    enabled: !!params.q && params.q.length >= 1,
    staleTime: 1000 * 30, // 30 seconds
  });
}

export default useGlobalSearch;