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:
13
src/App.tsx
13
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user