lbry-desktop/ui/component/viewers/pdfViewer.jsx

61 lines
1.5 KiB
React
Raw Normal View History

// @flow
2018-10-15 08:26:46 +02:00
import * as React from 'react';
2018-11-21 22:20:55 +01:00
import { stopContextMenu } from 'util/context-menu';
2019-03-20 05:41:51 +01:00
import Button from 'component/button';
2019-12-10 20:49:00 +01:00
import I18nMessage from 'component/i18nMessage';
// @if TARGET='app'
2019-03-20 05:41:51 +01:00
import { shell } from 'electron';
// @endif
type Props = {
source: string,
};
class PdfViewer extends React.PureComponent<Props> {
2019-03-20 05:41:51 +01:00
constructor() {
super();
(this: any).openFile = this.openFile.bind(this);
}
componentDidMount() {
this.openFile();
}
openFile() {
const { source } = this.props;
2019-03-20 05:41:51 +01:00
const path = `file://${source}`;
// @if TARGET='app'
2019-03-20 05:41:51 +01:00
shell.openExternal(path);
// @endif
2019-03-20 05:41:51 +01:00
}
render() {
// We used to be able to just render a webview and display the pdf inside the app
// This was disabled on electron@3
// https://github.com/electron/electron/issues/12337
const { source } = this.props;
return (
2019-08-13 07:35:13 +02:00
<div className="file-render__viewer--pdf" onContextMenu={stopContextMenu}>
{/* @if TARGET='app' */}
2019-03-20 05:41:51 +01:00
<p>
2019-12-10 20:49:00 +01:00
<I18nMessage
tokens={{ click_here: <Button button="link" label={__('Click here')} onClick={this.openFile} /> }}
>
PDF opened externally. %click_here% to open it again.
</I18nMessage>
2019-03-20 05:41:51 +01:00
</p>
{/* @endif */}
{/* @if TARGET='web' */}
<div className="file-render__viewer">
<iframe title={__('File preview')} src={source} />
</div>
{/* @endif */}
</div>
);
}
}
export default PdfViewer;