]>
Commit | Line | Data |
---|---|---|
230809ef | 1 | import { Component } from '@angular/core'; |
bddab65a | 2 | import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; |
dc8bc31b | 3 | |
4a6995be | 4 | import { FriendService } from './friends'; |
41a2aee3 | 5 | import { |
41a2aee3 | 6 | AuthService, |
a840d396 | 7 | AuthStatus, |
0629423c C |
8 | SearchComponent, |
9 | SearchService | |
4a6995be | 10 | } from './shared'; |
0629423c | 11 | import { 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 | ||
21 | export 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 | |
7da18e44 C |
48 | isUserAdmin() { |
49 | return this.authService.isAdmin(); | |
50 | } | |
51 | ||
b1794c53 | 52 | logout() { |
bd5c83a8 | 53 | this.authService.logout(); |
66af9ee1 C |
54 | // Redirect to home page |
55 | this.router.navigate(['/videos/list']); | |
b1794c53 C |
56 | } |
57 | ||
dc8bc31b | 58 | makeFriends() { |
ccf6ed16 | 59 | this.friendService.makeFriends().subscribe( |
dc8bc31b C |
60 | status => { |
61 | if (status === 409) { | |
62 | alert('Already made friends!'); | |
98b01bac | 63 | } else { |
dc8bc31b C |
64 | alert('Made friends!'); |
65 | } | |
66 | }, | |
67 | error => alert(error) | |
44124980 | 68 | ); |
dc8bc31b C |
69 | } |
70 | ||
71 | quitFriends() { | |
ccf6ed16 | 72 | this.friendService.quitFriends().subscribe( |
dc8bc31b | 73 | status => { |
4fd8aa32 | 74 | alert('Quit friends!'); |
dc8bc31b C |
75 | }, |
76 | error => alert(error) | |
44124980 | 77 | ); |
dc8bc31b C |
78 | } |
79 | } |