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'
This commit is contained in:
drelich
2026-03-26 09:39:45 +01:00
parent 17c79a3aa8
commit 511ebca4ad
2 changed files with 21 additions and 16 deletions

View File

@@ -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);
}
}

View File

@@ -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) {
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/${newCategory}`;
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
// Directory might already exist, continue
}
}
}