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

52 lines
1.4 KiB
React
Raw Normal View History

2019-05-09 00:47:39 +02:00
// @flow
import * as React from 'react';
import Villain from 'villain-react';
import useFileStream from 'effects/use-stream-file'
import LoadingScreen from 'component/common/loading-screen';
import 'villain-react/dist/style.css';
2019-05-09 00:47:39 +02:00
type Props = {
source: {
file: (?string) => any,
stream: string,
},
theme: string,
2019-05-09 00:47:39 +02:00
};
let workerUrl = 'webworkers/worker-bundle.js';
2019-06-04 20:32:42 +02:00
if (process.env.NODE_ENV !== 'production') {
// Don't add a leading slash in production because electron treats it as an absolute path
workerUrl = `/${workerUrl}`;
2019-06-04 20:32:42 +02:00
}
const ComicBookViewer = ( props: Props) => {
const { source, theme } = props
const { stream, file } = source
// @if TARGET='app'
const finalSource = useFileStream(file)
// @endif
// Villain options
const opts = {
theme: theme === 'dark' ? 'Dark' : 'Light',
allowFullScreen: true,
autoHideControls: false,
allowGlobalShortcuts: true,
};
2019-05-16 08:32:53 +02:00
const errorMessage = __("Sorry, looks like we can't load the archive.");
2020-04-26 03:55:23 +02:00
return (
<div className="file-render__viewer file-render__viewer--comic">
{ loading && <LoadingScreen status={__('Loading')} />}
{ ready && <Villain source={finalSource.content} className={'comic-viewer'} options={opts} workerUrl={workerUrl} /> }
{ error && <LoadingScreen status={errorMessage} spinner={false} /> }
2020-04-26 03:55:23 +02:00
</div>
);
2019-05-09 00:47:39 +02:00
}
export default ComicBookViewer;