generated from PackagrIO/goweb-template
-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renamed sse endpoint to events. Using the technology name in the API …
…isnt a good idea.
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import {Component, OnInit, TemplateRef} from '@angular/core'; | ||
import {ToastService} from '../../services/toast.service'; | ||
import {AuthService} from '../../services/auth.service'; | ||
import {FastenApiService} from '../../services/fasten-api.service'; | ||
import {Subscription} from 'rxjs'; | ||
import {NavigationEnd, Router} from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-toast', | ||
templateUrl: './toast.component.html', | ||
styleUrls: ['./toast.component.scss'] | ||
}) | ||
export class ToastComponent implements OnInit { | ||
routerSubscription: Subscription | undefined; | ||
|
||
constructor(public toastService: ToastService) {} | ||
constructor( | ||
public router: Router, | ||
public toastService: ToastService, | ||
public authService: AuthService, | ||
public fastenApiService: FastenApiService, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
|
||
} | ||
ngAfterViewInit() { | ||
//TODO: this is a bit kludgey. | ||
// Ideally we want consistently listen to events, but only when the user is authenticated. | ||
this.routerSubscription = this.router.events.subscribe((event) => { | ||
if (event instanceof NavigationEnd) { | ||
if(!event.url.startsWith("/auth") && this.authService.IsAuthenticated()){ | ||
console.log("user is authenticated, listening for notifications") | ||
//user is authenticated, lets start listening for notifications | ||
this.routerSubscription?.unsubscribe() | ||
this.fastenApiService.listenEventBus().subscribe((event)=>{ | ||
console.log("eventbus event:", event) | ||
//TODO: start toasts. | ||
}) | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters