import { useQuery, useQueryClient } from "@tanstack/react-query"; import { FileTree } from "./file-tree"; import { ScrollArea } from "./ui/scroll-area"; import { browseFilesystemOptions } from "../api-client/@tanstack/react-query.gen"; import { useFileBrowser } from "../hooks/use-file-browser"; type Props = { onSelectPath: (path: string) => void; selectedPath?: string; }; export const DirectoryBrowser = ({ onSelectPath, selectedPath }: Props) => { const queryClient = useQueryClient(); const { data, isLoading } = useQuery({ ...browseFilesystemOptions({ query: { path: "/" } }), }); const fileBrowser = useFileBrowser({ initialData: data, isLoading, fetchFolder: async (path) => { return await queryClient.ensureQueryData(browseFilesystemOptions({ query: { path } })); }, prefetchFolder: (path) => { queryClient.prefetchQuery(browseFilesystemOptions({ query: { path } })); }, }); if (fileBrowser.isLoading) { return (