From 9726e7c2497af29d0c5425a1a9ebfecdeac8d43b Mon Sep 17 00:00:00 2001 From: Ishaan Dey Date: Sun, 28 Apr 2024 01:33:28 -0400 Subject: [PATCH] start file/folder ui --- frontend/components/editor/sidebar/file.tsx | 2 +- frontend/components/editor/sidebar/folder.tsx | 2 +- frontend/components/editor/sidebar/index.tsx | 63 ++++++++++++------- frontend/components/editor/sidebar/new.tsx | 51 +++++++++++++++ 4 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 frontend/components/editor/sidebar/new.tsx diff --git a/frontend/components/editor/sidebar/file.tsx b/frontend/components/editor/sidebar/file.tsx index 6d33039..79058b4 100644 --- a/frontend/components/editor/sidebar/file.tsx +++ b/frontend/components/editor/sidebar/file.tsx @@ -66,7 +66,7 @@ export default function SidebarFile({ > boolean }) { + const [creatingNew, setCreatingNew] = useState<"file" | "folder" | null>(null) + return (
Explorer
-
+
-
+ +
-
+ + {/* Todo: Implement file searching */} + {/*
+ */}
@@ -41,23 +52,31 @@ export default function Sidebar({
) : ( - files.map((child) => - child.type === "file" ? ( - + {files.map((child) => + child.type === "file" ? ( + + ) : ( + + ) + )} + {creatingNew !== null ? ( + setCreatingNew(null)} /> - ) : ( - - ) - ) + ) : null} + )}
diff --git a/frontend/components/editor/sidebar/new.tsx b/frontend/components/editor/sidebar/new.tsx new file mode 100644 index 0000000..3289e00 --- /dev/null +++ b/frontend/components/editor/sidebar/new.tsx @@ -0,0 +1,51 @@ +"use client" + +import Image from "next/image" +import { useEffect, useRef } from "react" + +export default function New({ + type, + stopEditing, +}: { + type: "file" | "folder" + stopEditing: () => void +}) { + const inputRef = useRef(null) + + const createFile = () => { + console.log("Create File") + stopEditing() + } + + useEffect(() => { + inputRef.current?.focus() + }, []) + + return ( +
+ File Icon +
{ + e.preventDefault() + createFile() + }} + > + createFile()} + /> +
+
+ ) +}