aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-03-11 19:52:29 +0800
committerGitHub <noreply@github.com>2019-03-11 19:52:29 +0800
commit8caef17dd3e455de27f44d13751c27ee4dfe2e1e (patch)
tree5b485ad438c9be9c180d425453588ff1c575a42d /Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts
parent17d90077b289c6b2203a34de727dd77c1985f146 (diff)
parentb26342764046d188d223aa494c3bbbf76deb4927 (diff)
downloadtimeline-8caef17dd3e455de27f44d13751c27ee4dfe2e1e.tar.gz
timeline-8caef17dd3e455de27f44d13751c27ee4dfe2e1e.tar.bz2
timeline-8caef17dd3e455de27f44d13751c27ee4dfe2e1e.zip
Merge pull request #11 from crupest/7-user-route
Use named route in user 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.ts47
1 files changed, 22 insertions, 25 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..498ffaa1 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 { UserService } from '../user-service/user.service';
-import { LoginEvent, LoginMessage } from '../user-login/user-login.component';
+import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
+import { InternalUserService } from '../internal-user-service/internal-user.service';
+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: InternalUserService, private router: Router) { }
- state: 'loading' | 'login' | 'success' = 'loading';
+ @ViewChild(RouterOutlet) outlet: RouterOutlet;
- loginMessage: LoginMessage;
-
- displayLoginSuccessMessage = false;
- userInfo: UserInfo;
+ isLoading = true;
ngOnInit() {
- this.userService.validateUserLoginState().subscribe(result => {
- if (result.state === 'success') {
- this.userInfo = result.userInfo;
- this.state = 'success';
+ // 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.refreshAndGetUserState().subscribe(result => {
+ this.isLoading = false;
+ if (result === 'success') {
+ this.userService.userRouteNavigate(['success', { reason: 'already' }]);
} else {
- this.loginMessage = result.state;
- this.state = 'login';
+ this.userService.userRouteNavigate(['login', { reason: result }]);
}
});
}
- 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);
}
}