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) => {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
const parts = newCategory.split('/');
|
||||||
|
let currentPath = '';
|
||||||
|
|
||||||
|
for (const part of parts) {
|
||||||
|
currentPath += (currentPath ? '/' : '') + part;
|
||||||
try {
|
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, {
|
await tauriFetch(categoryUrl, {
|
||||||
method: 'MKCOL',
|
method: 'MKCOL',
|
||||||
headers: { 'Authorization': this.authHeader },
|
headers: { 'Authorization': this.authHeader },
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Directory might already exist
|
// Directory might already exist, continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user