]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.component.ts
Client: Redirect user to home page after logout
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
CommitLineData
230809ef 1import { Component } from '@angular/core';
bddab65a 2import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
dc8bc31b 3
4a6995be 4import { FriendService } from './friends';
41a2aee3 5import {
41a2aee3 6 AuthService,
a840d396 7 AuthStatus,
0629423c
C
8 SearchComponent,
9 SearchService
4a6995be 10} from './shared';
0629423c 11import { VideoService } from './videos';
dc8bc31b
C
12
13@Component({
14 selector: 'my-app',
4a6995be
C
15 template: require('./app.component.html'),
16 styles: [ require('./app.component.scss') ],
471bc22f 17 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
bd5c83a8 18 providers: [ FriendService, VideoService, SearchService ]
dc8bc31b
C
19})
20
21export class AppComponent {
ccf6ed16 22 choices = [];
4fd8aa32 23 isLoggedIn: boolean;
a99593ed 24
4fd8aa32
C
25 constructor(
26 private authService: AuthService,
27 private friendService: FriendService,
bddab65a 28 private route: ActivatedRoute,
4fd8aa32 29 private router: Router
b1794c53 30 ) {
ccf6ed16 31 this.isLoggedIn = this.authService.isLoggedIn();
b1794c53 32
ccf6ed16 33 this.authService.loginChangedSource.subscribe(
b1794c53
C
34 status => {
35 if (status === AuthStatus.LoggedIn) {
36 this.isLoggedIn = true;
bd5c83a8
C
37 console.log('Logged in.');
38 } else if (status === AuthStatus.LoggedOut) {
39 this.isLoggedIn = false;
40 console.log('Logged out.');
41 } else {
42 console.error('Unknown auth status: ' + status);
b1794c53
C
43 }
44 }
45 );
46 }
98b01bac 47
b1794c53 48 logout() {
bd5c83a8 49 this.authService.logout();
66af9ee1
C
50 // Redirect to home page
51 this.router.navigate(['/videos/list']);
b1794c53
C
52 }
53
dc8bc31b 54 makeFriends() {
ccf6ed16 55 this.friendService.makeFriends().subscribe(
dc8bc31b
C
56 status => {
57 if (status === 409) {
58 alert('Already made friends!');
98b01bac 59 } else {
dc8bc31b
C
60 alert('Made friends!');
61 }
62 },
63 error => alert(error)
44124980 64 );
dc8bc31b
C
65 }
66
67 quitFriends() {
ccf6ed16 68 this.friendService.quitFriends().subscribe(
dc8bc31b 69 status => {
4fd8aa32 70 alert('Quit friends!');
dc8bc31b
C
71 },
72 error => alert(error)
44124980 73 );
dc8bc31b
C
74 }
75}