fix: direct sidebar refresh via window.appState instead of events
Replaced the fragile event-based sidebar refresh with direct function calls: - appState.init() now sets window.appState = this - _reloadAfterAction(), doCreate(), deleteWithUndo() call window.appState.refreshSidebarTree() directly (no DOM event) - Sidebar handlers (drop, deleteWorkspacePage, wsCtxAction, newFolder) call window._wsData._reloadAfterAction() directly (no DOM event) - Removed event listeners for flowdeck:workspace-changed and flowdeck:sidebar-refresh from local_workspace.html This is more reliable than CustomEvent which had timing/scope issues.
This commit is contained in:
+12
-2
@@ -511,6 +511,9 @@
|
|||||||
|
|
||||||
function appState() {
|
function appState() {
|
||||||
return {
|
return {
|
||||||
|
init() {
|
||||||
|
window.appState = this;
|
||||||
|
},
|
||||||
sidebarCollapsed: false,
|
sidebarCollapsed: false,
|
||||||
mobileSidebarOpen: false,
|
mobileSidebarOpen: false,
|
||||||
showInvite: true,
|
showInvite: true,
|
||||||
@@ -602,6 +605,9 @@
|
|||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
self.refreshSidebarTree();
|
self.refreshSidebarTree();
|
||||||
document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed'));
|
document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed'));
|
||||||
|
if (window._wsData && window._wsData._reloadAfterAction) {
|
||||||
|
window._wsData._reloadAfterAction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -933,7 +939,7 @@
|
|||||||
body: JSON.stringify({ name: name.trim(), type: 'folder' })
|
body: JSON.stringify({ name: name.trim(), type: 'folder' })
|
||||||
})
|
})
|
||||||
.then(r => { if (!r.ok) throw new Error('Failed'); return r.json(); })
|
.then(r => { if (!r.ok) throw new Error('Failed'); return r.json(); })
|
||||||
.then(() => { this.refreshSidebarTree(); document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed')); })
|
.then(() => { this.refreshSidebarTree(); document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed')); if (window._wsData && window._wsData._reloadAfterAction) { window._wsData._reloadAfterAction(); } })
|
||||||
.catch(err => { this.toast('Failed: ' + err.message, 'error'); });
|
.catch(err => { this.toast('Failed: ' + err.message, 'error'); });
|
||||||
},
|
},
|
||||||
deleteWorkspacePage(pageId, skipConfirm) {
|
deleteWorkspacePage(pageId, skipConfirm) {
|
||||||
@@ -943,7 +949,7 @@
|
|||||||
headers: { 'X-CSRF-Token': this.getCsrfToken() }
|
headers: { 'X-CSRF-Token': this.getCsrfToken() }
|
||||||
})
|
})
|
||||||
.then(r => { if (!r.ok) throw new Error('Failed'); return r.json(); })
|
.then(r => { if (!r.ok) throw new Error('Failed'); return r.json(); })
|
||||||
.then(() => { this.refreshSidebarTree(); document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed')); })
|
.then(() => { this.refreshSidebarTree(); document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed')); if (window._wsData && window._wsData._reloadAfterAction) { window._wsData._reloadAfterAction(); } })
|
||||||
.catch(err => { this.toast('Failed: ' + err.message, 'error'); });
|
.catch(err => { this.toast('Failed: ' + err.message, 'error'); });
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -991,6 +997,10 @@
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
this.refreshSidebarTree();
|
this.refreshSidebarTree();
|
||||||
document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed'));
|
document.dispatchEvent(new CustomEvent('flowdeck:workspace-changed'));
|
||||||
|
// Also directly notify main content if on local-workspace page
|
||||||
|
if (window._wsData && window._wsData._reloadAfterAction) {
|
||||||
|
window._wsData._reloadAfterAction();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => { this.toast('Move failed: ' + err.message, 'error'); });
|
.catch(err => { this.toast('Move failed: ' + err.message, 'error'); });
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -498,10 +498,6 @@ window._wsInitData = (function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
window.addEventListener('online', function() { self.online = true; });
|
window.addEventListener('online', function() { self.online = true; });
|
||||||
window.addEventListener('offline', function() { self.online = false; });
|
window.addEventListener('offline', function() { self.online = false; });
|
||||||
// Listen for workspace changes from sidebar context menu
|
|
||||||
document.addEventListener('flowdeck:workspace-changed', function() {
|
|
||||||
self._reloadAfterAction();
|
|
||||||
});
|
|
||||||
// Load workspace tags
|
// Load workspace tags
|
||||||
this.loadWorkspaceTags();
|
this.loadWorkspaceTags();
|
||||||
} catch(e) { console.error('Tree load error:', e); this.loaded = true; }
|
} catch(e) { console.error('Tree load error:', e); this.loaded = true; }
|
||||||
@@ -1115,8 +1111,10 @@ window._wsInitData = (function() {
|
|||||||
_reloadAfterAction() {
|
_reloadAfterAction() {
|
||||||
this._saveExpandedState();
|
this._saveExpandedState();
|
||||||
this._loadFolder(this.currentFolder);
|
this._loadFolder(this.currentFolder);
|
||||||
// Notify sidebar to refresh its tree
|
// Directly refresh sidebar tree
|
||||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
if (window.appState && window.appState.refreshSidebarTree) {
|
||||||
|
window.appState.refreshSidebarTree();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// ── Inline Rename ──
|
// ── Inline Rename ──
|
||||||
@@ -1224,8 +1222,10 @@ window._wsInitData = (function() {
|
|||||||
self.undoVisible = false;
|
self.undoVisible = false;
|
||||||
self.undoItemId = null;
|
self.undoItemId = null;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
// Notify sidebar to refresh its tree
|
// Directly refresh sidebar tree
|
||||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
if (window.appState && window.appState.refreshSidebarTree) {
|
||||||
|
window.appState.refreshSidebarTree();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
undoDelete() {
|
undoDelete() {
|
||||||
if (this.undoTimeout) clearTimeout(this.undoTimeout);
|
if (this.undoTimeout) clearTimeout(this.undoTimeout);
|
||||||
@@ -1563,8 +1563,10 @@ window._wsInitData = (function() {
|
|||||||
this.doFilter();
|
this.doFilter();
|
||||||
}
|
}
|
||||||
this._saveExpandedState();
|
this._saveExpandedState();
|
||||||
// Notify sidebar to refresh its tree
|
// Directly refresh sidebar tree
|
||||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
if (window.appState && window.appState.refreshSidebarTree) {
|
||||||
|
window.appState.refreshSidebarTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user