diff options
author | crupest <crupest@outlook.com> | 2019-03-09 01:42:38 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-09 01:42:38 +0800 |
commit | d6e7d702db4e600d2298376ba9310e985ee69079 (patch) | |
tree | b8248d41f5bfccc82c5c110143c5504decf3e16d /Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts | |
parent | 028af6f786ac2664d301614d57bbff053c3dc9c0 (diff) | |
download | timeline-d6e7d702db4e600d2298376ba9310e985ee69079.tar.gz timeline-d6e7d702db4e600d2298376ba9310e985ee69079.tar.bz2 timeline-d6e7d702db4e600d2298376ba9310e985ee69079.zip |
User named route in dialog.
Diffstat (limited to 'Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts index 7511de16..0edde924 100644 --- a/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts +++ b/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts @@ -1,43 +1,40 @@ -import { Component, OnInit } from '@angular/core'; -import { UserInfo } from '../user-info'; +import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { UserService } from '../user-service/user.service'; -import { LoginEvent, LoginMessage } from '../user-login/user-login.component'; +import { RouterOutlet, Router, ActivationStart } from '@angular/router'; @Component({ selector: 'app-user-dialog', templateUrl: './user-dialog.component.html', styleUrls: ['./user-dialog.component.css'] }) -export class UserDialogComponent implements OnInit { +export class UserDialogComponent implements OnInit, OnDestroy { - constructor(private userService: UserService) { } + constructor(private userService: UserService, private router: Router) { } - state: 'loading' | 'login' | 'success' = 'loading'; + @ViewChild(RouterOutlet) outlet: RouterOutlet; - loginMessage: LoginMessage; - - displayLoginSuccessMessage = false; - userInfo: UserInfo; + isLoading = true; ngOnInit() { + // this is a workaround for a bug. see https://github.com/angular/angular/issues/20694 + this.router.events.subscribe(e => { + if (e instanceof ActivationStart && e.snapshot.outlet === 'user') { + this.outlet.deactivate(); + } + }); + + this.userService.validateUserLoginState().subscribe(result => { + this.isLoading = false; if (result.state === 'success') { - this.userInfo = result.userInfo; - this.state = 'success'; + this.userService.userRouteNavigate(['success', { reason: 'already' }]); } else { - this.loginMessage = result.state; - this.state = 'login'; + this.userService.userRouteNavigate(['login', { reason: result.state }]); } }); } - login(event: LoginEvent) { - this.userService.tryLogin(event.username, event.password).subscribe(result => { - this.userInfo = result; - this.displayLoginSuccessMessage = true; - this.state = 'success'; - }, (error: Error) => { - this.loginMessage = error.message; - }); + ngOnDestroy() { + this.userService.userRouteNavigate(null); } } |