fix: deleteWithUndo uses _reloadAfterAction() instead of manual tree manipulation
Replaced fragile _removeFromTree() + displayTree spread (which had Alpine reactivity issues) with a clean _reloadAfterAction() call that reloads the tree from the API. This is the same approach used by doDelete() and doRename(), which work reliably. _reloadAfterAction also triggers the sidebar refresh via window.appState.refreshSidebarTree().
This commit is contained in:
@@ -1209,23 +1209,16 @@ window._wsInitData = (function() {
|
|||||||
this.undoItemId = node.db_id || node.id;
|
this.undoItemId = node.db_id || node.id;
|
||||||
this.undoMessage = 'Deleted "' + (node.name || 'item') + '"';
|
this.undoMessage = 'Deleted "' + (node.name || 'item') + '"';
|
||||||
this.undoVisible = true;
|
this.undoVisible = true;
|
||||||
// Soft-delete: actually delete after timeout
|
// Delete via API
|
||||||
var r = await fetch('/api/local-workspace/items/' + this.undoItemId, { method:'DELETE' });
|
var r = await fetch('/api/local-workspace/items/' + this.undoItemId, { method:'DELETE' });
|
||||||
if (!r.ok) { this.undoVisible = false; return; }
|
if (!r.ok) { this.undoVisible = false; return; }
|
||||||
// Remove from tree immediately
|
// Reload from API for reliability (sidebar refresh handled by _reloadAfterAction)
|
||||||
this._removeFromTree(this.tree, this.undoItemId);
|
this._reloadAfterAction();
|
||||||
if (!this.searchQuery && !this.filterType && !this.sortBy) this.displayTree = [...this.tree];
|
// Auto-dismiss undo banner after 5s
|
||||||
else if (this.sortBy) this.doSort();
|
|
||||||
else this.doFilter();
|
|
||||||
// Auto-dismiss + permanent after 5s
|
|
||||||
this.undoTimeout = setTimeout(function() {
|
this.undoTimeout = setTimeout(function() {
|
||||||
self.undoVisible = false;
|
self.undoVisible = false;
|
||||||
self.undoItemId = null;
|
self.undoItemId = null;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
// Directly refresh sidebar tree
|
|
||||||
if (window.appState && window.appState.refreshSidebarTree) {
|
|
||||||
window.appState.refreshSidebarTree();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
undoDelete() {
|
undoDelete() {
|
||||||
if (this.undoTimeout) clearTimeout(this.undoTimeout);
|
if (this.undoTimeout) clearTimeout(this.undoTimeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user