diff options
| author | diogo464 <[email protected]> | 2025-08-11 16:49:07 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-11 16:49:07 +0100 |
| commit | c2f5cd994d4d02b8b2ed7ba7b8ab8911c8ad6216 (patch) | |
| tree | a12bf5f46f3e30cfc1e3607bbcda230e26fefc94 /frontend | |
| parent | 741d42c7ab635180ab416dc749e1bcb774a22f5e (diff) | |
Add sorted tree structure to Drive_tree function
- Sort directories first, then files
- Both categories sorted alphabetically (case-insensitive)
- Recursive sorting applied to all tree levels
- Server-side sorting for better performance
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/lib/drive_server.ts | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/frontend/lib/drive_server.ts b/frontend/lib/drive_server.ts index 7e2193c..e6dd833 100644 --- a/frontend/lib/drive_server.ts +++ b/frontend/lib/drive_server.ts | |||
| @@ -142,5 +142,26 @@ export async function Drive_tree(): Promise<DriveTreeResponse> { | |||
| 142 | } | 142 | } |
| 143 | }); | 143 | }); |
| 144 | 144 | ||
| 145 | return { root: rootNodes }; | 145 | // Third pass: sort all levels (directories first, then files, both alphabetically) |
| 146 | const sortNodes = (nodes: DriveTreeNode[]): DriveTreeNode[] => { | ||
| 147 | const sorted = nodes.sort((a, b) => { | ||
| 148 | // Directories first, then files | ||
| 149 | if (a.type === "dir" && b.type === "file") return -1; | ||
| 150 | if (a.type === "file" && b.type === "dir") return 1; | ||
| 151 | |||
| 152 | // Both same type, sort alphabetically by name (case-insensitive) | ||
| 153 | return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); | ||
| 154 | }); | ||
| 155 | |||
| 156 | // Recursively sort children | ||
| 157 | sorted.forEach(node => { | ||
| 158 | if (node.children) { | ||
| 159 | node.children = sortNodes(node.children); | ||
| 160 | } | ||
| 161 | }); | ||
| 162 | |||
| 163 | return sorted; | ||
| 164 | }; | ||
| 165 | |||
| 166 | return { root: sortNodes(rootNodes) }; | ||
| 146 | } \ No newline at end of file | 167 | } \ No newline at end of file |
