Przeglądaj źródła

fix(admin-ui): Correctly init channel switcher

Michael Bromley 2 lat temu
rodzic
commit
7e5e5d5db5
1 zmienionych plików z 13 dodań i 6 usunięć
  1. 13 6
      packages/admin-ui/src/lib/core/src/app.component.ts

+ 13 - 6
packages/admin-ui/src/lib/core/src/app.component.ts

@@ -63,18 +63,25 @@ export class AppComponent implements OnInit {
                 },
             });
 
-        this.dataService.client
-            .userStatus()
-            .mapStream(({ userStatus }) => userStatus.administratorId)
-            .subscribe(administratorId => {
-                this.localStorageService.setAdminId(administratorId);
+        this.dataService.client.userStatus().stream$.subscribe(({ userStatus }) => {
+            this.localStorageService.setAdminId(userStatus.administratorId);
+
+            if (userStatus.administratorId) {
                 const theme = this.localStorageService.get('activeTheme');
                 if (theme) {
                     this.dataService.client.setUiTheme(theme).subscribe(() => {
                         this.localStorageService.set('activeTheme', theme);
                     });
                 }
-            });
+                const activeChannelToken = this.localStorageService.get('activeChannelToken');
+                if (activeChannelToken) {
+                    const activeChannel = userStatus.channels.find(c => c.token === activeChannelToken);
+                    if (activeChannel) {
+                        this.dataService.client.setActiveChannel(activeChannel.id).subscribe();
+                    }
+                }
+            }
+        });
 
         if (isDevMode()) {
             // eslint-disable-next-line no-console