From 00bc8aacc3c85206e7c3f9777200b7dc17069142 Mon Sep 17 00:00:00 2001 From: casper Date: Tue, 1 Jun 2021 15:09:33 +0200 Subject: [PATCH] Use `file-dialog` npm package for selecting files @companje file selecting werkt nu getest op Chrome, Safari, Firefox in MacOS (nog niet getest in IOS) --- package-lock.json | 11 +++++++++++ package.json | 1 + src/js/actions/files.js | 8 +++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e54b1b..efeed18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,6 +45,7 @@ "eslint-plugin-react": "^3.15.0", "executive": "^1.5.11", "fastclick": "^1.0.6", + "file-dialog": "^0.0.8", "file-loader": "^0.11.2", "file-saver": "^1.3.3", "form-data": "^2.1.1", @@ -5069,6 +5070,11 @@ "node": ">=0.10.0" } }, + "node_modules/file-dialog": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/file-dialog/-/file-dialog-0.0.8.tgz", + "integrity": "sha512-KnYitqNf/rANEhUxWzkINAaMVc7SshejwA5HEd5Wr8lEJQX1Js1LCndectS44SXTnXWK+jbHQYs4R6CaG+7Jkg==" + }, "node_modules/file-entry-cache": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz", @@ -22409,6 +22415,11 @@ "object-assign": "^4.1.0" } }, + "file-dialog": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/file-dialog/-/file-dialog-0.0.8.tgz", + "integrity": "sha512-KnYitqNf/rANEhUxWzkINAaMVc7SshejwA5HEd5Wr8lEJQX1Js1LCndectS44SXTnXWK+jbHQYs4R6CaG+7Jkg==" + }, "file-entry-cache": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz", diff --git a/package.json b/package.json index cf03c8a..b22973d 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "eslint-plugin-react": "^3.15.0", "executive": "^1.5.11", "fastclick": "^1.0.6", + "file-dialog": "^0.0.8", "file-loader": "^0.11.2", "file-saver": "^1.3.3", "form-data": "^2.1.1", diff --git a/src/js/actions/files.js b/src/js/actions/files.js index 45b6d05..e31bcbe 100644 --- a/src/js/actions/files.js +++ b/src/js/actions/files.js @@ -1,3 +1,4 @@ +import fileDialog from 'file-dialog'; import { createUniqueName, sketchDataToDoc, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT } from 'src/js/utils/saveUtils.js'; import sketchDataToJSON from '@doodle3d/doodle3d-core/lib/shape/sketchDataToJSON'; import { JSONToBlob } from '@doodle3d/doodle3d-core/lib/utils/binaryUtils'; @@ -78,9 +79,10 @@ export const downloadAllSketches = () => { export const openFileSelector = () => { return async (dispatch, getState) => { - const files = await window.showOpenFilePicker({ multiple: true }); - for (let file of files) { - await loadFile(dispatch, file.name, () => file.getFile()); + const files = await fileDialog({ multiple: true }); + for (let i = 0; i < files.length; i ++) { + const file = files[i]; + await loadFile(dispatch, file.name, () => Promise.resolve(file)) } };