"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, addNew, }: { socket: Socket; type: "file" | "folder"; stopEditing: () => void; addNew: (name: string, type: "file" | "folder") => 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, ({ success }: { success: boolean }) => { if (success) { addNew(name, type); } } ); } else { socket.emit("createFolder", name, () => { addNew(name, type); }); } } } stopEditing(); } useEffect(() => { inputRef.current?.focus(); }, []); return (
File Icon
{ e.preventDefault(); createNew(); }} > createNew()} />
); }