import { useQuery, useQueryClient } from "@tanstack/react-query"; import { FolderOpen } from "lucide-react"; import { FileTree } from "~/client/components/file-tree"; import { listFilesOptions } from "../api-client/@tanstack/react-query.gen"; import { useFileBrowser } from "../hooks/use-file-browser"; type VolumeFileBrowserProps = { volumeName: string; enabled?: boolean; withCheckboxes?: boolean; selectedPaths?: Set; onSelectionChange?: (paths: Set) => void; foldersOnly?: boolean; className?: string; emptyMessage?: string; emptyDescription?: string; }; export const VolumeFileBrowser = ({ volumeName, enabled = true, withCheckboxes = false, selectedPaths, onSelectionChange, foldersOnly = false, className, emptyMessage = "This volume appears to be empty.", emptyDescription, }: VolumeFileBrowserProps) => { const queryClient = useQueryClient(); const { data, isLoading, error } = useQuery({ ...listFilesOptions({ path: { name: volumeName } }), enabled, }); const fileBrowser = useFileBrowser({ initialData: data, isLoading, fetchFolder: async (path) => { return await queryClient.ensureQueryData( listFilesOptions({ path: { name: volumeName }, query: { path }, }), ); }, prefetchFolder: (path) => { queryClient.prefetchQuery( listFilesOptions({ path: { name: volumeName }, query: { path }, }), ); }, }); if (fileBrowser.isLoading) { return (

Loading files...

); } if (error) { return (

Failed to load files: {(error as Error).message}

); } if (fileBrowser.isEmpty) { return (

{emptyMessage}

{emptyDescription &&

{emptyDescription}

}
); } return (
); };