"use client" import Image from "next/image" import { getIconForFile } from "vscode-icons-js" import { TFile, TTab } from "./types" import { useEffect, useRef, useState } from "react" export default function SidebarFile({ data, selectFile, handleRename, }: { data: TFile selectFile: (file: TTab) => void handleRename: ( id: string, newName: string, oldName: string, type: "file" | "folder" ) => boolean }) { const [imgSrc, setImgSrc] = useState(`/icons/${getIconForFile(data.name)}`) const [editing, setEditing] = useState(false) const inputRef = useRef(null) useEffect(() => { if (editing) { inputRef.current?.focus() } }, [editing]) const renameFile = () => { const renamed = handleRename( data.id, inputRef.current?.value ?? data.name, data.name, "file" ) if (!renamed && inputRef.current) { inputRef.current.value = data.name } setEditing(false) } return ( ) }