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() {
|
||||
return {
|
||||
init() {
|
||||
window.appState = this;
|
||||
},
|
||||
sidebarCollapsed: false,
|
||||
mobileSidebarOpen: false,
|
||||
showInvite: true,
|
||||
@@ -602,6 +605,9 @@
|
||||
if (r.ok) {
|
||||
self.refreshSidebarTree();
|
||||
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' })
|
||||
})
|
||||
.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'); });
|
||||
},
|
||||
deleteWorkspacePage(pageId, skipConfirm) {
|
||||
@@ -943,7 +949,7 @@
|
||||
headers: { 'X-CSRF-Token': this.getCsrfToken() }
|
||||
})
|
||||
.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'); });
|
||||
},
|
||||
|
||||
@@ -991,6 +997,10 @@
|
||||
.then(() => {
|
||||
this.refreshSidebarTree();
|
||||
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'); });
|
||||
},
|
||||
|
||||
@@ -498,10 +498,6 @@ window._wsInitData = (function() {
|
||||
var self = this;
|
||||
window.addEventListener('online', function() { self.online = true; });
|
||||
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
|
||||
this.loadWorkspaceTags();
|
||||
} catch(e) { console.error('Tree load error:', e); this.loaded = true; }
|
||||
@@ -1115,8 +1111,10 @@ window._wsInitData = (function() {
|
||||
_reloadAfterAction() {
|
||||
this._saveExpandedState();
|
||||
this._loadFolder(this.currentFolder);
|
||||
// Notify sidebar to refresh its tree
|
||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
||||
// Directly refresh sidebar tree
|
||||
if (window.appState && window.appState.refreshSidebarTree) {
|
||||
window.appState.refreshSidebarTree();
|
||||
}
|
||||
},
|
||||
|
||||
// ── Inline Rename ──
|
||||
@@ -1224,8 +1222,10 @@ window._wsInitData = (function() {
|
||||
self.undoVisible = false;
|
||||
self.undoItemId = null;
|
||||
}, 5000);
|
||||
// Notify sidebar to refresh its tree
|
||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
||||
// Directly refresh sidebar tree
|
||||
if (window.appState && window.appState.refreshSidebarTree) {
|
||||
window.appState.refreshSidebarTree();
|
||||
}
|
||||
},
|
||||
undoDelete() {
|
||||
if (this.undoTimeout) clearTimeout(this.undoTimeout);
|
||||
@@ -1563,8 +1563,10 @@ window._wsInitData = (function() {
|
||||
this.doFilter();
|
||||
}
|
||||
this._saveExpandedState();
|
||||
// Notify sidebar to refresh its tree
|
||||
document.dispatchEvent(new CustomEvent('flowdeck:sidebar-refresh'));
|
||||
// Directly refresh sidebar tree
|
||||
if (window.appState && window.appState.refreshSidebarTree) {
|
||||
window.appState.refreshSidebarTree();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user