From 753754a0981ee57f1ceca3738bbcd9956510cb5c Mon Sep 17 00:00:00 2001 From: diogo464 Date: Thu, 14 Aug 2025 18:13:32 +0100 Subject: feat: implement file/directory move functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace fake move implementation with actual functionality using the existing rename API. The move feature now properly moves selected files/directories to chosen destinations. - Use existing /api/rename endpoint to move files by renaming paths - Handle multiple file selection with sequential move operations - Add comprehensive error handling for partial failures - Show detailed success/failure toast notifications - Refresh page after successful moves to display changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- frontend/components/drive/DriveDirectoryClient.tsx | 92 +++++++++++++++++++--- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/frontend/components/drive/DriveDirectoryClient.tsx b/frontend/components/drive/DriveDirectoryClient.tsx index 7c5827b..f523e4f 100644 --- a/frontend/components/drive/DriveDirectoryClient.tsx +++ b/frontend/components/drive/DriveDirectoryClient.tsx @@ -310,18 +310,86 @@ export function DriveDirectoryClient({ path, files, breadcrumbs, storageData, us const handleMove = async (destinationPath: string) => { - // TODO: Implement actual move API calls - console.log('Moving files:', Array.from(selectedFiles), 'to:', destinationPath) - setSelectedFiles(new Set()) - setMoveDialogOpen(false) - - toast({ - title: "Moved successfully", - description: `${selectedFiles.size} item(s) moved to ${destinationPath}`, - }) - - // Refresh page to show changes - window.location.reload() + const filesToMove = Array.from(selectedFiles) + let successCount = 0 + let errorCount = 0 + const errors: string[] = [] + + try { + // Move files sequentially using the rename API + for (const filePath of filesToMove) { + try { + // Extract filename from the full path + const fileName = filePath.split('/').pop() || '' + // Construct new path: destination + filename + const newPath = destinationPath.endsWith('/') + ? `${destinationPath}${fileName}` + : `${destinationPath}/${fileName}` + + const response = await fetch('/api/rename', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + oldPath: filePath, + newPath: newPath + }) + }) + + if (!response.ok) { + const result = await response.json() + throw new Error(result.error || `Move failed with status ${response.status}`) + } + + successCount++ + } catch (error) { + console.error(`Failed to move ${filePath}:`, error) + errorCount++ + errors.push(`${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`) + } + } + + // Clear selection and close dialog + setSelectedFiles(new Set()) + setMoveDialogOpen(false) + + // Show results + if (successCount > 0) { + toast({ + title: "Move completed", + description: `${successCount} item(s) moved successfully${errorCount > 0 ? `, ${errorCount} failed` : ''}`, + }) + + // Refresh page to show changes + window.location.reload() + } + + if (errorCount > 0 && successCount === 0) { + toast({ + title: "Move failed", + description: `All ${errorCount} item(s) failed to move. ${errors[0] || ''}`, + variant: "destructive" + }) + } else if (errorCount > 0) { + toast({ + title: "Partial move failure", + description: `${errorCount} item(s) failed to move. Check console for details.`, + variant: "destructive" + }) + console.error('Move errors:', errors) + } + + } catch (error) { + console.error('Move error:', error) + setSelectedFiles(new Set()) + setMoveDialogOpen(false) + toast({ + title: "Move failed", + description: error instanceof Error ? error.message : 'Unknown error occurred', + variant: "destructive" + }) + } } const handleCreateFolder = async () => { -- cgit