]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/menu.component.ts
Client: try to improve ux for the upload form
[github/Chocobozzz/PeerTube.git] / client / src / app / menu.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3
4 import { AuthService } from './core';
5 import { AuthStatus } from './shared';
6
7 @Component({
8 selector: 'my-menu',
9 templateUrl: './menu.component.html'
10 })
11 export class MenuComponent implements OnInit {
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
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 }