// @flow import React from 'react'; import LoadingScreen from 'component/common/loading-screen'; import PdfViewer from 'component/viewers/pdfViewer'; import ThreeViewer from 'component/viewers/threeViewer'; import DocumentViewer from 'component/viewers/documentViewer'; import DocxViewer from 'component/viewers/docxViewer'; import HtmlViewer from 'component/viewers/htmlViewer'; type Props = { mediaType: string, source: { stream: string => void, fileName: string, fileType: string, contentType: string, downloadPath: string, }, currentTheme: string, }; class FileRender extends React.PureComponent { renderViewer() { const { source, mediaType, currentTheme } = this.props; // Extract relevant data to render file const { stream, fileType, contentType, downloadPath } = source; // Human-readable files (scripts and plain-text files) const readableFiles = ['text', 'document', 'script']; // Supported mediaTypes const mediaTypes = { '3D-file': , // Add routes to viewer... }; // Supported fileType const fileTypes = { pdf: , docx: , html: , // Add routes to viewer... }; // Check for a valid fileType or mediaType let viewer = fileTypes[fileType] || mediaTypes[mediaType]; // Check for Human-readable files if (!viewer && readableFiles.includes(mediaType)) { viewer = ; } // Message Error const unsupportedMessage = __("Sorry, looks like we can't preview this file."); const unsupported = ; // Return viewer return viewer || unsupported; } render() { return
{this.renderViewer()}
; } } export default FileRender;