2016-05-13 07:18:37 -05:00
|
|
|
import { Component } from '@angular/core';
|
2016-07-18 08:39:10 -05:00
|
|
|
import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
|
2016-03-14 07:50:19 -05:00
|
|
|
|
2016-06-03 15:08:03 -05:00
|
|
|
import { FriendService } from './friends';
|
2016-05-27 09:23:10 -05:00
|
|
|
import {
|
|
|
|
AuthService,
|
2016-06-01 13:36:27 -05:00
|
|
|
AuthStatus,
|
2016-07-08 10:15:14 -05:00
|
|
|
SearchComponent,
|
|
|
|
SearchService
|
2016-06-03 15:08:03 -05:00
|
|
|
} from './shared';
|
2016-07-08 10:15:14 -05:00
|
|
|
import { VideoService } from './videos';
|
2016-03-14 07:50:19 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-app',
|
2016-06-03 15:08:03 -05:00
|
|
|
template: require('./app.component.html'),
|
|
|
|
styles: [ require('./app.component.scss') ],
|
2016-05-23 02:30:18 -05:00
|
|
|
directives: [ ROUTER_DIRECTIVES, SearchComponent ],
|
2016-07-20 09:24:18 -05:00
|
|
|
providers: [ FriendService, VideoService, SearchService ]
|
2016-03-14 07:50:19 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
export class AppComponent {
|
2016-05-27 10:25:52 -05:00
|
|
|
choices = [];
|
2016-05-27 10:49:18 -05:00
|
|
|
isLoggedIn: boolean;
|
2016-05-24 16:00:58 -05:00
|
|
|
|
2016-05-27 10:49:18 -05:00
|
|
|
constructor(
|
|
|
|
private authService: AuthService,
|
|
|
|
private friendService: FriendService,
|
2016-07-18 08:39:10 -05:00
|
|
|
private route: ActivatedRoute,
|
2016-05-27 10:49:18 -05:00
|
|
|
private router: Router
|
2016-03-22 09:51:54 -05:00
|
|
|
) {
|
2016-05-27 10:25:52 -05:00
|
|
|
this.isLoggedIn = this.authService.isLoggedIn();
|
2016-03-22 09:51:54 -05:00
|
|
|
|
2016-05-27 10:25:52 -05:00
|
|
|
this.authService.loginChangedSource.subscribe(
|
2016-03-22 09:51:54 -05:00
|
|
|
status => {
|
|
|
|
if (status === AuthStatus.LoggedIn) {
|
|
|
|
this.isLoggedIn = true;
|
2016-07-20 09:24:18 -05:00
|
|
|
console.log('Logged in.');
|
|
|
|
} else if (status === AuthStatus.LoggedOut) {
|
|
|
|
this.isLoggedIn = false;
|
|
|
|
console.log('Logged out.');
|
|
|
|
} else {
|
|
|
|
console.error('Unknown auth status: ' + status);
|
2016-03-22 09:51:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-03-14 16:16:43 -05:00
|
|
|
|
2016-03-22 09:51:54 -05:00
|
|
|
logout() {
|
2016-07-20 09:24:18 -05:00
|
|
|
this.authService.logout();
|
2016-03-22 09:51:54 -05:00
|
|
|
}
|
|
|
|
|
2016-03-14 07:50:19 -05:00
|
|
|
makeFriends() {
|
2016-05-27 10:25:52 -05:00
|
|
|
this.friendService.makeFriends().subscribe(
|
2016-03-14 07:50:19 -05:00
|
|
|
status => {
|
|
|
|
if (status === 409) {
|
|
|
|
alert('Already made friends!');
|
2016-03-14 16:16:43 -05:00
|
|
|
} else {
|
2016-03-14 07:50:19 -05:00
|
|
|
alert('Made friends!');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error => alert(error)
|
2016-04-08 13:58:07 -05:00
|
|
|
);
|
2016-03-14 07:50:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
quitFriends() {
|
2016-05-27 10:25:52 -05:00
|
|
|
this.friendService.quitFriends().subscribe(
|
2016-03-14 07:50:19 -05:00
|
|
|
status => {
|
2016-05-27 10:49:18 -05:00
|
|
|
alert('Quit friends!');
|
2016-03-14 07:50:19 -05:00
|
|
|
},
|
|
|
|
error => alert(error)
|
2016-04-08 13:58:07 -05:00
|
|
|
);
|
2016-03-14 07:50:19 -05:00
|
|
|
}
|
|
|
|
}
|