2018-06-11 08:41:25 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import LoadingScreen from 'component/common/loading-screen';
|
2018-07-05 04:49:12 +02:00
|
|
|
import PdfViewer from 'component/viewers/pdfViewer';
|
2018-07-19 08:45:32 +02:00
|
|
|
import ThreeViewer from 'component/viewers/threeViewer';
|
2018-07-26 07:18:35 +02:00
|
|
|
import DocumentViewer from 'component/viewers/documentViewer';
|
2018-07-27 04:06:39 +02:00
|
|
|
import DocxViewer from 'component/viewers/docxViewer';
|
2018-06-11 08:41:25 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
mediaType: string,
|
2018-06-13 06:06:53 +02:00
|
|
|
source: {
|
2018-06-11 08:41:25 +02:00
|
|
|
filePath: string,
|
|
|
|
fileType: string,
|
2018-07-05 04:49:12 +02:00
|
|
|
downloadPath: string,
|
2018-06-11 08:41:25 +02:00
|
|
|
},
|
|
|
|
currentTheme: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileRender extends React.PureComponent<Props> {
|
2018-06-13 06:06:53 +02:00
|
|
|
renderViewer() {
|
2018-07-28 03:42:35 +02:00
|
|
|
const { source, mediaType, currentTheme: theme } = this.props;
|
|
|
|
const viewerProps = { source, theme };
|
2018-06-11 08:41:25 +02:00
|
|
|
|
|
|
|
// Supported mediaTypes
|
|
|
|
const mediaTypes = {
|
2018-07-16 16:38:46 +02:00
|
|
|
'3D-file': <ThreeViewer {...viewerProps} />,
|
2018-07-26 07:18:35 +02:00
|
|
|
document: <DocumentViewer {...viewerProps} />,
|
2018-06-11 08:41:25 +02:00
|
|
|
// Add routes to viewer...
|
|
|
|
};
|
|
|
|
|
2018-07-05 04:49:12 +02:00
|
|
|
// Supported fileType
|
|
|
|
const fileTypes = {
|
|
|
|
pdf: <PdfViewer {...viewerProps} />,
|
2018-07-27 04:06:39 +02:00
|
|
|
docx: <DocxViewer {...viewerProps} />,
|
2018-07-05 04:49:12 +02:00
|
|
|
// Add routes to viewer...
|
|
|
|
};
|
|
|
|
|
|
|
|
const { fileType } = source;
|
2018-07-27 04:06:39 +02:00
|
|
|
const viewer = mediaType && source && (fileTypes[fileType] || mediaTypes[mediaType]);
|
2018-07-09 06:57:31 +02:00
|
|
|
const unsupportedMessage = __("Sorry, looks like we can't preview this file.");
|
2018-06-13 06:06:53 +02:00
|
|
|
const unsupported = <LoadingScreen status={unsupportedMessage} spinner={false} />;
|
|
|
|
|
2018-06-11 08:41:25 +02:00
|
|
|
// Return viewer
|
2018-06-13 06:06:53 +02:00
|
|
|
return viewer || unsupported;
|
2018-06-11 08:41:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-06-13 06:06:53 +02:00
|
|
|
return <div className="file-render">{this.renderViewer()}</div>;
|
2018-06-11 08:41:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileRender;
|