lbry-desktop/src/renderer/component/fileRender/view.jsx

49 lines
1.3 KiB
React
Raw Normal View History

2018-06-11 08:41:25 +02:00
// @flow
import React from 'react';
import LoadingScreen from 'component/common/loading-screen';
import PdfViewer from 'component/viewers/pdfViewer';
2018-07-19 08:45:32 +02:00
import ThreeViewer from 'component/viewers/threeViewer';
2018-06-11 08:41:25 +02:00
type Props = {
mediaType: string,
source: {
2018-06-11 08:41:25 +02:00
filePath: string,
fileType: string,
downloadPath: string,
2018-06-11 08:41:25 +02:00
},
currentTheme: string,
};
class FileRender extends React.PureComponent<Props> {
renderViewer() {
const { source, mediaType, currentTheme } = this.props;
const viewerProps = { source, theme: currentTheme };
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-06-11 08:41:25 +02:00
// Add routes to viewer...
};
// Supported fileType
const fileTypes = {
pdf: <PdfViewer {...viewerProps} />,
// Add routes to viewer...
};
const { fileType } = source;
const viewer = mediaType && source && (mediaTypes[mediaType] || fileTypes[fileType]);
2018-07-09 06:57:31 +02:00
const unsupportedMessage = __("Sorry, looks like we can't preview this file.");
const unsupported = <LoadingScreen status={unsupportedMessage} spinner={false} />;
2018-06-11 08:41:25 +02:00
// Return viewer
return viewer || unsupported;
2018-06-11 08:41:25 +02:00
}
render() {
return <div className="file-render">{this.renderViewer()}</div>;
2018-06-11 08:41:25 +02:00
}
}
export default FileRender;