From 2d47dd17805eb22ba749ebb188b91e14c89238ea Mon Sep 17 00:00:00 2001 From: btzr-io Date: Mon, 10 Aug 2020 21:08:03 -0500 Subject: [PATCH] fix fileReader flow errors --- ui/component/postEditor/view.jsx | 1 + ui/component/publishFile/view.jsx | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/component/postEditor/view.jsx b/ui/component/postEditor/view.jsx index e08ce6118..18bed4f7c 100644 --- a/ui/component/postEditor/view.jsx +++ b/ui/component/postEditor/view.jsx @@ -47,6 +47,7 @@ function PostEditor(props: Props) { // Ready to edit content useEffect(() => { + // flow error if (!ready && !loading && fileText && streamingUrl) { setReady(true); } diff --git a/ui/component/publishFile/view.jsx b/ui/component/publishFile/view.jsx index 4f08cc7ea..cf5d1542b 100644 --- a/ui/component/publishFile/view.jsx +++ b/ui/component/publishFile/view.jsx @@ -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');