mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-29 10:56:24 +02:00
- Fix errors in connectors-api.service (use .issues instead of .errors) - Create useGoogleDriveFolders hook with proper React Query integration - Add Google Drive folders cache keys with proper query invalidation - Refactor GoogleDriveFolderTree to use React Query hook for root data - Remove manual state management (isInitialized, setRootItems, loadRootItems) - Remove unused state (driveFolders, isLoadingFolders) from manage page - Simplify handleOpenDriveFolderDialog function - Automatic loading, caching, error handling, and refetching via React Query - Better performance with proper caching and state management
29 lines
750 B
TypeScript
29 lines
750 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { connectorsApiService } from "@/lib/apis/connectors-api.service";
|
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
|
|
|
interface UseGoogleDriveFoldersOptions {
|
|
connectorId: number;
|
|
parentId?: string;
|
|
enabled?: boolean;
|
|
}
|
|
|
|
export function useGoogleDriveFolders({
|
|
connectorId,
|
|
parentId,
|
|
enabled = true,
|
|
}: UseGoogleDriveFoldersOptions) {
|
|
return useQuery({
|
|
queryKey: cacheKeys.connectors.googleDrive.folders(connectorId, parentId),
|
|
queryFn: async () => {
|
|
return connectorsApiService.listGoogleDriveFolders({
|
|
connector_id: connectorId,
|
|
parent_id: parentId,
|
|
});
|
|
},
|
|
enabled: enabled && !!connectorId,
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
retry: 2,
|
|
});
|
|
}
|
|
|