"use client"; import Image from "next/image"; import { useEffect, useRef, useState } from "react"; import { getIconForFolder, getIconForOpenFolder } from "vscode-icons-js"; import { TFile, TFolder, TTab } from "@/lib/types"; import SidebarFile from "./file"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, } from "@/components/ui/context-menu"; import { Pencil, Trash2 } from "lucide-react"; export default function SidebarFolder({ data, selectFile, handleRename, handleDeleteFile, handleDeleteFolder, }: { data: TFolder; selectFile: (file: TTab) => void; handleRename: ( id: string, newName: string, oldName: string, type: "file" | "folder" ) => boolean; handleDeleteFile: (file: TFile) => void; handleDeleteFolder: (folder: TFolder) => void; }) { const [isOpen, setIsOpen] = useState(false); const folder = isOpen ? getIconForOpenFolder(data.name) : getIconForFolder(data.name); const [editing, setEditing] = useState(false); const inputRef = useRef(null); useEffect(() => { if (editing) { inputRef.current?.focus(); } }, [editing]); return ( setIsOpen((prev) => !prev)} className="w-full flex items-center h-7 px-1 transition-colors hover:bg-secondary rounded-sm cursor-pointer" > Folder icon
{ e.preventDefault(); setEditing(false); }} > { setEditing(false); }} />
{ setEditing(true); }} > Rename { console.log("delete"); // setPendingDelete(true) // handleDeleteFile(data) }} > Delete {isOpen ? (
{data.children.map((child) => child.type === "file" ? ( ) : ( ) )}
) : null}
); }