]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/menu.component.ts
Client: split in angular modules
[github/Chocobozzz/PeerTube.git] / client / src / app / menu.component.ts
CommitLineData
beacf699 1import { Component, OnInit } from '@angular/core';
ab32b0fc 2import { Router } from '@angular/router';
602eb142 3
693b1aba
C
4import { AuthService } from './core';
5import { AuthStatus } from './shared';
602eb142
C
6
7@Component({
8 selector: 'my-menu',
ec8d8440 9 templateUrl: './menu.component.html'
602eb142
C
10})
11export class MenuComponent implements OnInit {
602eb142
C
12 isLoggedIn: boolean;
13
14 constructor (
15 private authService: AuthService,
16 private router: Router
17 ) {}
18
19 ngOnInit() {
20 this.isLoggedIn = this.authService.isLoggedIn();
21
22 this.authService.loginChangedSource.subscribe(
23 status => {
24 if (status === AuthStatus.LoggedIn) {
25 this.isLoggedIn = true;
26 console.log('Logged in.');
27 } else if (status === AuthStatus.LoggedOut) {
28 this.isLoggedIn = false;
29 console.log('Logged out.');
30 } else {
31 console.error('Unknown auth status: ' + status);
32 }
33 }
34 );
35 }
36
602eb142
C
37 isUserAdmin() {
38 return this.authService.isAdmin();
39 }
40
41 logout() {
42 this.authService.logout();
43 // Redirect to home page
44 this.router.navigate(['/videos/list']);
45 }
46}