import React from "react"; import { Button } from "@/components/ui/button.tsx"; import { Trash2, Folder, File, Plus, Pin } from "lucide-react"; import { Tabs, TabsList, TabsTrigger, TabsContent, } from "@/components/ui/tabs.tsx"; import { Input } from "@/components/ui/input.tsx"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { FileItem, ShortcutItem } from "../../../types/index"; interface FileManagerHomeViewProps { recent: FileItem[]; pinned: FileItem[]; shortcuts: ShortcutItem[]; onOpenFile: (file: FileItem) => void; onRemoveRecent: (file: FileItem) => void; onPinFile: (file: FileItem) => void; onUnpinFile: (file: FileItem) => void; onOpenShortcut: (shortcut: ShortcutItem) => void; onRemoveShortcut: (shortcut: ShortcutItem) => void; onAddShortcut: (path: string) => void; } export function FileManagerHomeView({ recent, pinned, shortcuts, onOpenFile, onRemoveRecent, onPinFile, onUnpinFile, onOpenShortcut, onRemoveShortcut, onAddShortcut, }: FileManagerHomeViewProps) { const { t } = useTranslation(); const [tab, setTab] = useState<"recent" | "pinned" | "shortcuts">("recent"); const [newShortcut, setNewShortcut] = useState(""); const renderFileCard = ( file: FileItem, onRemove: () => void, onPin?: () => void, isPinned = false, ) => (
onOpenFile(file)} > {file.type === "directory" ? ( ) : ( )}
{file.name}
{onPin && ( )} {onRemove && ( )}
); const renderShortcutCard = (shortcut: ShortcutItem) => (
onOpenShortcut(shortcut)} >
{shortcut.path}
); return (
setTab(v as "recent" | "pinned" | "shortcuts")} className="w-full" > {t("fileManager.recent")} {t("fileManager.pinned")} {t("fileManager.folderShortcuts")}
{recent.length === 0 ? (
{t("fileManager.noRecentFiles")}
) : ( recent.map((file) => renderFileCard( file, () => onRemoveRecent(file), () => (file.isPinned ? onUnpinFile(file) : onPinFile(file)), file.isPinned, ), ) )}
{pinned.length === 0 ? (
{t("fileManager.noPinnedFiles")}
) : ( pinned.map((file) => renderFileCard(file, undefined, () => onUnpinFile(file), true), ) )}
setNewShortcut(e.target.value)} className="flex-1 bg-dark-bg-button border-2 border-dark-border text-white placeholder:text-muted-foreground" onKeyDown={(e) => { if (e.key === "Enter" && newShortcut.trim()) { onAddShortcut(newShortcut.trim()); setNewShortcut(""); } }} />
{shortcuts.length === 0 ? (
{t("fileManager.noShortcuts")}
) : ( shortcuts.map((shortcut) => renderShortcutCard(shortcut)) )}
); }