Simpler file transfer callback

This commit is contained in:
Dustin Brett
2025-04-27 15:02:47 -07:00
parent 690d2da88c
commit 5577016fa8

View File

@@ -1,5 +1,4 @@
import { useEffect, useMemo, useRef } from "react";
import { getShortcutInfo } from "components/system/Files/FileEntry/functions";
import { useMemo } from "react";
import { useFileSystem } from "contexts/fileSystem";
import { useProcesses } from "contexts/process";
import { useProcessesRef } from "hooks/useProcessesRef";
@@ -33,16 +32,6 @@ const useTransferDialog = (): Dialog => {
const { argument, open } = useProcesses();
const processesRef = useProcessesRef();
const { readFile } = useFileSystem();
const getTransferIdCallbackRef = useRef<(url: string) => string>(undefined);
useEffect(() => {
getTransferIdCallbackRef.current = (url: string) =>
Object.keys(processesRef.current).find((id) => {
const [pid, pidUrl] = id.split(PROCESS_DELIMITER);
return pid === "Transfer" && url === pidUrl;
}) || "";
}, [processesRef]);
return useMemo(
() => ({
@@ -50,7 +39,11 @@ const useTransferDialog = (): Dialog => {
if (fileReaders?.length === 0) return;
if (fileReaders && url) {
const currentPid = getTransferIdCallbackRef.current?.(url);
const currentPid = Object.keys(processesRef.current).find((id) => {
const [pid, pidUrl] = id.split(PROCESS_DELIMITER);
return pid === "Transfer" && url === pidUrl;
});
if (currentPid) {
argument(currentPid, "fileReaders", fileReaders);
@@ -60,6 +53,9 @@ const useTransferDialog = (): Dialog => {
const [{ directory, name }] = fileReaders;
if (getExtension(name) === SHORTCUT_EXTENSION) {
const { getShortcutInfo } = await import(
"components/system/Files/FileEntry/functions"
);
const { url: shortcutUrl } = getShortcutInfo(
await readFile(name)
);
@@ -72,7 +68,7 @@ const useTransferDialog = (): Dialog => {
}
},
}),
[argument, open, readFile]
[argument, open, processesRef, readFile]
);
};