import React, { createContext, useContext } from 'react'; import { useFileOperations, useFolderOperations, type FilePreviewResult } from '../hooks/useFiles'; import type { FolderInfo } from '../api/fileApi'; interface FileContextType { handleFileUpload: (file: File, workflowId?: string) => Promise<{ success: boolean; fileData?: any; error?: string }>; handleFileDelete: (fileId: string, onOptimisticDelete?: () => void) => Promise; handleFilePreview: (fileId: string, fileName: string, mimeType?: string) => Promise; handleFileDownload: (fileId: string, fileName: string) => Promise; uploadingFile: boolean; deletingFiles: Set; previewingFiles: Set; downloadingFiles: Set; handleCreateFolder: (name: string, parentId?: string | null) => Promise; handleRenameFolder: (folderId: string, name: string) => Promise; handleDeleteFolderCascade: (folderId: string) => Promise<{ deletedFolders: number; deletedFiles: number }>; handleMoveFolder: (folderId: string, parentId: string | null) => Promise; handleMoveFiles: (fileIds: string[], targetFolderId: string | null) => Promise; fetchOwnFolderTree: () => Promise; fetchSharedFolderTree: () => Promise; } export const FileContext = createContext(undefined); export function FileProvider({ children }: { children: React.ReactNode }) { const { handleFileUpload: hookHandleFileUpload, handleFileDelete: hookHandleFileDelete, handleFilePreview, handleFileDownload, uploadingFile, deletingFiles, previewingFiles, downloadingFiles, } = useFileOperations(); const { handleCreateFolder, handleRenameFolder, handleMoveFolder, handleDeleteFolderCascade, handleMoveFiles, fetchOwnFolderTree, fetchSharedFolderTree, } = useFolderOperations(); return ( { await handleFileDownload(fileId, fileName); }, uploadingFile, deletingFiles, previewingFiles, downloadingFiles, handleCreateFolder, handleRenameFolder, handleMoveFolder, handleDeleteFolderCascade, handleMoveFiles, fetchOwnFolderTree, fetchSharedFolderTree, }} > {children} ); } export function useFileContext() { const context = useContext(FileContext); if (context === undefined) { throw new Error('useFileContext must be used within a FileProvider'); } return context; }