From f2fafe555b65f9207c2c6e216b7d7b2ff83af866 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 3 Nov 2025 10:15:45 +0000
Subject: (최겸) 구매 PQ/실사 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/file-manager/FileManager.tsx | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

(limited to 'components/file-manager/FileManager.tsx')

diff --git a/components/file-manager/FileManager.tsx b/components/file-manager/FileManager.tsx
index c56bb16a..8463f03e 100644
--- a/components/file-manager/FileManager.tsx
+++ b/components/file-manager/FileManager.tsx
@@ -414,7 +414,7 @@ export function FileManager({ projectId }: FileManagerProps) {
   const { data: session } = useSession();
   const [items, setItems] = useState<FileItem[]>([]);
   const [treeItems, setTreeItems] = useState<FileItem[]>([]);
-  const [currentPath, setCurrentPath] = useState<string[]>([]);
+  const [currentPath, setCurrentPath] = useState<{ id: string; name: string }[]>([]);
   const [currentParentId, setCurrentParentId] = useState<string | null>(null);
   const [selectedItems, setSelectedItems] = useState<Set<string>>(new Set());
   const [expandedFolders, setExpandedFolders] = useState<Set<string>>(new Set());
@@ -543,6 +543,16 @@ export function FileManager({ projectId }: FileManagerProps) {
       }
     });
 
+    const byName = (a: FileItem, b: FileItem) =>
+      a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' });
+    // sort every children array
+    for (const node of itemMap.values()) {
+      if (node.children && node.children.length > 0) {
+        node.children.sort(byName);
+      }
+    }
+    // sort root nodes
+    rootItems.sort(byName);
     return rootItems;
   };
 
@@ -566,7 +576,9 @@ export function FileManager({ projectId }: FileManagerProps) {
       if (!response.ok) throw new Error('Failed to fetch files');
 
       const data = await response.json();
-      setItems(data);
+      const byName = (a: FileItem, b: FileItem) =>
+        a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' });
+      setItems([...data].sort(byName));
 
       // Build tree structure
       if (viewMode === 'list') {
@@ -1072,7 +1084,7 @@ export function FileManager({ projectId }: FileManagerProps) {
   // Handle folder double click
   const handleFolderOpen = (folder: FileItem) => {
     if (viewMode === 'grid') {
-      setCurrentPath([...currentPath, folder.name]);
+      setCurrentPath([...currentPath, { id: folder.id, name: folder.name }]);
       setCurrentParentId(folder.id);
     } else {
       // In tree view, expand/collapse
@@ -1117,6 +1129,7 @@ export function FileManager({ projectId }: FileManagerProps) {
     } else {
       setCurrentPath(currentPath.slice(0, index + 1));
       // Need to update parentId logic
+      setCurrentParentId(currentPath[index].id);
     }
   };
 
@@ -1269,11 +1282,11 @@ export function FileManager({ projectId }: FileManagerProps) {
                 Home
               </BreadcrumbLink>
             </BreadcrumbItem>
-            {currentPath.map((path, index) => (
+            {currentPath.map((seg, index) => (
               <BreadcrumbItem key={index}>
                 <ChevronRight className="h-4 w-4" />
-                <BreadcrumbLink onClick={() => navigateToPath(index)}>
-                  {path}
+                <BreadcrumbLink onClick={() => navigateToPath(index)}>                  
+                  {seg.name}
                 </BreadcrumbLink>
               </BreadcrumbItem>
             ))}
-- 
cgit v1.2.3

