"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 "./types" import SidebarFile from "./file" 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)} onDoubleClick={() => { setEditing(true) }} className="w-full flex items-center h-7 px-1 transition-colors hover:bg-secondary rounded-sm cursor-pointer" > Folder icon
{ e.preventDefault() console.log("file renamed") setEditing(false) }} > { console.log("file renamed") setEditing(false) }} />
{isOpen ? (
{data.children.map((child) => child.type === "file" ? ( ) : ( ) )}
) : null} ) }