diff options
author | 杨宇千 <crupest@outlook.com> | 2019-03-14 16:51:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 16:51:46 +0800 |
commit | c65db42c9ce3532509bbd0b4abfc500692cfe4d3 (patch) | |
tree | 9e6a91af019e14fa3fb40e03bf84507a98a33d4c /Timeline/ClientApp/src/app/user/user.service.ts | |
parent | 4535d1fd30eb02b3fe60718235a0725e3b30049e (diff) | |
parent | 7b929db4fcfa34acc82885b75a573e6e4bd40465 (diff) | |
download | timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.tar.gz timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.tar.bz2 timeline-c65db42c9ce3532509bbd0b4abfc500692cfe4d3.zip |
Merge pull request #13 from crupest/auth-guard
Add auth guard.
Diffstat (limited to 'Timeline/ClientApp/src/app/user/user.service.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/user/user.service.ts | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/Timeline/ClientApp/src/app/user/user.service.ts b/Timeline/ClientApp/src/app/user/user.service.ts index e876706c..e7d50dd2 100644 --- a/Timeline/ClientApp/src/app/user/user.service.ts +++ b/Timeline/ClientApp/src/app/user/user.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; -import { MatDialog } from '@angular/material'; +import { MatDialog, MatDialogRef } from '@angular/material'; +import { Router, ActivationStart } from '@angular/router'; import { Observable } from 'rxjs'; @@ -15,7 +16,18 @@ import { UserDialogComponent } from './user-dialog/user-dialog.component'; providedIn: 'root' }) export class UserService { - constructor(private dialog: MatDialog, private internalService: InternalUserService) { } + + private dialogRef: MatDialogRef<UserDialogComponent> | null = null; + + constructor(router: Router, private dialog: MatDialog, private internalService: InternalUserService) { + router.events.subscribe(event => { + if (event instanceof ActivationStart && event.snapshot.outlet === 'user') { + if (!this.dialogRef) { + setTimeout(() => this.openUserDialog(), 0); + } + } + }); + } get currentUserInfo(): UserInfo | null { return this.internalService.currentUserInfo; @@ -25,9 +37,19 @@ export class UserService { return this.internalService.userInfo$; } - openUserDialog() { - this.dialog.open(UserDialogComponent, { + private openUserDialog() { + if (this.dialogRef) { + return; + } + + this.dialogRef = this.dialog.open(UserDialogComponent, { width: '300px' }); + + const subscription = this.dialogRef.afterClosed().subscribe(_ => { + this.internalService.userRouteNavigate(null); + this.dialogRef = null; + subscription.unsubscribe(); + }); } } |