fix more flow errors for document viewers

This commit is contained in:
btzr-io 2018-10-14 18:27:09 -06:00
parent 49721b87c8
commit 15cbdd42a8
6 changed files with 55 additions and 29 deletions

View file

@ -6,25 +6,34 @@ import remarkEmoji from 'remark-emoji';
import ExternalLink from 'component/externalLink';
import defaultSchema from 'hast-util-sanitize/lib/github.json';
type MarkdownProps = {
content: ?string,
promptLinks?: boolean,
};
type SimpleLinkProps = {
href?: string,
title?: string,
children?: React.Node,
};
const SimpleLink = (props: SimpleLinkProps) => {
const { href, title, children } = props;
return (
<a href={href} title={title}>
{children}
</a>
);
};
// Use github sanitation schema
const schema = { ...defaultSchema };
// Extend sanitation schema to support lbry protocol
schema.protocols.href[3] = 'lbry';
type MarkdownProps = {
content: string,
promptLinks?: boolean,
};
const SimpleLink = ({ href, title, children }) => (
<a href={href} title={title}>
{children}
</a>
);
const MarkdownPreview = (props: MarkdownProps) => {
const { content, externalLinks, promptLinks } = props;
const { content, promptLinks } = props;
const remarkOptions = {
sanitize: schema,
remarkReactComponents: {

View file

@ -10,11 +10,11 @@ import HtmlViewer from 'component/viewers/htmlViewer';
type Props = {
mediaType: string,
source: {
stream: string => void,
fileName: string,
fileType: string,
contentType: string,
downloadPath: string,
stream: opts => void,
blob: callback => void,
},
currentTheme: string,
};

View file

@ -22,12 +22,12 @@ import 'codemirror/mode/javascript/javascript';
type Props = {
theme: string,
value: string,
value: ?string,
contentType: string,
};
class CodeViewer extends React.PureComponent<Props> {
constructor(props) {
constructor(props: Props) {
super(props);
this.codeMirror = null;
this.textarea = React.createRef();
@ -54,6 +54,8 @@ class CodeViewer extends React.PureComponent<Props> {
this.codeMirror.on('contextmenu', openSnippetMenu);
}
codeMirror: any;
render() {
const { value } = this.props;
return (

View file

@ -8,19 +8,25 @@ import MarkdownPreview from 'component/common/markdown-preview';
type Props = {
theme: string,
source: {
stream: opts => void,
stream: string => any,
fileType: string,
contentType: string,
},
};
class DocumentViewer extends React.PureComponent<Props> {
constructor(props) {
type State = {
error: boolean,
loading: boolean,
content: ?string,
};
class DocumentViewer extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
error: null,
content: null,
error: false,
loading: true,
content: null,
};
}
@ -38,13 +44,14 @@ class DocumentViewer extends React.PureComponent<Props> {
this.setState({ content: data, loading: false });
});
stream.on('error', error => {
stream.on('error', () => {
this.setState({ error: true, loading: false });
});
}
renderDocument(content = null) {
renderDocument() {
let viewer = null;
const { content } = this.state;
const { source, theme } = this.props;
const { fileType, contentType } = source;
const markdownType = ['md', 'markdown'];
@ -70,7 +77,7 @@ class DocumentViewer extends React.PureComponent<Props> {
<div className="file-render__viewer document-viewer">
{loading && !error && <LoadingScreen status={loadingMessage} spinner />}
{error && <LoadingScreen status={errorMessage} spinner={!error} />}
{isReady && this.renderDocument(content)}
{isReady && this.renderDocument()}
</div>
);
}

View file

@ -10,11 +10,17 @@ type Props = {
source: string,
};
class DocxViewer extends React.PureComponent<Props> {
constructor(props) {
type State = {
error: boolean,
loading: boolean,
content: ?string,
};
class DocxViewer extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
error: null,
error: false,
content: null,
loading: true,
};
@ -46,7 +52,7 @@ class DocxViewer extends React.PureComponent<Props> {
const markdown = breakdance.render(result.value);
this.setState({ content: markdown, loading: false });
})
.catch(error => {
.catch(() => {
this.setState({ error: true, loading: false });
})
.done();

View file

@ -7,11 +7,13 @@ type Props = {
};
class PdfViewer extends React.PureComponent<Props> {
constructor(props) {
constructor(props: Props) {
super(props);
this.viewer = React.createRef();
}
viewer: { current: any };
render() {
const { source } = this.props;
return (