-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.component.ts
89 lines (79 loc) · 2.17 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { UserService } from './service/user.service';
import { ApolloService } from './service/apollo.service';
import { AuthGuardService } from './service/auth-guard.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
isLogin = false;
userInfo = {avatarUrl: '', login: ""};
currentRouter = '';
isShowMenuList = false;
routes = [
{path: '/profile', name: 'Profile', icon: 'profile'},
{path: '/repository', name: 'Repository', icon: 'home'},
{path: '/search', name: 'Search', icon: 'search'},
];
constructor(private apolloService: ApolloService,
private userService: UserService,
private router: Router,
private authGuardService: AuthGuardService
) {
}
ngOnInit() {
document.body.addEventListener('touchstart', function () { });
const url = window.location.search;
if (url.indexOf('code') > 0 && url.indexOf('state') > 0) {
this.userService.getAccessToken(url);
this.router.navigate(['/'], {replaceUrl: true});
}
this.checkLogin();
this.authGuardService.currentPathSubject().subscribe((value: string) => {
this.currentRouter = value;
})
}
checkLogin() {
this.userService.isLoginSubject().subscribe((value: boolean) => {
this.isLogin = value;
if (value) {
this.getUserInfo();
}
});
}
async getUserInfo() {
const userInfo = await this.apolloService.queryUser();
if (userInfo) {
this.userInfo = userInfo;
}
}
loginOrOut() {
if (this.isLogin) {
this.userService.logout();
this.isLogin = false;
} else {
this.userService.authorizeGithub();
}
}
login() {
if (!this.isLogin) {
this.userService.authorizeGithub();
}
}
logOut(){
if (this.isLogin) {
this.userService.logout();
this.isLogin = false;
this.userInfo = {avatarUrl: '', login: ""};
}
}
showMenuList() {
this.isShowMenuList = !this.isShowMenuList;
}
routeClick() {
this.isShowMenuList = false;
}
}