diff --git a/app/templates/local_workspace.html b/app/templates/local_workspace.html index 6e57e52..e2b524a 100644 --- a/app/templates/local_workspace.html +++ b/app/templates/local_workspace.html @@ -668,13 +668,52 @@ document.addEventListener('alpine:init', function() { body:JSON.stringify(body) }); if (r.ok) { + var d = await r.json(); this.showCreate = false; this.parentFolder = null; this.newName = ''; - this._reloadAfterAction(); + // Insert new node into tree without reload + var isFolder = this.createType === 'folder'; + var newNode = { + id: d.id, db_id: d.id, name: d.name || n, + is_folder: isFolder, type: isFolder ? 'folder' : 'page', + content_format: isFolder ? null : 'blocks', + children: [], has_children: false, depth: 0 + }; + if (this.parentFolder && this.parentFolder.db_id) { + // Insert as child of parent folder + this._insertIntoParent(this.tree, this.parentFolder.db_id, newNode); + // Auto-expand parent so the new item is visible + this.expanded[this.parentFolder.db_id] = true; + this.expanded = Object.assign({}, this.expanded); + } else { + // Insert at root + this.tree.unshift(newNode); + } + // Update displayTree + if (!this.searchQuery && !this.filterType) { + this.displayTree = this.tree; + } + this._saveExpandedState(); } }, + _insertIntoParent(nodes, parentId, newNode) { + for (var i=0; i