diff --git a/webapp/src/app/app.component.ts b/webapp/src/app/app.component.ts index 22ec3d1..c292506 100644 --- a/webapp/src/app/app.component.ts +++ b/webapp/src/app/app.component.ts @@ -1,6 +1,7 @@ -import { Component } from '@angular/core'; +import { Component, OnInit, inject } from '@angular/core'; import { NavbarComponent } from './components/navbar/navbar.component'; -import { RouterOutlet } from '@angular/router'; +import { RouterOutlet, ActivatedRoute } from '@angular/router'; +import { PubsubService } from './services/pubsub.service'; @Component({ selector: 'app-root', @@ -9,6 +10,17 @@ import { RouterOutlet } from '@angular/router'; standalone: true, imports: [NavbarComponent, RouterOutlet] }) -export class AppComponent { +export class AppComponent implements OnInit { title = 'webapp'; + private route = inject(ActivatedRoute); + private pubsub = inject(PubsubService); + + ngOnInit(): void { + this.route.queryParamMap.subscribe(params => { + const host = params.get('host'); + if (host) { + this.pubsub.setHost(host); + } + }); + } } diff --git a/webapp/src/app/components/navbar/navbar.component.ts b/webapp/src/app/components/navbar/navbar.component.ts index 5241552..0b6a624 100644 --- a/webapp/src/app/components/navbar/navbar.component.ts +++ b/webapp/src/app/components/navbar/navbar.component.ts @@ -5,7 +5,7 @@ import { PubsubService } from 'src/app/services/pubsub.service'; import { InputDialogComponent } from '../input-dialog/input-dialog.component'; import { MatToolbar } from '@angular/material/toolbar'; import { MatIconButton } from '@angular/material/button'; -import { RouterLink } from '@angular/router'; +import { RouterLink, Router } from '@angular/router'; import { MatIcon } from '@angular/material/icon'; import { AsyncPipe } from '@angular/common'; @@ -19,6 +19,7 @@ import { AsyncPipe } from '@angular/common'; export class NavbarComponent implements OnInit { private pubsub = inject(PubsubService); private dialog = inject(MatDialog); + private router = inject(Router); currentHost: Observable @@ -36,6 +37,11 @@ export class NavbarComponent implements OnInit { ref.afterClosed().pipe(filter(result => !!result)) .subscribe((result: { user_input: string }) => { this.pubsub.setHost(result.user_input) + + this.router.navigate([], { + queryParams: { host: result.user_input }, + queryParamsHandling: 'merge' + }); }) }