diff --git a/frontend/src/appShellContext.js b/frontend/src/appShellContext.js new file mode 100644 index 0000000..054a48c --- /dev/null +++ b/frontend/src/appShellContext.js @@ -0,0 +1,12 @@ +import React from 'react'; + +export const AppShellContext = React.createContext(null); + +export const useAppShell = () => { + const context = React.useContext(AppShellContext); + if (!context) { + throw new Error('AppShellContext not found. Ensure routes are nested under AppLayout.'); + } + return context; +}; + diff --git a/frontend/src/index.jsx b/frontend/src/index.jsx index 5bf57b6..4f64585 100644 --- a/frontend/src/index.jsx +++ b/frontend/src/index.jsx @@ -1,10 +1,10 @@ import React, { useCallback, + useContext, useEffect, useMemo, useRef, useState, - useContext, useReducer, } from 'react'; import { createRoot } from 'react-dom/client'; @@ -28,11 +28,11 @@ import DetailPanel from './detail/DetailPanel'; import TagsPanel from './tags/TagsPanel'; import CorrespondentsPanel from './correspondents/CorrespondentsPanel'; import { CORRESPONDENT_ROLES } from './constants/correspondents'; -import { DownloadIcon } from './ui/icons'; import TagManager from './tag_manager'; -import { formatFileSize } from './utils/format'; import Sidebar from './sidebar/Sidebar'; import DocumentsTable from './documents/DocumentsTable'; +import { AppShellContext, useAppShell } from './appShellContext'; +import DocumentViewerRoute from './routes/DocumentViewerRoute'; const runtimeApiBase = typeof window !== 'undefined' && window.__PAPERCRATE_API_BASE_URL @@ -226,91 +226,6 @@ const LoginView = ({ onSubmit, status }) => ( -const PreviewWorkspace = ({ - document, - previewEntry, - onClose, - onRegenerateThumbnails, -}) => { - if (!document) { - return null; - } - - const title = document.title || document.original_name || 'Document'; - const mime = previewEntry?.contentType || document.content_type || 'application/pdf'; - const downloadHref = document.current_version?.download_path - ? resolveApiPath(document.current_version.download_path) - : null; - const sizeBytes = Number(document.current_version?.size_bytes) || 0; - const sizeLabel = sizeBytes > 0 ? formatFileSize(sizeBytes) : null; - const metadata = - document.metadata && Object.keys(document.metadata).length > 0 ? document.metadata : null; - - return ( -
-
-
- -
-

{title}

- - {document.content_type || mime} - {sizeLabel ? ` · ${sizeLabel}` : ''} - -
-
-
- { - if (!downloadHref) { - event.preventDefault(); - } - }} - > - - Download - - -
-
-
- {!previewEntry?.url ? ( -
Loading preview…
- ) : ( -