diff --git a/modules/rtime/components/folk-timebank-app.ts b/modules/rtime/components/folk-timebank-app.ts index fda9aafd..8c8c9c72 100644 --- a/modules/rtime/components/folk-timebank-app.ts +++ b/modules/rtime/components/folk-timebank-app.ts @@ -362,6 +362,29 @@ class FolkTimebankApp extends HTMLElement { if (name === 'view' && (val === 'canvas' || val === 'collaborate' || val === 'dashboard')) this.currentView = val; } + private _onShellTabChange = (e: Event) => { + const tab = (e as CustomEvent).detail?.tab; + if (!tab) return; + if (tab === 'pool') this._switchView('canvas'); + else if (tab === 'fulfillment') this._switchView('dashboard'); + // 'cyclos' tab is a redirect, no client-side handling needed + }; + + private _switchView(view: 'canvas' | 'collaborate' | 'dashboard') { + if (view === this.currentView) return; + this._history.push(view); + this.currentView = view; + const canvasView = this.shadow.getElementById('canvas-view'); + const collabView = this.shadow.getElementById('collaborate-view'); + const dashView = this.shadow.getElementById('dashboard-view'); + if (canvasView) canvasView.style.display = view === 'canvas' ? 'flex' : 'none'; + if (collabView) collabView.style.display = view === 'collaborate' ? 'flex' : 'none'; + if (dashView) dashView.style.display = view === 'dashboard' ? 'flex' : 'none'; + if (view === 'canvas') { this.resizePoolCanvas(); this.rebuildSidebar(); } + if (view === 'collaborate') this.refreshCollaborate(); + if (view === 'dashboard') this.refreshDashboard(); + } + connectedCallback() { this.space = this.getAttribute('space') || 'demo'; const rawView = this.getAttribute('view'); @@ -383,6 +406,7 @@ class FolkTimebankApp extends HTMLElement { this.fetchData(); this._stopPresence = startPresenceHeartbeat(() => ({ module: 'rtime', context: 'Timebank' })); if (this.space !== 'demo') this.subscribeOffline(); + document.addEventListener('rapp-tab-change', this._onShellTabChange); window.addEventListener('rspace-view-restored', this._onViewRestored as EventListener); } @@ -421,6 +445,7 @@ class FolkTimebankApp extends HTMLElement { disconnectedCallback() { this._history.destroy(); + document.removeEventListener('rapp-tab-change', this._onShellTabChange); window.removeEventListener('rspace-view-restored', this._onViewRestored as EventListener); if (this.animFrame) cancelAnimationFrame(this.animFrame); this._stopPresence?.(); this._offlineUnsub?.(); this._offlineUnsub = null; @@ -435,18 +460,7 @@ class FolkTimebankApp extends HTMLElement { private _onViewRestored = (e: CustomEvent) => { if (e.detail?.moduleId !== 'rtime') return; - this.currentView = e.detail.view; - // Toggle visibility of view panels - const canvasView = this.shadow.getElementById('canvas-view'); - const collabView = this.shadow.getElementById('collaborate-view'); - const dashView = this.shadow.getElementById('dashboard-view'); - if (canvasView) canvasView.style.display = this.currentView === 'canvas' ? 'flex' : 'none'; - if (collabView) collabView.style.display = this.currentView === 'collaborate' ? 'flex' : 'none'; - if (dashView) dashView.style.display = this.currentView === 'dashboard' ? 'flex' : 'none'; - this.shadow.querySelectorAll('.tab').forEach(t => t.classList.toggle('active', (t as HTMLElement).dataset.view === this.currentView)); - if (this.currentView === 'canvas') { this.resizePoolCanvas(); this.rebuildSidebar(); } - if (this.currentView === 'collaborate') this.refreshCollaborate(); - if (this.currentView === 'dashboard') this.refreshDashboard(); + this._switchView(e.detail.view); }; private async fetchData() { @@ -528,18 +542,6 @@ class FolkTimebankApp extends HTMLElement { private render() { this.shadow.innerHTML = ` -
-