* Replace app logo across window icon, tray, splash, and in-app brand
- public/logo.svg: new netcatty mark
- public/icon.png: regenerated 1024x1024 from new SVG (source for
electron-builder — .icns/.ico rebuilt automatically at pack time)
- public/dmg-fix-icon.png: regenerated 1024x1024
- public/tray-icon{,@2x}.png: regenerated color 16/32px for Linux/Windows
- public/tray-iconTemplate{,@2x}.png: regenerated monochrome silhouette
for macOS menu bar (background stripped, foreground flattened to
black on transparent so template-image rendering produces a clean
mask)
- components/AppLogo.tsx: render the new logo as a static <img>. The
old hand-coded inline SVG bound fills to the accent CSS variable;
the new mark has a fixed palette, so callers keep their sizing /
rounding classes via className while the asset itself is a single
file served from /public.
- index.html: splash screen now uses the same /logo.svg via <img>,
with border-radius for the rounded-square frame.
* Polish logo: theme the in-app mark, gloss the OS icon, shrink cat
- components/AppLogo.tsx: back to an inline SVG. Background rect fills
with hsl(var(--primary)) so the in-app brand follows the theme
accent (was fixed navy when imported as <img>). Cat scaled to 68%
of the frame and centred so it doesn't crowd the edges at small
sidebar sizes.
- public/logo.svg + regenerated PNGs: polished OS icon variant with a
large rounded-square clip (rx 224 on 1024), top-left spotlight
radial gradient, subtle top sheen + bottom darkening, and an inner
edge vignette for a slight chamfer. The cat is shrunk to the same
68% as the in-app logo for visual consistency.
- Monochrome tray template (macOS menu bar) is rebuilt from the
shrunk-cat path set with all fills flattened to black; keeps a
clean silhouette instead of a filled rounded square.
* Smooth paws, richer gloss on app icon
- Drop the dark toe/claw detail paths from the source illustration
(indices 22-25, 30, 35, 37, 39 — the ones tracing vertical claw
dividers inside the paws). At small sizes those read as teeth/
claws; paws now render as clean rounded blobs.
- public/logo.svg (OS icon source): richer depth pass —
* two-tone navy vertical gradient (lighter top, deeper bottom)
* brighter upper-left spotlight for glassy highlight
* top sheen + bottom darkening for sheen-across-curve effect
* soft elliptical ground shadow beneath the cat to anchor it
* 2% inner edge stroke to crisp the rounded-square chamfer
- components/AppLogo.tsx: regenerated with the same cleaned cat set,
still themed via hsl(var(--primary)). The in-app mark stays flat
(no gloss) because the effect adds nothing at 20-40px sidebar
sizes and would fight theme accents.
- All raster variants (icon.png, dmg-fix-icon.png, tray color + tray
macOS template) rebuilt from the cleaned sources.
* Respect Apple icon safe area; drop gloss, add thin border
macOS icon was rendering to the full 1024x1024 canvas, so it looked
noticeably larger than neighbour apps (VS Code, Ghostty, Zed) in the
Dock. Apple's Big Sur+ convention puts the artwork body inside an
~824x824 safe area centred in a 1024 canvas, which is how those apps
are sized.
- public/logo.svg: artwork body is now 824x824 centred with ~100px
transparent padding. Corner radius 185 (close enough to the macOS
squircle at Dock scale). Cat rescaled so it keeps the same 68%
proportion within the smaller body.
- Gloss layers (spotlight / sheen / ground shadow / vignette) removed
per request — went for a Ghostty-style clean look instead.
- Thin white inner border (stroke 3px, 22% opacity) outlines the
rounded square for definition.
- Tray PNGs for Linux/Windows keep the full-bleed variant (tray slots
expect the icon to fill the space, unlike the Dock safe area).
- components/AppLogo.tsx unchanged conceptually — it still fills its
own bounding box via hsl(var(--primary)); the Apple safe-area rule
is Dock-specific, not relevant to in-app rendering.
* AppLogo: tighten corner radius to match previous (rx 18.75%)
Previous AppLogo used rx=12 on a 64 viewBox (18.75%). The inline
replacement had rx=224 on a 1024 viewBox (21.9%), which combined
with the caller's rounded-xl class read noticeably rounder in the
sidebar. Drop to rx=192 on 1024 viewBox so the in-app mark matches
the old proportions.
* Beef up icon border so it survives Dock downscaling
3 px at 22% opacity disappeared when rasterised down to ~128 px Dock /
Launchpad size. Bumped stroke-width to 8 px and opacity to 40% so the
inner highlight reads as ~1 px at Dock scale. Stroke is inset by
stroke-width/2 so it sits fully inside the rounded-square body (no
anti-alias bleed outside the safe area). Same treatment applied to the
full-bleed tray variant.
* Enlarge cat inside icon tile (68% -> 85% of body)
Dock render had too much navy margin around the mark. Bump the cat's
scale so it fills 85% of the Apple safe-area body while keeping a
visible bezel to the rounded corners and the inner border. Tray color
variant and macOS template (scale 0.9, no border) follow the same
scale-up.
* Add ripple effect on sidebar nav and tidy logo in vault header
- Add RippleButton wrapper + ripple keyframe; use it for the six vault
sidebar nav entries (Hosts, Keychain, Port Forwarding, Snippets,
Known Hosts, Logs) so clicks get a subtle material-style ripple.
- Shrink vault sidebar AppLogo to h-8 w-8 and drop the outer rounded-xl
so the visible corner comes from the SVG's own rx instead of the
container clip.
- Relax AppLogo tile rx/ry to 144 for a more moderate corner radius.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* AppLogo: bump tile corner radius back up to rx 18.75%
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Unify manager toolbars, tighten tabs and vault sidebar title
- Manager toolbars (Keychain, KnownHosts, PortForwarding, Snippets)
normalised to h-14 / h-10 controls with bg-secondary/80 backdrop-blur
and the shared bg-foreground/5 secondary button treatment, so Hosts /
Keychain / Known Hosts / Port Forwarding / Snippets headers size and
tint identically.
- Keychain filter tabs: drop primary tint and cert-count pill; reuse
the same foreground/5 vs foreground/10 active states as other
managers. Search input grown to h-10 to match.
- Known Hosts: removed the leftover text-xs on Scan System / Import
File so they inherit Button's text-sm like every other action.
- TopTabs: drop the 2px active-accent top line and add rounded-t-md +
overflow-hidden so active tabs read as a clean soft tab shape rather
than a banner.
- VaultView sidebar: wordmark grown to text-xl font-black italic with
tightened tracking; logo gap trimmed from 3 to 2.5; outer bg dropped
from secondary/80 to flat secondary to sit flush against the
toolbars.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
620 lines
20 KiB
TypeScript
620 lines
20 KiB
TypeScript
import {
|
|
ArrowRight,
|
|
ChevronDown,
|
|
FolderOpen,
|
|
Import,
|
|
LayoutGrid,
|
|
List as ListIcon,
|
|
RefreshCw,
|
|
Search,
|
|
Server,
|
|
Shield,
|
|
Trash2,
|
|
} from "lucide-react";
|
|
import React, {
|
|
memo,
|
|
useCallback,
|
|
useDeferredValue,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
} from "react";
|
|
import { useI18n } from "../application/i18n/I18nProvider";
|
|
import { useKnownHostsBackend } from "../application/state/useKnownHostsBackend";
|
|
import { useStoredViewMode, ViewMode } from "../application/state/useStoredViewMode";
|
|
import { STORAGE_KEY_VAULT_KNOWN_HOSTS_VIEW_MODE } from "../infrastructure/config/storageKeys";
|
|
import { logger } from "../lib/logger";
|
|
import { cn } from "../lib/utils";
|
|
import { Host, KnownHost } from "../types";
|
|
import { Button } from "./ui/button";
|
|
import {
|
|
ContextMenu,
|
|
ContextMenuContent,
|
|
ContextMenuItem,
|
|
ContextMenuTrigger,
|
|
} from "./ui/context-menu";
|
|
import { Dropdown, DropdownContent, DropdownTrigger } from "./ui/dropdown";
|
|
import { Input } from "./ui/input";
|
|
import { ScrollArea } from "./ui/scroll-area";
|
|
import { SortDropdown, SortMode } from "./ui/sort-dropdown";
|
|
import { toast } from "./ui/toast";
|
|
|
|
interface KnownHostsManagerProps {
|
|
knownHosts: KnownHost[];
|
|
hosts: Host[];
|
|
onSave: (knownHost: KnownHost) => void;
|
|
onUpdate: (knownHost: KnownHost) => void;
|
|
onDelete: (id: string) => void;
|
|
onConvertToHost: (knownHost: KnownHost) => void;
|
|
onImportFromFile: (hosts: KnownHost[]) => void;
|
|
onRefresh: () => void;
|
|
}
|
|
|
|
// Parse known_hosts file content - pure function, moved outside component
|
|
const parseKnownHostsFile = (content: string): KnownHost[] => {
|
|
const lines = content
|
|
.split("\n")
|
|
.filter((line) => line.trim() && !line.startsWith("#"));
|
|
const parsed: KnownHost[] = [];
|
|
|
|
for (const line of lines) {
|
|
try {
|
|
const parts = line.trim().split(/\s+/);
|
|
if (parts.length < 3) continue;
|
|
|
|
const [hostPattern, keyType, publicKey] = parts;
|
|
|
|
let hostname = hostPattern;
|
|
let port = 22;
|
|
|
|
const bracketMatch = hostPattern.match(/^\[([^\]]+)\]:(\d+)$/);
|
|
if (bracketMatch) {
|
|
hostname = bracketMatch[1];
|
|
port = parseInt(bracketMatch[2], 10);
|
|
} else if (hostPattern.includes(",")) {
|
|
hostname = hostPattern.split(",")[0];
|
|
}
|
|
|
|
if (hostname.startsWith("|1|")) {
|
|
hostname = "(hashed)";
|
|
}
|
|
|
|
parsed.push({
|
|
id: `kh-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
hostname,
|
|
port,
|
|
keyType,
|
|
publicKey: publicKey.slice(0, 64) + "...",
|
|
discoveredAt: Date.now(),
|
|
});
|
|
} catch {
|
|
logger.warn("Failed to parse known_hosts line:", line);
|
|
}
|
|
}
|
|
|
|
return parsed;
|
|
};
|
|
|
|
// Memoized Grid Item Component
|
|
interface HostItemProps {
|
|
knownHost: KnownHost;
|
|
converted: boolean;
|
|
viewMode: ViewMode;
|
|
onDelete: (id: string) => void;
|
|
onConvertToHost: (knownHost: KnownHost) => void;
|
|
}
|
|
|
|
const HostItem = React.memo<HostItemProps>(
|
|
({ knownHost, converted, viewMode, onDelete, onConvertToHost }) => {
|
|
const { t } = useI18n();
|
|
// Disabled to reduce log noise - uncomment for debugging
|
|
// console.log('[HostItem] render:', knownHost.hostname);
|
|
if (viewMode === "grid") {
|
|
return (
|
|
<ContextMenu>
|
|
<ContextMenuTrigger asChild>
|
|
<div
|
|
className={cn(
|
|
"group cursor-pointer soft-card elevate rounded-xl h-[68px] px-3 py-2",
|
|
converted && "opacity-60",
|
|
)}
|
|
>
|
|
{/* Quick action buttons on hover */}
|
|
<div className="absolute top-1 right-1 flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">
|
|
{!converted && (
|
|
<button
|
|
className="p-1 rounded hover:bg-primary/20 text-primary"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onConvertToHost(knownHost);
|
|
}}
|
|
title={t("action.convertToHost")}
|
|
>
|
|
<ArrowRight size={12} />
|
|
</button>
|
|
)}
|
|
<button
|
|
className="p-1 rounded hover:bg-destructive/20 text-destructive"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onDelete(knownHost.id);
|
|
}}
|
|
title={t("action.remove")}
|
|
>
|
|
<Trash2 size={12} />
|
|
</button>
|
|
</div>
|
|
<div className="flex items-center gap-3 h-full">
|
|
<div className="h-11 w-11 rounded-xl bg-primary/10 text-primary flex items-center justify-center flex-shrink-0">
|
|
<Server size={18} />
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-sm font-semibold truncate block">
|
|
{knownHost.hostname}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
{!converted && (
|
|
<ContextMenuItem onClick={() => onConvertToHost(knownHost)}>
|
|
<ArrowRight className="mr-2 h-4 w-4" /> {t("action.convertToHost")}
|
|
</ContextMenuItem>
|
|
)}
|
|
<ContextMenuItem
|
|
className="text-destructive"
|
|
onClick={() => onDelete(knownHost.id)}
|
|
>
|
|
<Trash2 className="mr-2 h-4 w-4" /> {t("action.remove")}
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
}
|
|
|
|
// List view
|
|
return (
|
|
<ContextMenu>
|
|
<ContextMenuTrigger asChild>
|
|
<div
|
|
className={cn(
|
|
"group flex items-center gap-3 px-3 py-2 h-14 rounded-lg hover:bg-secondary/60 transition-colors cursor-pointer",
|
|
converted && "opacity-60",
|
|
)}
|
|
>
|
|
<div className="h-11 w-11 rounded-xl bg-primary/10 text-primary flex items-center justify-center flex-shrink-0">
|
|
<Server size={18} />
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-sm font-semibold truncate block">
|
|
{knownHost.hostname}
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
|
{!converted && (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onConvertToHost(knownHost);
|
|
}}
|
|
title={t("action.convertToHost")}
|
|
>
|
|
<ArrowRight size={14} />
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
{!converted && (
|
|
<ContextMenuItem onClick={() => onConvertToHost(knownHost)}>
|
|
<ArrowRight className="mr-2 h-4 w-4" /> {t("action.convertToHost")}
|
|
</ContextMenuItem>
|
|
)}
|
|
<ContextMenuItem
|
|
className="text-destructive"
|
|
onClick={() => onDelete(knownHost.id)}
|
|
>
|
|
<Trash2 className="mr-2 h-4 w-4" /> {t("action.remove")}
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
);
|
|
},
|
|
);
|
|
|
|
HostItem.displayName = "HostItem";
|
|
|
|
const KnownHostsManager: React.FC<KnownHostsManagerProps> = ({
|
|
knownHosts,
|
|
hosts,
|
|
onSave: _onSave,
|
|
onUpdate: _onUpdate,
|
|
onDelete,
|
|
onConvertToHost,
|
|
onImportFromFile,
|
|
onRefresh,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const { readKnownHosts } = useKnownHostsBackend();
|
|
const [search, setSearch] = useState("");
|
|
const deferredSearch = useDeferredValue(search);
|
|
const [isScanning, setIsScanning] = useState(false);
|
|
const [viewMode, setViewMode] = useStoredViewMode(
|
|
STORAGE_KEY_VAULT_KNOWN_HOSTS_VIEW_MODE,
|
|
"grid",
|
|
);
|
|
const [sortMode, setSortMode] = useState<SortMode>("newest");
|
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
|
const hasScannedRef = React.useRef(false);
|
|
const RENDER_LIMIT = 100; // Limit rendered items for performance
|
|
|
|
// Define handleScanSystem before useEffect that depends on it
|
|
const handleScanSystem = useCallback(async (silent = false) => {
|
|
setIsScanning(true);
|
|
try {
|
|
const content = await readKnownHosts();
|
|
if (content === undefined) {
|
|
if (!silent) toast.error(
|
|
t("knownHosts.toast.scanUnavailable"),
|
|
t("vault.nav.knownHosts"),
|
|
);
|
|
return;
|
|
}
|
|
if (!content) {
|
|
if (!silent) toast.info(t("knownHosts.toast.scanNoFile"), t("vault.nav.knownHosts"));
|
|
return;
|
|
}
|
|
|
|
const parsed = parseKnownHostsFile(content);
|
|
if (parsed.length === 0) {
|
|
if (!silent) toast.info(
|
|
t("knownHosts.toast.scanNoEntries"),
|
|
t("vault.nav.knownHosts"),
|
|
);
|
|
return;
|
|
}
|
|
|
|
const existingHostnames = new Set(
|
|
knownHosts.map((h) => `${h.hostname}:${h.port}`),
|
|
);
|
|
const newHosts = parsed.filter(
|
|
(h) => !existingHostnames.has(`${h.hostname}:${h.port}`),
|
|
);
|
|
|
|
if (newHosts.length > 0) {
|
|
onImportFromFile(newHosts);
|
|
if (!silent) toast.success(
|
|
t("knownHosts.toast.scanImported", { count: newHosts.length }),
|
|
t("vault.nav.knownHosts"),
|
|
);
|
|
} else {
|
|
if (!silent) toast.info(t("knownHosts.toast.scanNoNew"), t("vault.nav.knownHosts"));
|
|
}
|
|
} catch (err) {
|
|
logger.error("Failed to scan system known_hosts:", err);
|
|
if (!silent) toast.error(
|
|
err instanceof Error ? err.message : t("knownHosts.toast.scanFailed"),
|
|
t("vault.nav.knownHosts"),
|
|
);
|
|
} finally {
|
|
onRefresh();
|
|
setIsScanning(false);
|
|
}
|
|
}, [knownHosts, onRefresh, onImportFromFile, readKnownHosts, t]);
|
|
|
|
// Auto-scan on first mount (silent — don't show toasts for missing known_hosts)
|
|
useEffect(() => {
|
|
if (!hasScannedRef.current) {
|
|
hasScannedRef.current = true;
|
|
const timer = setTimeout(() => {
|
|
handleScanSystem(true);
|
|
}, 100);
|
|
return () => clearTimeout(timer);
|
|
}
|
|
}, [handleScanSystem]);
|
|
|
|
// Sort and filter hosts with deduplication by hostname
|
|
const filteredHosts = useMemo(() => {
|
|
// First, deduplicate by hostname (keep the most recent one)
|
|
const hostnameMap = new Map<string, KnownHost>();
|
|
for (const h of knownHosts) {
|
|
const key = h.hostname;
|
|
const existing = hostnameMap.get(key);
|
|
if (!existing || h.discoveredAt > existing.discoveredAt) {
|
|
hostnameMap.set(key, h);
|
|
}
|
|
}
|
|
let result = Array.from(hostnameMap.values());
|
|
|
|
// Filter by search
|
|
if (deferredSearch.trim()) {
|
|
const term = deferredSearch.toLowerCase();
|
|
result = result.filter(
|
|
(h) =>
|
|
h.hostname.toLowerCase().includes(term) ||
|
|
h.keyType.toLowerCase().includes(term),
|
|
);
|
|
}
|
|
|
|
// Sort
|
|
result = [...result].sort((a, b) => {
|
|
switch (sortMode) {
|
|
case "az":
|
|
return a.hostname.localeCompare(b.hostname);
|
|
case "za":
|
|
return b.hostname.localeCompare(a.hostname);
|
|
case "newest":
|
|
return b.discoveredAt - a.discoveredAt;
|
|
case "oldest":
|
|
return a.discoveredAt - b.discoveredAt;
|
|
default:
|
|
return 0;
|
|
}
|
|
});
|
|
|
|
return result;
|
|
}, [knownHosts, deferredSearch, sortMode]);
|
|
|
|
// Limit rendered items for performance
|
|
const displayedHosts = useMemo(() => {
|
|
return filteredHosts.slice(0, RENDER_LIMIT);
|
|
}, [filteredHosts]);
|
|
|
|
const hasMore = filteredHosts.length > RENDER_LIMIT;
|
|
|
|
const handleFileSelect = useCallback(
|
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const file = e.target.files?.[0];
|
|
if (!file) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = (event) => {
|
|
const content = event.target?.result as string;
|
|
const parsed = parseKnownHostsFile(content);
|
|
|
|
// Filter out already existing hosts and directly import
|
|
const existingHostnames = new Set(
|
|
knownHosts.map((h) => `${h.hostname}:${h.port}`),
|
|
);
|
|
const newHosts = parsed.filter(
|
|
(h) => !existingHostnames.has(`${h.hostname}:${h.port}`),
|
|
);
|
|
|
|
if (newHosts.length > 0) {
|
|
onImportFromFile(newHosts);
|
|
}
|
|
};
|
|
reader.readAsText(file);
|
|
|
|
// Reset file input
|
|
if (fileInputRef.current) {
|
|
fileInputRef.current.value = "";
|
|
}
|
|
},
|
|
[knownHosts, onImportFromFile],
|
|
);
|
|
|
|
// Memoize host lookup for performance
|
|
const hostIdSet = useMemo(() => new Set(hosts.map((h) => h.id)), [hosts]);
|
|
|
|
// Pre-compute converted status for all known hosts
|
|
const convertedMap = useMemo(() => {
|
|
const map = new Map<string, boolean>();
|
|
for (const kh of knownHosts) {
|
|
if (kh.convertedToHostId) {
|
|
map.set(kh.id, hostIdSet.has(kh.convertedToHostId));
|
|
} else {
|
|
map.set(kh.id, false);
|
|
}
|
|
}
|
|
return map;
|
|
}, [knownHosts, hostIdSet]);
|
|
|
|
// Memoized handlers to prevent re-renders
|
|
const handleDelete = useCallback(
|
|
(id: string) => {
|
|
onDelete(id);
|
|
},
|
|
[onDelete],
|
|
);
|
|
|
|
const handleConvertToHost = useCallback(
|
|
(knownHost: KnownHost) => {
|
|
onConvertToHost(knownHost);
|
|
},
|
|
[onConvertToHost],
|
|
);
|
|
|
|
const openFilePicker = useCallback(() => fileInputRef.current?.click(), []);
|
|
|
|
// Memoize the rendered list to prevent re-renders
|
|
const renderedItems = useMemo(() => {
|
|
return displayedHosts.map((knownHost) => (
|
|
<HostItem
|
|
key={knownHost.id}
|
|
knownHost={knownHost}
|
|
converted={convertedMap.get(knownHost.id) || false}
|
|
viewMode={viewMode}
|
|
onDelete={handleDelete}
|
|
onConvertToHost={handleConvertToHost}
|
|
/>
|
|
));
|
|
}, [
|
|
displayedHosts,
|
|
convertedMap,
|
|
viewMode,
|
|
handleDelete,
|
|
handleConvertToHost,
|
|
]);
|
|
|
|
return (
|
|
<div className="h-full flex flex-col">
|
|
{/* Header */}
|
|
<div className="h-14 px-4 py-2 flex items-center gap-3 border-b border-border/50 bg-secondary/80 backdrop-blur">
|
|
<div className="flex-1 min-w-0 flex items-center gap-2">
|
|
<div className="relative flex-1 max-w-xs">
|
|
<Search
|
|
size={14}
|
|
className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"
|
|
/>
|
|
<Input
|
|
placeholder={t("knownHosts.search.placeholder")}
|
|
className="pl-9 h-10 bg-secondary border-border/60 text-sm"
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-1">
|
|
{/* View Mode Toggle */}
|
|
<Dropdown>
|
|
<DropdownTrigger asChild>
|
|
<Button variant="ghost" size="icon" className="h-10 w-10">
|
|
{viewMode === "grid" ? (
|
|
<LayoutGrid size={16} />
|
|
) : (
|
|
<ListIcon size={16} />
|
|
)}
|
|
<ChevronDown size={10} className="ml-0.5" />
|
|
</Button>
|
|
</DropdownTrigger>
|
|
<DropdownContent className="w-32" align="end">
|
|
<Button
|
|
variant={viewMode === "grid" ? "secondary" : "ghost"}
|
|
className="w-full justify-start gap-2 h-9"
|
|
onClick={() => setViewMode("grid")}
|
|
>
|
|
<LayoutGrid size={14} /> {t("vault.view.grid")}
|
|
</Button>
|
|
<Button
|
|
variant={viewMode === "list" ? "secondary" : "ghost"}
|
|
className="w-full justify-start gap-2 h-9"
|
|
onClick={() => setViewMode("list")}
|
|
>
|
|
<ListIcon size={14} /> {t("vault.view.list")}
|
|
</Button>
|
|
</DropdownContent>
|
|
</Dropdown>
|
|
|
|
{/* Sort Toggle */}
|
|
<SortDropdown
|
|
value={sortMode}
|
|
onChange={setSortMode}
|
|
className="h-10 w-10"
|
|
/>
|
|
</div>
|
|
<div className="w-px h-5 bg-border/50" />
|
|
<div className="flex items-center gap-2">
|
|
<Button
|
|
variant="secondary"
|
|
className="h-10 px-3 bg-foreground/5 text-foreground hover:bg-foreground/10 border-border/40"
|
|
onClick={() => handleScanSystem()}
|
|
disabled={isScanning}
|
|
>
|
|
<RefreshCw
|
|
size={14}
|
|
className={cn("mr-2", isScanning && "animate-spin")}
|
|
/>
|
|
{t("knownHosts.action.scanSystem")}
|
|
</Button>
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept=".txt,known_hosts"
|
|
className="hidden"
|
|
onChange={handleFileSelect}
|
|
/>
|
|
<Button
|
|
variant="secondary"
|
|
className="h-10 px-3 bg-foreground/5 text-foreground hover:bg-foreground/10 border-border/40"
|
|
onClick={openFilePicker}
|
|
>
|
|
<Import size={14} className="mr-2" />
|
|
{t("knownHosts.action.importFile")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Content */}
|
|
<ScrollArea className="flex-1">
|
|
<div
|
|
className={cn(
|
|
"p-4",
|
|
viewMode === "grid"
|
|
? "grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-4 gap-3"
|
|
: "flex flex-col gap-0",
|
|
)}
|
|
>
|
|
{displayedHosts.length === 0 ? (
|
|
<div
|
|
className={cn(
|
|
"flex flex-col items-center justify-center py-16 text-muted-foreground",
|
|
viewMode === "grid" && "col-span-full",
|
|
)}
|
|
>
|
|
<div className="h-16 w-16 rounded-2xl bg-secondary/80 flex items-center justify-center mb-4">
|
|
<Shield size={32} className="opacity-60" />
|
|
</div>
|
|
<h3 className="text-lg font-semibold text-foreground mb-2">
|
|
{t("knownHosts.empty.title")}
|
|
</h3>
|
|
<p className="text-sm text-center max-w-sm mb-4">
|
|
{t("knownHosts.empty.desc")}
|
|
</p>
|
|
<div className="flex gap-2">
|
|
<Button
|
|
variant="secondary"
|
|
onClick={() => handleScanSystem()}
|
|
disabled={isScanning}
|
|
>
|
|
<RefreshCw
|
|
size={14}
|
|
className={cn("mr-2", isScanning && "animate-spin")}
|
|
/>
|
|
{t("knownHosts.action.scanSystem")}
|
|
</Button>
|
|
<Button variant="outline" onClick={openFilePicker}>
|
|
<FolderOpen size={14} className="mr-2" />
|
|
{t("knownHosts.action.browseFile")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<>
|
|
{renderedItems}
|
|
{hasMore && (
|
|
<div
|
|
className={cn(
|
|
"text-center py-4 text-sm text-muted-foreground",
|
|
viewMode === "grid" && "col-span-full",
|
|
)}
|
|
>
|
|
{t("knownHosts.results.showingLimited", {
|
|
shown: displayedHosts.length,
|
|
total: filteredHosts.length,
|
|
})}
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
</ScrollArea>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
// Custom comparison - only compare data props, not callbacks
|
|
const knownHostsManagerAreEqual = (
|
|
prev: KnownHostsManagerProps,
|
|
next: KnownHostsManagerProps,
|
|
): boolean => {
|
|
return prev.knownHosts === next.knownHosts && prev.hosts === next.hosts;
|
|
};
|
|
|
|
export default memo(KnownHostsManager, knownHostsManagerAreEqual);
|