fix fileReader flow errors

This commit is contained in:
btzr-io 2020-08-10 21:08:03 -05:00 committed by Sean Yesmunt
parent 334f582a4d
commit 2d47dd1780
2 changed files with 11 additions and 5 deletions

View file

@ -47,6 +47,7 @@ function PostEditor(props: Props) {
// Ready to edit content
useEffect(() => {
// flow error
if (!ready && !loading && fileText && streamingUrl) {
setReady(true);
}

View file

@ -232,6 +232,15 @@ function PublishFile(props: Props) {
}
}
function handleFileReaderLoaded(event: ProgressEvent) {
// See: https://github.com/facebook/flow/issues/3470
if (event.target instanceof FileReader) {
const text = event.target.result;
updatePublishForm({ fileText: text });
setPublishMode(PUBLISH_MODES.POST);
}
}
function handleFileChange(file: WebFile) {
const { showToast } = props;
window.URL = window.URL || window.webkitURL;
@ -283,11 +292,7 @@ function PublishFile(props: Props) {
// Create reader
const reader = new FileReader();
// Handler for file reader
reader.addEventListener('load', event => {
const text = event.target.result;
updatePublishForm({ fileText: text });
setPublishMode(PUBLISH_MODES.POST);
});
reader.addEventListener('load', handleFileReaderLoaded);
// Read file contents
reader.readAsText(file);
setCurrentFileType('text/markdown');