mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 11:23:10 +02:00
co-authored by
a <a>
parent
82a3b8c770
commit
cdc288e78d
@@ -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} />;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user