Refactored title service
All checks were successful
Gitea/swiss-client/pipeline/head This commit looks good
All checks were successful
Gitea/swiss-client/pipeline/head This commit looks good
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||
import {ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||
import {CommonModule, NgOptimizedImage} from "@angular/common";
|
||||
import {MatAnchor, MatButton} from "@angular/material/button";
|
||||
import {MatIcon} from "@angular/material/icon";
|
||||
import {MatToolbar} from "@angular/material/toolbar";
|
||||
import {TitleService} from "./service/title.service";
|
||||
import {Subscription} from "rxjs";
|
||||
import {filter, map, Subscription} from "rxjs";
|
||||
import {MatMenu, MatMenuItem, MatMenuTrigger} from "@angular/material/menu";
|
||||
import {UserService} from "./authentication/user.service";
|
||||
import {TournamentService} from "./service/tournament.service";
|
||||
import {HeaderService} from "./service/header.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
imports: [RouterOutlet, CommonModule, RouterLink, MatAnchor, MatIcon, MatButton, MatToolbar, NgOptimizedImage, MatMenuTrigger, MatMenu, MatMenuItem],
|
||||
providers: [TitleService],
|
||||
imports: [RouterOutlet, CommonModule, RouterLink, MatAnchor, MatIcon, MatButton, MatToolbar, NgOptimizedImage, MatMenuTrigger, MatMenu, MatMenuItem],
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.scss'
|
||||
})
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
export class AppComponent implements OnInit {
|
||||
|
||||
title: string;
|
||||
titleSubscription: Subscription;
|
||||
header: string;
|
||||
user: string;
|
||||
userSubscription: Subscription;
|
||||
|
||||
@@ -28,18 +26,32 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
protected userService: UserService,
|
||||
private router: Router,
|
||||
protected activatedRoute: ActivatedRoute,
|
||||
private titleService: TitleService,
|
||||
private tournamentService: TournamentService
|
||||
private tournamentService: TournamentService,
|
||||
private headerService: HeaderService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleSubscription = this.titleService.currentTitle.subscribe(newTitle => this.title = newTitle);
|
||||
this.userSubscription = this.userService.currentUser.subscribe(newUser => this.user = newUser);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.titleSubscription.unsubscribe();
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
map(() => {
|
||||
let currentRoute = this.activatedRoute;
|
||||
while (currentRoute.firstChild) {
|
||||
currentRoute = currentRoute.firstChild;
|
||||
}
|
||||
return currentRoute.snapshot.data['header'] || '';
|
||||
})
|
||||
).subscribe(header => {
|
||||
this.header = header;
|
||||
});
|
||||
|
||||
this.headerService.header$.subscribe(override => {
|
||||
if (override) {
|
||||
this.header = override;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logOut() {
|
||||
|
||||
Reference in New Issue
Block a user