From c45358c0568bf475872d74103a62affff7bf0c28 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 14 Sep 2021 17:45:56 +0200
Subject: [PATCH] Listen to a dbp-show-activity event for switching activities

In case the activity emits this event then we switch to the specified activity.
---
 packages/app-shell/src/app-shell.js | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js
index fd60dd70..dca5dc2d 100644
--- a/packages/app-shell/src/app-shell.js
+++ b/packages/app-shell/src/app-shell.js
@@ -66,6 +66,7 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
         this.matomoSiteId = -1;
 
         this._attrObserver = new MutationObserver(this.onAttributeObserved);
+        this._onShowActivityEvent = this._onShowActivityEvent.bind(this);
 
         this.auth = {};
     }
@@ -761,6 +762,10 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
         return elm;
     }
 
+    _onShowActivityEvent(e) {
+        this.switchComponent(e.detail.name);
+    }
+
     _onActivityAdded(element) {
         for(const key of this.topic.attributes || []) {
             let value = sessionStorage.getItem('dbp-attr-' + key);
@@ -769,10 +774,12 @@ export class AppShell extends ScopedElementsMixin(DBPLitElement) {
             }
         }
         this._attrObserver.observe(element, {attributes: true, attributeFilter: this.topic.attributes});
+        element.addEventListener('dbp-show-activity', this._onShowActivityEvent);
     }
 
     _onActivityRemoved(element) {
         this._attrObserver.disconnect();
+        element.removeEventListener('dbp-show-activity', this._onShowActivityEvent);
     }
 
     track(action, message) {
-- 
GitLab