]>
Commit | Line | Data |
---|---|---|
1 | import { Component } from '@angular/core'; | |
2 | import { HTTP_PROVIDERS } from '@angular/http'; | |
3 | import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; | |
4 | ||
5 | import { FriendService } from './friends'; | |
6 | import { | |
7 | AuthService, | |
8 | AuthStatus, | |
9 | SearchComponent, | |
10 | SearchService | |
11 | } from './shared'; | |
12 | import { VideoService } from './videos'; | |
13 | ||
14 | @Component({ | |
15 | selector: 'my-app', | |
16 | template: require('./app.component.html'), | |
17 | styles: [ require('./app.component.scss') ], | |
18 | directives: [ ROUTER_DIRECTIVES, SearchComponent ], | |
19 | providers: [ AuthService, FriendService, HTTP_PROVIDERS, VideoService, SearchService ] | |
20 | }) | |
21 | ||
22 | export class AppComponent { | |
23 | choices = []; | |
24 | isLoggedIn: boolean; | |
25 | ||
26 | constructor( | |
27 | private authService: AuthService, | |
28 | private friendService: FriendService, | |
29 | private route: ActivatedRoute, | |
30 | private router: Router | |
31 | ) { | |
32 | this.isLoggedIn = this.authService.isLoggedIn(); | |
33 | ||
34 | this.authService.loginChangedSource.subscribe( | |
35 | status => { | |
36 | if (status === AuthStatus.LoggedIn) { | |
37 | this.isLoggedIn = true; | |
38 | } | |
39 | } | |
40 | ); | |
41 | } | |
42 | ||
43 | // FIXME | |
44 | logout() { | |
45 | // this._authService.logout(); | |
46 | } | |
47 | ||
48 | makeFriends() { | |
49 | this.friendService.makeFriends().subscribe( | |
50 | status => { | |
51 | if (status === 409) { | |
52 | alert('Already made friends!'); | |
53 | } else { | |
54 | alert('Made friends!'); | |
55 | } | |
56 | }, | |
57 | error => alert(error) | |
58 | ); | |
59 | } | |
60 | ||
61 | quitFriends() { | |
62 | this.friendService.quitFriends().subscribe( | |
63 | status => { | |
64 | alert('Quit friends!'); | |
65 | }, | |
66 | error => alert(error) | |
67 | ); | |
68 | } | |
69 | } |