mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
29 lines
1011 B
TypeScript
29 lines
1011 B
TypeScript
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 type { ViewerProps };
|
|
|
|
const Viewer = (props: ViewerProps) => {
|
|
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} />;
|
|
};
|
|
|
|
export default Viewer;
|