From 511ebca4ad2165b478e9aa1d177f173a2d88eaab Mon Sep 17 00:00:00 2001 From: drelich Date: Thu, 26 Mar 2026 09:39:45 +0100 Subject: [PATCH] Fix category rename to actually move notes between folders - Changed handleRenameCategory to use moveNote instead of updateNote - Fixed moveNoteWebDAV to create nested subdirectories for categories with slashes - Now properly supports hierarchical category structures like 'Parent/Child' --- src/App.tsx | 13 ++++++------- src/api/nextcloud.ts | 24 +++++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8d60de2..e7500cc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -236,16 +236,15 @@ function App() { }; const handleRenameCategory = async (oldName: string, newName: string) => { - // Update all notes with the old category to the new category - const notesToUpdate = notes.filter(note => note.category === oldName); + // Move all notes from old category to new category + const notesToMove = notes.filter(note => note.category === oldName); - for (const note of notesToUpdate) { + for (const note of notesToMove) { try { - const updatedNote = { ...note, category: newName }; - await syncManager.updateNote(updatedNote); - setNotes(prevNotes => prevNotes.map(n => n.id === note.id ? updatedNote : n)); + const movedNote = await syncManager.moveNote(note, newName); + setNotes(prevNotes => prevNotes.map(n => n.id === note.id ? movedNote : n)); } catch (error) { - console.error(`Failed to update note ${note.id}:`, error); + console.error(`Failed to move note ${note.id}:`, error); } } diff --git a/src/api/nextcloud.ts b/src/api/nextcloud.ts index 8af8db0..35f0800 100644 --- a/src/api/nextcloud.ts +++ b/src/api/nextcloud.ts @@ -478,16 +478,22 @@ export class NextcloudAPI { const oldPath = `/remote.php/dav/files/${this.username}/Notes${oldCategoryPath}/${note.filename}`; const newPath = `/remote.php/dav/files/${this.username}/Notes${newCategoryPath}/${note.filename}`; - // Ensure new category directory exists + // Ensure new category directory exists (including nested subdirectories) if (newCategory) { - try { - const categoryUrl = `${this.serverURL}/remote.php/dav/files/${this.username}/Notes/${newCategory}`; - await tauriFetch(categoryUrl, { - method: 'MKCOL', - headers: { 'Authorization': this.authHeader }, - }); - } catch (e) { - // Directory might already exist + const parts = newCategory.split('/'); + let currentPath = ''; + + for (const part of parts) { + currentPath += (currentPath ? '/' : '') + part; + try { + const categoryUrl = `${this.serverURL}/remote.php/dav/files/${this.username}/Notes/${currentPath}`; + await tauriFetch(categoryUrl, { + method: 'MKCOL', + headers: { 'Authorization': this.authHeader }, + }); + } catch (e) { + // Directory might already exist, continue + } } }