"use client" import { validateName } from "@/lib/utils" import Image from "next/image" import { useEffect, useRef } from "react" import { Socket } from "socket.io-client" export default function New({ socket, type, stopEditing, }: { socket: Socket type: "file" | "folder" stopEditing: () => void }) { const inputRef = useRef(null) function createNew() { const name = inputRef.current?.value if (name) { const valid = validateName(name, "", type) if (valid.status) { if (type === "file") { socket.emit("createFile", { name }) } else { socket.emit("createFolder", { name }) } } } stopEditing() } useEffect(() => { inputRef.current?.focus() }, []) return (
File Icon
{ e.preventDefault() createNew() }} > createNew()} />
) }