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) => { const handleRenameCategory = async (oldName: string, newName: string) => {
// Update all notes with the old category to the new category // Move all notes from old category to new category
const notesToUpdate = notes.filter(note => note.category === oldName); const notesToMove = notes.filter(note => note.category === oldName);
for (const note of notesToUpdate) { for (const note of notesToMove) {
try { try {
const updatedNote = { ...note, category: newName }; const movedNote = await syncManager.moveNote(note, newName);
await syncManager.updateNote(updatedNote); setNotes(prevNotes => prevNotes.map(n => n.id === note.id ? movedNote : n));
setNotes(prevNotes => prevNotes.map(n => n.id === note.id ? updatedNote : n));
} catch (error) { } 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 oldPath = `/remote.php/dav/files/${this.username}/Notes${oldCategoryPath}/${note.filename}`;
const newPath = `/remote.php/dav/files/${this.username}/Notes${newCategoryPath}/${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) { if (newCategory) {
try { const parts = newCategory.split('/');
const categoryUrl = `${this.serverURL}/remote.php/dav/files/${this.username}/Notes/${newCategory}`; let currentPath = '';
await tauriFetch(categoryUrl, {
method: 'MKCOL', for (const part of parts) {
headers: { 'Authorization': this.authHeader }, currentPath += (currentPath ? '/' : '') + part;
}); try {
} catch (e) { const categoryUrl = `${this.serverURL}/remote.php/dav/files/${this.username}/Notes/${currentPath}`;
// Directory might already exist await tauriFetch(categoryUrl, {
method: 'MKCOL',
headers: { 'Authorization': this.authHeader },
});
} catch (e) {
// Directory might already exist, continue
}
} }
} }