add project size ratelimiting

This commit is contained in:
Ishaan Dey
2024-05-09 22:32:21 -07:00
parent e86e86dbe2
commit 3325b20aed
4 changed files with 65 additions and 23 deletions

View File

@ -1,9 +1,9 @@
"use client"
"use client";
import { validateName } from "@/lib/utils"
import Image from "next/image"
import { useEffect, useRef } from "react"
import { Socket } from "socket.io-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,
@ -11,31 +11,38 @@ export default function New({
stopEditing,
addNew,
}: {
socket: Socket
type: "file" | "folder"
stopEditing: () => void
addNew: (name: string, type: "file" | "folder") => void
socket: Socket;
type: "file" | "folder";
stopEditing: () => void;
addNew: (name: string, type: "file" | "folder") => void;
}) {
const inputRef = useRef<HTMLInputElement>(null)
const inputRef = useRef<HTMLInputElement>(null);
const createNew = () => {
const name = inputRef.current?.value
const name = inputRef.current?.value;
if (name) {
const valid = validateName(name, "", type)
const valid = validateName(name, "", type);
if (valid.status) {
if (type === "file") {
socket.emit("createFile", name)
socket.emit(
"createFile",
name,
({ success }: { success: boolean }) => {
if (success) {
addNew(name, type);
}
}
);
}
addNew(name, type)
}
}
stopEditing()
}
stopEditing();
};
useEffect(() => {
inputRef.current?.focus()
}, [])
inputRef.current?.focus();
}, []);
return (
<div className="w-full flex items-center h-7 px-1 hover:bg-secondary rounded-sm cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring">
@ -52,8 +59,8 @@ export default function New({
/>
<form
onSubmit={(e) => {
e.preventDefault()
createNew()
e.preventDefault();
createNew();
}}
>
<input
@ -63,5 +70,5 @@ export default function New({
/>
</form>
</div>
)
);
}