diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100644 index 877d932ef..000000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "permissions": { - "allow": [ - "Bash(chmod:*)", - "Bash(mkdir:*)", - "Bash(./gradlew:*)", - "Bash(grep:*)", - "Bash(cat:*)", - "Bash(find:*)", - "Bash(npm test)", - "Bash(npm test:*)", - "Bash(ls:*)", - "Bash(npx tsc:*)", - "Bash(node:*)", - "Bash(npm run dev:*)", - "Bash(sed:*)", - "Bash(npm run typecheck:*)" - ], - "deny": [], - "defaultMode": "acceptEdits" - } -} \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index a806d0098..bc6af38c9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,7 +39,7 @@ Frontend designed for **stateful document processing**: #### FileContext - Central State Management **Location**: `src/contexts/FileContext.tsx` - **Active files**: Currently loaded PDFs and their variants -- **Tool navigation**: Current mode (viewer/pageEditor/fileEditor/toolName) +- **Tool navigation**: Current mode (viewer/pageEditor/fileEditor/toolName) - **Memory management**: PDF document cleanup, blob URL lifecycle, Web Worker management - **IndexedDB persistence**: File storage with thumbnail caching - **Preview system**: Tools can preview results (e.g., Split → Viewer → back to Split) without context pollution @@ -89,7 +89,6 @@ return useToolOperation({ endpoint: '/api/v1/misc/compress-pdf', buildFormData: (params, file: File) => { /* single file */ }, multiFileEndpoint: false, - filePrefix: 'compressed_' }); ``` @@ -103,7 +102,7 @@ return useToolOperation({ endpoint: '/api/v1/general/split-pages', buildFormData: (params, files: File[]) => { /* all files */ }, multiFileEndpoint: true, - filePrefix: 'split_' + filePrefix: 'split_', }); ``` @@ -115,13 +114,12 @@ return useToolOperation({ return useToolOperation({ operationType: 'convert', customProcessor: async (params, files) => { /* custom logic */ }, - filePrefix: 'converted_' }); ``` **Benefits**: - **No Timeouts**: Operations run until completion (supports 100GB+ files) -- **Consistent**: All tools follow same pattern and interface +- **Consistent**: All tools follow same pattern and interface - **Maintainable**: Single responsibility hooks, easy to test and modify - **i18n Ready**: Built-in internationalization support - **Type Safe**: Full TypeScript support with generic interfaces @@ -185,7 +183,7 @@ return useToolOperation({ ## Frontend Architecture Status - **Core Status**: React SPA architecture complete with multi-tool workflow support -- **State Management**: FileContext handles all file operations and tool navigation +- **State Management**: FileContext handles all file operations and tool navigation - **File Processing**: Production-ready with memory management for large PDF workflows (up to 100GB+) - **Tool Integration**: Modular hook architecture with `useToolOperation` orchestrator - Individual hooks: `useToolState`, `useToolApiCalls`, `useToolResources` diff --git a/frontend/src/components/fileEditor/FileEditor.tsx b/frontend/src/components/fileEditor/FileEditor.tsx index 93cb4e6a0..f03404eac 100644 --- a/frontend/src/components/fileEditor/FileEditor.tsx +++ b/frontend/src/components/fileEditor/FileEditor.tsx @@ -11,6 +11,8 @@ import FileEditorThumbnail from './FileEditorThumbnail'; import FilePickerModal from '../shared/FilePickerModal'; import SkeletonLoader from '../shared/SkeletonLoader'; import { FileId, StirlingFile } from '../../types/fileContext'; +import { downloadBlob } from '../../utils/downloadUtils'; + interface FileEditorProps { onOpenPageEditor?: () => void; @@ -278,7 +280,6 @@ const FileEditor = ({ const handleDeleteFile = useCallback((fileId: FileId) => { const record = activeStirlingFileStubs.find(r => r.id === fileId); const file = record ? selectors.getFile(record.id) : null; - if (record && file) { // Remove file from context but keep in storage (close, don't delete) const contextFileId = record.id; @@ -290,6 +291,14 @@ const FileEditor = ({ } }, [activeStirlingFileStubs, selectors, removeFiles, setSelectedFiles, selectedFileIds]); + const handleDownloadFile = useCallback((fileId: FileId) => { + const record = activeStirlingFileStubs.find(r => r.id === fileId); + const file = record ? selectors.getFile(record.id) : null; + if (record && file) { + downloadBlob(file, file.name); + } + }, [activeStirlingFileStubs, selectors, setStatus]); + const handleViewFile = useCallback((fileId: FileId) => { const record = activeStirlingFileStubs.find(r => r.id === fileId); if (record) { @@ -401,6 +410,7 @@ const FileEditor = ({ onViewFile={handleViewFile} onSetStatus={setStatus} onReorderFiles={handleReorderFiles} + onDownloadFile={handleDownloadFile} toolMode={toolMode} isSupported={isFileSupported(record.name)} /> diff --git a/frontend/src/components/fileEditor/FileEditorThumbnail.tsx b/frontend/src/components/fileEditor/FileEditorThumbnail.tsx index 2a927d012..f28713c73 100644 --- a/frontend/src/components/fileEditor/FileEditorThumbnail.tsx +++ b/frontend/src/components/fileEditor/FileEditorThumbnail.tsx @@ -13,6 +13,7 @@ import { StirlingFileStub } from '../../types/fileContext'; import styles from './FileEditor.module.css'; import { useFileContext } from '../../contexts/FileContext'; import { FileId } from '../../types/file'; +import { formatFileSize } from '../../utils/fileUtils'; import ToolChain from '../shared/ToolChain'; @@ -28,7 +29,7 @@ interface FileEditorThumbnailProps { onViewFile: (fileId: FileId) => void; onSetStatus: (status: string) => void; onReorderFiles?: (sourceFileId: FileId, targetFileId: FileId, selectedFileIds: FileId[]) => void; - onDownloadFile?: (fileId: FileId) => void; + onDownloadFile: (fileId: FileId) => void; toolMode?: boolean; isSupported?: boolean; } @@ -61,29 +62,6 @@ const FileEditorThumbnail = ({ const pageCount = file.processedFile?.totalPages || 0; - const downloadSelectedFile = useCallback(() => { - // Prefer parent-provided handler if available - if (typeof onDownloadFile === 'function') { - onDownloadFile(file.id); - return; - } - - // Fallback: attempt to download using the File object if provided - const maybeFile = (file as unknown as { file?: File }).file; - if (maybeFile instanceof File) { - const link = document.createElement('a'); - link.href = URL.createObjectURL(maybeFile); - link.download = maybeFile.name || file.name || 'download'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - URL.revokeObjectURL(link.href); - return; - } - - // If we can't find a way to download, surface a status message - onSetStatus?.(typeof t === 'function' ? t('downloadUnavailable', 'Download unavailable for this item') : 'Download unavailable for this item'); - }, [file, onDownloadFile, onSetStatus, t]); const handleRef = useRef(null); // ---- Selection ---- @@ -91,12 +69,7 @@ const FileEditorThumbnail = ({ // ---- Meta formatting ---- const prettySize = useMemo(() => { - const bytes = file.size ?? 0; - if (bytes === 0) return '0 B'; - const k = 1024; - const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`; + return formatFileSize(file.size); }, [file.size]); const extUpper = useMemo(() => { @@ -305,7 +278,7 @@ const FileEditorThumbnail = ({