From c21302815c41f59fd5076327c799e09a9a8b28d9 Mon Sep 17 00:00:00 2001 From: Richard Roberson Date: Wed, 12 Feb 2025 21:12:49 -0700 Subject: [PATCH] Change folder creation popover --- src/components/DocumentList.tsx | 81 ++++++++++++++++----------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/src/components/DocumentList.tsx b/src/components/DocumentList.tsx index 65da8f1..7c18848 100644 --- a/src/components/DocumentList.tsx +++ b/src/components/DocumentList.tsx @@ -70,7 +70,6 @@ export function DocumentList() { const [newFolderName, setNewFolderName] = useState(''); const [pendingFolderDocs, setPendingFolderDocs] = useState<{ source: DocumentListDocument, target: DocumentListDocument } | null>(null); const [collapsedFolders, setCollapsedFolders] = useState>(new Set()); - const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 }); useEffect(() => { // Load saved state @@ -164,7 +163,6 @@ export function DocumentList() { // Only highlight target if neither document is in a folder if (!doc.folderId) { setDropTargetDoc(doc); - setMousePosition({ x: e.clientX, y: e.clientY }); } } }; @@ -213,9 +211,12 @@ export function DocumentList() { }, [pendingFolderDocs, newFolderName]); const handleFolderNameKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Enter' || e.key === 'Escape') { + if (e.key === 'Enter') { e.preventDefault(); createFolder(); + } else if (e.key === 'Escape') { + setPendingFolderDocs(null); + setNewFolderName(''); } }; @@ -328,17 +329,16 @@ export function DocumentList() { {(doc.size / 1024 / 1024).toFixed(2)} MB

- - + ); @@ -387,7 +387,7 @@ export function DocumentList() { className={`rounded-lg p-2 transition-all bg-offbase shadow-lg transition-shadow ${dropTargetDoc?.folderId === folder.id ? 'ring-2 ring-primary bg-primary/10' : '' }`} > -
+

{folder.name}

- - <> - {pendingFolderDocs && ( -
- -
-

Name your new folder

- setNewFolderName(e.target.value)} - onKeyDown={handleFolderNameKeyDown} - placeholder="Enter folder name" - className="w-full rounded-lg bg-background py-2 px-3 text-foreground shadow-sm focus:outline-none focus:ring-2 focus:ring-accent" - autoFocus - /> -

Press Enter to create

-
-
+ + {pendingFolderDocs && ( +
+
+ +
+

Create New Folder

+
+ setNewFolderName(e.target.value)} + onKeyDown={handleFolderNameKeyDown} + placeholder="Enter folder name" + className="w-full rounded-lg bg-base py-2 px-3 text-foreground shadow-sm focus:outline-none focus:ring-2 focus:ring-accent" + autoFocus + /> +

Press Enter to create or Escape to cancel

+
- )} - +
+
+ )}