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} - +