|
@@ -1,18 +1,23 @@
|
|
import { useCallback, useRef, useState } from "react";
|
|
import { useCallback, useRef, useState } from "react";
|
|
|
|
|
|
/**
|
|
/**
|
|
- * TODO (MR): Understand how this is happening, and validate it further (on
|
|
|
|
- * first glance this is correct).
|
|
|
|
- *
|
|
|
|
* [Note: File paths when running under Electron]
|
|
* [Note: File paths when running under Electron]
|
|
*
|
|
*
|
|
* We have access to the absolute path of the web {@link File} object when we
|
|
* We have access to the absolute path of the web {@link File} object when we
|
|
* are running in the context of our desktop app.
|
|
* are running in the context of our desktop app.
|
|
*
|
|
*
|
|
|
|
+ * https://www.electronjs.org/docs/latest/api/file-object
|
|
|
|
+ *
|
|
* This is in contrast to the `webkitRelativePath` that we get when we're
|
|
* This is in contrast to the `webkitRelativePath` that we get when we're
|
|
* running in the browser, which is the relative path to the directory that the
|
|
* running in the browser, which is the relative path to the directory that the
|
|
* user selected (or just the name of the file if the user selected or
|
|
* user selected (or just the name of the file if the user selected or
|
|
* drag/dropped a single one).
|
|
* drag/dropped a single one).
|
|
|
|
+ *
|
|
|
|
+ * Note that this is a deprecated approach. From Electron docs:
|
|
|
|
+ *
|
|
|
|
+ * > Warning: The path property that Electron adds to the File interface is
|
|
|
|
+ * > deprecated and will be removed in a future Electron release. We recommend
|
|
|
|
+ * > you use `webUtils.getPathForFile` instead.
|
|
*/
|
|
*/
|
|
export interface FileWithPath extends File {
|
|
export interface FileWithPath extends File {
|
|
readonly path?: string;
|
|
readonly path?: string;
|
|
@@ -49,7 +54,10 @@ interface UseFileInputParams {
|
|
* accept can be an extension or a MIME type (See
|
|
* accept can be an extension or a MIME type (See
|
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept).
|
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept).
|
|
*/
|
|
*/
|
|
-export default function useFileInput({ directory, accept }: UseFileInputParams) {
|
|
|
|
|
|
+export default function useFileInput({
|
|
|
|
+ directory,
|
|
|
|
+ accept,
|
|
|
|
+}: UseFileInputParams) {
|
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
|
const inputRef = useRef<HTMLInputElement>();
|
|
const inputRef = useRef<HTMLInputElement>();
|
|
|
|
|