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)
This commit is contained in:
casper 2021-06-01 15:09:33 +02:00
parent f4d187efa7
commit 00bc8aacc3
3 changed files with 17 additions and 3 deletions

11
package-lock.json generated
View File

@ -45,6 +45,7 @@
"eslint-plugin-react": "^3.15.0", "eslint-plugin-react": "^3.15.0",
"executive": "^1.5.11", "executive": "^1.5.11",
"fastclick": "^1.0.6", "fastclick": "^1.0.6",
"file-dialog": "^0.0.8",
"file-loader": "^0.11.2", "file-loader": "^0.11.2",
"file-saver": "^1.3.3", "file-saver": "^1.3.3",
"form-data": "^2.1.1", "form-data": "^2.1.1",
@ -5069,6 +5070,11 @@
"node": ">=0.10.0" "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": { "node_modules/file-entry-cache": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz",
@ -22409,6 +22415,11 @@
"object-assign": "^4.1.0" "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": { "file-entry-cache": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz",

View File

@ -54,6 +54,7 @@
"eslint-plugin-react": "^3.15.0", "eslint-plugin-react": "^3.15.0",
"executive": "^1.5.11", "executive": "^1.5.11",
"fastclick": "^1.0.6", "fastclick": "^1.0.6",
"file-dialog": "^0.0.8",
"file-loader": "^0.11.2", "file-loader": "^0.11.2",
"file-saver": "^1.3.3", "file-saver": "^1.3.3",
"form-data": "^2.1.1", "form-data": "^2.1.1",

View File

@ -1,3 +1,4 @@
import fileDialog from 'file-dialog';
import { createUniqueName, sketchDataToDoc, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT } from 'src/js/utils/saveUtils.js'; import { createUniqueName, sketchDataToDoc, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT } from 'src/js/utils/saveUtils.js';
import sketchDataToJSON from '@doodle3d/doodle3d-core/lib/shape/sketchDataToJSON'; import sketchDataToJSON from '@doodle3d/doodle3d-core/lib/shape/sketchDataToJSON';
import { JSONToBlob } from '@doodle3d/doodle3d-core/lib/utils/binaryUtils'; import { JSONToBlob } from '@doodle3d/doodle3d-core/lib/utils/binaryUtils';
@ -78,9 +79,10 @@ export const downloadAllSketches = () => {
export const openFileSelector = () => { export const openFileSelector = () => {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const files = await window.showOpenFilePicker({ multiple: true }); const files = await fileDialog({ multiple: true });
for (let file of files) { for (let i = 0; i < files.length; i ++) {
await loadFile(dispatch, file.name, () => file.getFile()); const file = files[i];
await loadFile(dispatch, file.name, () => Promise.resolve(file))
} }
}; };