From 668c9f4841e7118b98bb31d8e68640689be99830 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sat, 22 Aug 2020 13:54:56 +0300
Subject: refactor!: simplify file operations

---
 src/containers/PollCreation/ImageInput.tsx | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'src/containers/PollCreation/ImageInput.tsx')

diff --git a/src/containers/PollCreation/ImageInput.tsx b/src/containers/PollCreation/ImageInput.tsx
index 475d527..e807865 100644
--- a/src/containers/PollCreation/ImageInput.tsx
+++ b/src/containers/PollCreation/ImageInput.tsx
@@ -10,6 +10,7 @@ import { Check, CancelOutlined } from '@material-ui/icons';
 import AttachLink from '../../components/AttachLink/AttachLink';
 import FileUpload from '../../components/FileUpload/FileUpload';
 import BackgroundImage from '../../components/Image/BackgroundImage';
+import getLocalFileUrl from '../../utils/getLocalFileUrl';
 
 interface PropTypes {
   callback: (file?: File | string) => void;
@@ -59,9 +60,12 @@ const ImageInput: React.FC<PropTypes> = ({ callback, progress }) => {
     callback(undefined);
   };
 
-  const childrenCallback = (fileUrl: string, file?: File) => {
-    setUrl(fileUrl);
-    callback(file || fileUrl);
+  const childrenCallback = (value: File | string) => {
+    if (value instanceof File) {
+      getLocalFileUrl(value).then(localUrl => setUrl(localUrl));
+    } else setUrl(value);
+
+    callback(value);
   };
 
   const Upload = (
-- 
cgit v1.2.3

