From 821330eba54751718dfebc289a30548830b4a0a8 Mon Sep 17 00:00:00 2001 From: Kobe Date: Sat, 31 May 2025 12:09:24 +0200 Subject: [PATCH] Fix name not in rename modal --- static/js/rooms/fileManager.js | 10 +++++++++- static/js/rooms/modalManager.js | 13 ++++++++++--- static/js/rooms/viewManager.js | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/static/js/rooms/fileManager.js b/static/js/rooms/fileManager.js index 823a39d..e46d469 100644 --- a/static/js/rooms/fileManager.js +++ b/static/js/rooms/fileManager.js @@ -29,6 +29,8 @@ export class FileManager { this.fileToDeletePath = ''; this.fileToMove = null; this.fileToMovePath = ''; + this.fileToRename = null; + this.fileToRenamePath = ''; console.log('[FileManager] Initialized with roomManager:', roomManager); } @@ -139,7 +141,10 @@ export class FileManager { 'Content-Type': 'application/json', 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content') }, - body: JSON.stringify({ new_name: newName }) + body: JSON.stringify({ + new_name: newName, + path: this.fileToRenamePath + }) }); console.log('[FileManager] Rename response status:', response.status); @@ -157,6 +162,9 @@ export class FileManager { await this.roomManager.viewManager.renderFiles(this.currentFiles); console.log('[FileManager] File renamed and view updated'); } + // Clear the rename state + this.fileToRename = null; + this.fileToRenamePath = ''; return { success: true, message: 'File renamed successfully' }; } else { throw new Error(result.message || 'Failed to rename file'); diff --git a/static/js/rooms/modalManager.js b/static/js/rooms/modalManager.js index 9c5c061..45a262e 100644 --- a/static/js/rooms/modalManager.js +++ b/static/js/rooms/modalManager.js @@ -174,8 +174,15 @@ export class ModalManager { /** * Shows the rename modal for a file or folder. * @param {string} filename - The current name of the file/folder + * @param {string} [path=''] - The path of the file/folder */ - showRenameModal(filename) { + showRenameModal(filename, path = '') { + console.log('[ModalManager] Showing rename modal for:', { filename, path }); + + // Store the file info in the FileManager + this.roomManager.fileManager.fileToRename = filename; + this.roomManager.fileManager.fileToRenamePath = path; + document.getElementById('renameError').textContent = ''; const ext = filename.includes('.') ? filename.substring(filename.lastIndexOf('.')) : ''; const isFile = ext && filename.lastIndexOf('.') > 0; @@ -444,9 +451,9 @@ export class ModalManager { } const result = await this.roomManager.fileManager.renameFile( - this.renameTarget, + this.roomManager.fileManager.fileToRename, newName, - this.roomManager.currentPath + this.roomManager.fileManager.fileToRenamePath ); if (result.success) { diff --git a/static/js/rooms/viewManager.js b/static/js/rooms/viewManager.js index 5cf8c70..8253353 100644 --- a/static/js/rooms/viewManager.js +++ b/static/js/rooms/viewManager.js @@ -351,9 +351,9 @@ export class ViewManager { if (this.roomManager.canRename) { actions.push(` - `); }