feat: Implement collection deletion and loading spinners
- Add API endpoint and handler to delete collections - Introduce LoadingSpinner component for async operations - Show loading spinners during file loading and preview rendering - Enhance modal accessibility by removing aria-hidden attribute - Refactor delete functionality to distinguish between collections and files/folders - Remove unused collection definitions from config
This commit is contained in:
@@ -189,26 +189,62 @@ class FileTreeActions {
|
||||
},
|
||||
|
||||
delete: async function (path, isDir) {
|
||||
const name = path.split('/').pop();
|
||||
const name = path.split('/').pop() || this.webdavClient.currentCollection;
|
||||
const type = isDir ? 'folder' : 'file';
|
||||
|
||||
const confirmed = await window.ModalManager.confirm(
|
||||
`Are you sure you want to delete ${name}?`,
|
||||
`Delete this ${type}?`,
|
||||
true
|
||||
);
|
||||
// Check if this is a root-level collection (empty path or single-level path)
|
||||
const pathParts = path.split('/').filter(p => p.length > 0);
|
||||
const isCollection = pathParts.length === 0;
|
||||
|
||||
if (!confirmed) return;
|
||||
if (isCollection) {
|
||||
// Deleting a collection - use backend API
|
||||
const confirmed = await window.ModalManager.confirm(
|
||||
`Are you sure you want to delete the collection "${name}"? This will delete all files and folders in it.`,
|
||||
'Delete Collection?',
|
||||
true
|
||||
);
|
||||
|
||||
await this.webdavClient.delete(path);
|
||||
if (!confirmed) return;
|
||||
|
||||
// Clear undo history since manual delete occurred
|
||||
if (this.fileTree.lastMoveOperation) {
|
||||
this.fileTree.lastMoveOperation = null;
|
||||
try {
|
||||
// Call backend API to delete collection
|
||||
const response = await fetch(`/api/collections/${name}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
throw new Error(error || 'Failed to delete collection');
|
||||
}
|
||||
|
||||
showNotification(`Collection "${name}" deleted successfully`, 'success');
|
||||
|
||||
// Reload the page to refresh collections list
|
||||
window.location.href = '/';
|
||||
} catch (error) {
|
||||
Logger.error('Failed to delete collection:', error);
|
||||
showNotification(`Failed to delete collection: ${error.message}`, 'error');
|
||||
}
|
||||
} else {
|
||||
// Deleting a regular file/folder - use WebDAV
|
||||
const confirmed = await window.ModalManager.confirm(
|
||||
`Are you sure you want to delete ${name}?`,
|
||||
`Delete this ${type}?`,
|
||||
true
|
||||
);
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
await this.webdavClient.delete(path);
|
||||
|
||||
// Clear undo history since manual delete occurred
|
||||
if (this.fileTree.lastMoveOperation) {
|
||||
this.fileTree.lastMoveOperation = null;
|
||||
}
|
||||
|
||||
await this.fileTree.load();
|
||||
showNotification(`Deleted ${name}`, 'success');
|
||||
}
|
||||
|
||||
await this.fileTree.load();
|
||||
showNotification(`Deleted ${name}`, 'success');
|
||||
},
|
||||
|
||||
download: async function (path, isDir) {
|
||||
|
||||
Reference in New Issue
Block a user