nonpdf-viewer (#6024)

Co-authored-by: a <a>
This commit is contained in:
Anthony Stirling
2026-03-30 16:39:11 +01:00
committed by GitHub
co-authored by a <a>
parent 82a3b8c770
commit cdc288e78d
12 changed files with 824 additions and 14 deletions
+20 -9
View File
@@ -1,16 +1,27 @@
import { useMemo } from 'react';
import EmbedPdfViewer from '@app/components/viewer/EmbedPdfViewer';
import { NonPdfViewerWrapper, type ViewerProps } from '@app/components/viewer/NonPdfViewer';
import { useFileState } from '@app/contexts/FileContext';
import { isPdfFile } from '@app/utils/fileUtils';
export interface ViewerProps {
sidebarsVisible: boolean;
setSidebarsVisible: (v: boolean) => void;
onClose?: () => void;
previewFile?: File | null;
activeFileIndex?: number;
setActiveFileIndex?: (index: number) => void;
}
export type { ViewerProps };
const Viewer = (props: ViewerProps) => {
// Default to EmbedPDF viewer
const { selectors } = useFileState();
const activeFiles = selectors.getFiles();
const activeFileIndex = props.activeFileIndex ?? 0;
// Determine the active file — previewFile takes priority
const activeFile = useMemo(() => {
if (props.previewFile) return props.previewFile;
return activeFiles[activeFileIndex] ?? activeFiles[0] ?? null;
}, [props.previewFile, activeFiles, activeFileIndex]);
// Route to the appropriate viewer based on file type
if (activeFile && !isPdfFile(activeFile)) {
return <NonPdfViewerWrapper {...props} />;
}
return <EmbedPdfViewer {...props} />;
};