From eae24c397a3fba792cc2d89adda16c93bb4e5f38 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Mon, 15 Apr 2019 16:04:27 -0700 Subject: [PATCH] reuse fileToDataUrl --- components/FontSelect.js | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/components/FontSelect.js b/components/FontSelect.js index 1ab0df1..a4c1736 100644 --- a/components/FontSelect.js +++ b/components/FontSelect.js @@ -1,17 +1,10 @@ import React from 'react' import ListSetting from './ListSetting' import { FONTS } from '../lib/constants' +import { fileToDataURL as blobToUrl } from '../lib/util' const EXTENSIONS = ['.otf', '.ttf', '.woff'] -const blobToUrl = blob => - new Promise(resolve => { - const reader = new FileReader() - - reader.onload = event => resolve(event.target.result) - reader.readAsDataURL(blob) - }) - const Font = ({ id, name }) => ( {name} @@ -32,8 +25,8 @@ function FontSelect(props) { } } - async function onFiles() { - const { files } = inputEl.current + async function onFiles(e) { + const { files } = e.target const name = files[0].name.split('.')[0] const url = await blobToUrl(files[0]) @@ -53,14 +46,7 @@ function FontSelect(props) { > {Font} - +