aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-09 01:42:38 +0800
committercrupest <crupest@outlook.com>2019-03-09 01:42:38 +0800
commitb01ba534a0017ad8bf85ddecff7610a6de6a74e9 (patch)
tree282b8feda6ac6dfd5213f4fe67766401d72472c3 /Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts
parent17d90077b289c6b2203a34de727dd77c1985f146 (diff)
downloadtimeline-b01ba534a0017ad8bf85ddecff7610a6de6a74e9.tar.gz
timeline-b01ba534a0017ad8bf85ddecff7610a6de6a74e9.tar.bz2
timeline-b01ba534a0017ad8bf85ddecff7610a6de6a74e9.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.ts41
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);
}
}