mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 17:32:18 +00:00
Adjusts relative import paths across the application to reflect recent changes in the project's directory structure. This primarily affects SFTP state management and modal components. Updates React hook dependency arrays for `useCallback` and `useEffect` to ensure proper memoization and re-execution, addressing `react-hooks/exhaustive-deps` linting rules. Improves type safety for translation function parameters by changing `Record<string, any>` to `Record<string, unknown>`. Adds the `ls` command to the allowed commands for the Claude AI assistant in local settings.
100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
import React, { useCallback, useRef } from "react";
|
|
import type { RemoteFile } from "../../../types";
|
|
|
|
interface UseSftpModalSelectionParams {
|
|
files: RemoteFile[];
|
|
setSelectedFiles: (value: Set<string> | ((prev: Set<string>) => Set<string>)) => void;
|
|
currentPath: string;
|
|
joinPath: (base: string, name: string) => string;
|
|
onNavigate: (path: string) => void;
|
|
onOpenFile: (file: RemoteFile) => void;
|
|
onNavigateUp: () => void;
|
|
}
|
|
|
|
interface UseSftpModalSelectionResult {
|
|
handleFileClick: (file: RemoteFile, index: number, e: React.MouseEvent) => void;
|
|
handleFileDoubleClick: (file: RemoteFile) => void;
|
|
}
|
|
|
|
export const useSftpModalSelection = ({
|
|
files,
|
|
setSelectedFiles,
|
|
currentPath,
|
|
joinPath,
|
|
onNavigate,
|
|
onOpenFile,
|
|
onNavigateUp,
|
|
}: UseSftpModalSelectionParams): UseSftpModalSelectionResult => {
|
|
const lastSelectedIndexRef = useRef<number | null>(null);
|
|
|
|
const handleFileClick = useCallback(
|
|
(file: RemoteFile, index: number, e: React.MouseEvent) => {
|
|
if (file.name === "..") return;
|
|
|
|
if (file.type === "directory") {
|
|
if (e.shiftKey && lastSelectedIndexRef.current !== null) {
|
|
const start = Math.min(lastSelectedIndexRef.current, index);
|
|
const end = Math.max(lastSelectedIndexRef.current, index);
|
|
const newSelection = new Set<string>();
|
|
for (let i = start; i <= end; i++) {
|
|
if (files[i] && files[i].type !== "directory") {
|
|
newSelection.add(files[i].name);
|
|
}
|
|
}
|
|
setSelectedFiles(newSelection);
|
|
} else if (e.ctrlKey || e.metaKey) {
|
|
setSelectedFiles((prev) => {
|
|
const next = new Set(prev);
|
|
return next;
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (e.shiftKey && lastSelectedIndexRef.current !== null) {
|
|
const start = Math.min(lastSelectedIndexRef.current, index);
|
|
const end = Math.max(lastSelectedIndexRef.current, index);
|
|
const newSelection = new Set<string>();
|
|
for (let i = start; i <= end; i++) {
|
|
if (files[i] && files[i].type !== "directory") {
|
|
newSelection.add(files[i].name);
|
|
}
|
|
}
|
|
setSelectedFiles(newSelection);
|
|
} else if (e.ctrlKey || e.metaKey) {
|
|
setSelectedFiles((prev) => {
|
|
const next = new Set(prev);
|
|
if (next.has(file.name)) {
|
|
next.delete(file.name);
|
|
} else {
|
|
next.add(file.name);
|
|
}
|
|
return next;
|
|
});
|
|
lastSelectedIndexRef.current = index;
|
|
} else {
|
|
setSelectedFiles(new Set([file.name]));
|
|
lastSelectedIndexRef.current = index;
|
|
}
|
|
},
|
|
[files, setSelectedFiles],
|
|
);
|
|
|
|
const handleFileDoubleClick = useCallback(
|
|
(file: RemoteFile) => {
|
|
if (file.name === "..") {
|
|
onNavigateUp();
|
|
return;
|
|
}
|
|
if (file.type === "directory" || (file.type === "symlink" && file.linkTarget === "directory")) {
|
|
onNavigate(joinPath(currentPath, file.name));
|
|
} else {
|
|
onOpenFile(file);
|
|
}
|
|
},
|
|
[currentPath, joinPath, onNavigate, onNavigateUp, onOpenFile],
|
|
);
|
|
|
|
return { handleFileClick, handleFileDoubleClick };
|
|
};
|