aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-dialog/user-dialog.component.ts
blob: cf5f36434692e1ea829432eb5e8e01f00b58f1bf (plain)
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
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, OnDestroy {

  constructor(private userService: InternalUserService, private router: Router) { }

  @ViewChild(RouterOutlet) outlet!: RouterOutlet;

  isLoading = true;

  ngOnInit() {
    // this is a workaround for a bug. see https://github.com/angular/angular/issues/20694
    const subscription = this.router.events.subscribe(e => {
      if (e instanceof ActivationStart && e.snapshot.outlet === 'user') {
        this.outlet.deactivate();
        subscription.unsubscribe();
      }
    });


    this.userService.refreshAndGetUserState().subscribe(result => {
      this.isLoading = false;
      if (result === 'success') {
        this.userService.userRouteNavigate(['success', { reason: 'already' }]);
      } else {
        this.userService.userRouteNavigate(['login', { reason: result }]);
      }
    });
  }

  ngOnDestroy() {
    this.userService.userRouteNavigate(null);
  }
}