mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 08:31:49 +00:00
- Use FolderUp icon for folder upload in context menu (matches toolbar) - Auto-close encoding popover when an option is selected - Add trailing newline to uploadService.ts Co-Authored-By: Claude (gemini-claude-opus-4-5-thinking) <noreply@anthropic.com>
340 lines
11 KiB
TypeScript
340 lines
11 KiB
TypeScript
import React from "react";
|
|
import { ArrowUp, Check, ChevronRight, FilePlus, FolderPlus, FolderUp, Home, Languages, MoreHorizontal, RefreshCw, Upload } from "lucide-react";
|
|
import { cn } from "../../lib/utils";
|
|
import type { Host, SftpFilenameEncoding } from "../../types";
|
|
import { DistroAvatar } from "../DistroAvatar";
|
|
import { Button } from "../ui/button";
|
|
import { DialogHeader, DialogTitle } from "../ui/dialog";
|
|
import { Input } from "../ui/input";
|
|
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "../ui/popover";
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
|
|
|
|
interface BreadcrumbPart {
|
|
part: string;
|
|
originalIndex: number;
|
|
}
|
|
|
|
interface SftpModalHeaderProps {
|
|
t: (key: string, params?: Record<string, unknown>) => string;
|
|
host: Host;
|
|
credentials: { username?: string; hostname: string; port?: number };
|
|
showEncoding: boolean;
|
|
filenameEncoding: SftpFilenameEncoding;
|
|
onFilenameEncodingChange: (encoding: SftpFilenameEncoding) => void;
|
|
currentPath: string;
|
|
isEditingPath: boolean;
|
|
editingPathValue: string;
|
|
setEditingPathValue: (value: string) => void;
|
|
handlePathSubmit: () => void;
|
|
handlePathKeyDown: (e: React.KeyboardEvent) => void;
|
|
handlePathDoubleClick: () => void;
|
|
isAtRoot: boolean;
|
|
rootLabel: string;
|
|
isRefreshing: boolean;
|
|
onUp: () => void;
|
|
onHome: () => void;
|
|
onRefresh: () => void;
|
|
visibleBreadcrumbs: BreadcrumbPart[];
|
|
hiddenBreadcrumbs: BreadcrumbPart[];
|
|
needsBreadcrumbTruncation: boolean;
|
|
breadcrumbs: string[];
|
|
onBreadcrumbSelect: (index: number) => void;
|
|
onRootSelect: () => void;
|
|
inputRef: React.RefObject<HTMLInputElement>;
|
|
folderInputRef: React.RefObject<HTMLInputElement>;
|
|
pathInputRef: React.RefObject<HTMLInputElement>;
|
|
uploading: boolean;
|
|
onTriggerUpload: () => void;
|
|
onTriggerFolderUpload: () => void;
|
|
onCreateFolder: () => void;
|
|
onCreateFile: () => void;
|
|
onFileSelect: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
onFolderSelect: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
}
|
|
|
|
export const SftpModalHeader: React.FC<SftpModalHeaderProps> = ({
|
|
t,
|
|
host,
|
|
credentials,
|
|
showEncoding,
|
|
filenameEncoding,
|
|
onFilenameEncodingChange,
|
|
currentPath,
|
|
isEditingPath,
|
|
editingPathValue,
|
|
setEditingPathValue,
|
|
handlePathSubmit,
|
|
handlePathKeyDown,
|
|
handlePathDoubleClick,
|
|
isAtRoot,
|
|
rootLabel,
|
|
isRefreshing,
|
|
onUp,
|
|
onHome,
|
|
onRefresh,
|
|
visibleBreadcrumbs,
|
|
hiddenBreadcrumbs,
|
|
needsBreadcrumbTruncation,
|
|
breadcrumbs,
|
|
onBreadcrumbSelect,
|
|
onRootSelect,
|
|
inputRef,
|
|
folderInputRef,
|
|
pathInputRef,
|
|
uploading,
|
|
onTriggerUpload,
|
|
onTriggerFolderUpload,
|
|
onCreateFolder,
|
|
onCreateFile,
|
|
onFileSelect,
|
|
onFolderSelect,
|
|
}) => (
|
|
<>
|
|
<DialogHeader className="px-4 py-3 border-b border-border/60 flex-shrink-0">
|
|
<div className="flex items-center gap-3 pr-8">
|
|
<DistroAvatar
|
|
host={host}
|
|
fallback={host.label.slice(0, 2).toUpperCase()}
|
|
className="h-8 w-8"
|
|
/>
|
|
<div className="flex-1 min-w-0">
|
|
<DialogTitle className="text-sm font-semibold">
|
|
{host.label}
|
|
</DialogTitle>
|
|
<div className="text-xs text-muted-foreground font-mono">
|
|
{credentials.username || "root"}@{credentials.hostname}:
|
|
{credentials.port || 22}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</DialogHeader>
|
|
|
|
<TooltipProvider delayDuration={300}>
|
|
<div className="px-4 py-2 border-b border-border/60 flex items-center gap-2 flex-shrink-0 bg-muted/30">
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onUp}
|
|
disabled={isAtRoot}
|
|
>
|
|
<ArrowUp size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.nav.up")}</TooltipContent>
|
|
</Tooltip>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onHome}
|
|
>
|
|
<Home size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.nav.home")}</TooltipContent>
|
|
</Tooltip>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onRefresh}
|
|
>
|
|
<RefreshCw
|
|
size={14}
|
|
className={cn(isRefreshing && "animate-spin")}
|
|
/>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.nav.refresh")}</TooltipContent>
|
|
</Tooltip>
|
|
{showEncoding && (
|
|
<Popover>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
>
|
|
<Languages size={14} />
|
|
</Button>
|
|
</PopoverTrigger>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.encoding.label")}</TooltipContent>
|
|
</Tooltip>
|
|
<PopoverContent className="w-36 p-1" align="start">
|
|
{(["auto", "utf-8", "gb18030"] as const).map((encoding) => (
|
|
<PopoverClose asChild key={encoding}>
|
|
<button
|
|
className={cn(
|
|
"w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded-sm hover:bg-secondary transition-colors",
|
|
filenameEncoding === encoding && "bg-secondary"
|
|
)}
|
|
onClick={() => onFilenameEncodingChange(encoding)}
|
|
>
|
|
<Check
|
|
size={14}
|
|
className={cn(
|
|
"shrink-0",
|
|
filenameEncoding === encoding ? "opacity-100" : "opacity-0"
|
|
)}
|
|
/>
|
|
{t(`sftp.encoding.${encoding === "utf-8" ? "utf8" : encoding}`)}
|
|
</button>
|
|
</PopoverClose>
|
|
))}
|
|
</PopoverContent>
|
|
</Popover>
|
|
)}
|
|
|
|
<div className="flex items-center gap-1 text-sm flex-1 min-w-0 overflow-hidden">
|
|
{isEditingPath ? (
|
|
<Input
|
|
ref={pathInputRef}
|
|
value={editingPathValue}
|
|
onChange={(e) => setEditingPathValue(e.target.value)}
|
|
onBlur={handlePathSubmit}
|
|
onKeyDown={handlePathKeyDown}
|
|
className="h-7 text-sm bg-background"
|
|
autoFocus
|
|
/>
|
|
) : (
|
|
<div
|
|
className="flex items-center gap-1 flex-1 min-w-0 cursor-text hover:bg-secondary/50 rounded px-1 py-0.5 transition-colors"
|
|
onDoubleClick={handlePathDoubleClick}
|
|
title={currentPath}
|
|
>
|
|
<button
|
|
className="text-muted-foreground hover:text-foreground px-1 shrink-0"
|
|
onClick={onRootSelect}
|
|
>
|
|
{rootLabel}
|
|
</button>
|
|
{visibleBreadcrumbs.map(({ part, originalIndex }, displayIdx) => {
|
|
const isLast = originalIndex === breadcrumbs.length - 1;
|
|
const showEllipsisBefore =
|
|
needsBreadcrumbTruncation && displayIdx === 1;
|
|
|
|
return (
|
|
<React.Fragment key={originalIndex}>
|
|
{showEllipsisBefore && (
|
|
<>
|
|
<ChevronRight
|
|
size={12}
|
|
className="text-muted-foreground flex-shrink-0"
|
|
/>
|
|
<span
|
|
className="text-muted-foreground px-1 shrink-0 flex items-center cursor-default"
|
|
title={`${t("sftp.showHiddenPaths")}: ${hiddenBreadcrumbs
|
|
.map((h) => h.part)
|
|
.join(" > ")}`}
|
|
>
|
|
<MoreHorizontal size={14} />
|
|
</span>
|
|
</>
|
|
)}
|
|
<ChevronRight
|
|
size={12}
|
|
className="text-muted-foreground flex-shrink-0"
|
|
/>
|
|
<button
|
|
className={cn(
|
|
"text-muted-foreground hover:text-foreground truncate px-1 max-w-[100px]",
|
|
isLast && "text-foreground font-medium",
|
|
)}
|
|
onClick={() => onBreadcrumbSelect(originalIndex)}
|
|
title={part}
|
|
>
|
|
{part}
|
|
</button>
|
|
</React.Fragment>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex items-center gap-1 ml-auto">
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onTriggerUpload}
|
|
disabled={uploading}
|
|
>
|
|
<Upload size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.upload")}</TooltipContent>
|
|
</Tooltip>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onTriggerFolderUpload}
|
|
disabled={uploading}
|
|
>
|
|
<FolderUp size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.uploadFolder")}</TooltipContent>
|
|
</Tooltip>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onCreateFolder}
|
|
>
|
|
<FolderPlus size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.newFolder")}</TooltipContent>
|
|
</Tooltip>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
className="h-7 w-7"
|
|
onClick={onCreateFile}
|
|
>
|
|
<FilePlus size={14} />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("sftp.newFile")}</TooltipContent>
|
|
</Tooltip>
|
|
<input
|
|
type="file"
|
|
className="hidden"
|
|
ref={inputRef}
|
|
onChange={onFileSelect}
|
|
multiple
|
|
/>
|
|
<input
|
|
type="file"
|
|
className="hidden"
|
|
ref={folderInputRef}
|
|
onChange={onFolderSelect}
|
|
webkitdirectory=""
|
|
multiple
|
|
/>
|
|
</div>
|
|
</div>
|
|
</TooltipProvider>
|
|
</>
|
|
);
|