aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/modal/account-setup-modal.component.ts
blob: 4cb8de2c778dc53db1f5bdf1b415b5483f4f1b43 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { AuthService, ServerService, User, UserService } from '@app/core'
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { HTMLServerConfig } from '@shared/models'

@Component({
  selector: 'my-account-setup-modal',
  templateUrl: './account-setup-modal.component.html',
  styleUrls: [ './account-setup-modal.component.scss' ]
})
export class AccountSetupModalComponent implements OnInit {
  @ViewChild('modal', { static: true }) modal: ElementRef

  user: User = null
  ref: NgbModalRef = null

  private serverConfig: HTMLServerConfig

  constructor (
    private userService: UserService,
    private authService: AuthService,
    private modalService: NgbModal,
    private serverService: ServerService
  ) { }

  get userInformationLoaded () {
    return this.authService.userInformationLoaded
  }

  get instanceName () {
    return this.serverConfig.instance.name
  }

  get isUserRoot () {
    return this.user.username === 'root'
  }

  get hasAccountAvatar () {
    return !!this.user.account.avatar
  }

  get hasAccountDescription () {
    return !!this.user.account.description
  }

  ngOnInit () {
    this.serverConfig = this.serverService.getHTMLConfig()

    this.authService.userInformationLoaded
      .subscribe(
        () => {
          this.user = this.authService.getUser()

          if (this.isUserRoot) return
          if (this.hasAccountAvatar && this.hasAccountDescription) return
          if (this.userService.hasSignupInThisSession()) return

          this.show()
        }
      )
  }

  show () {
    if (this.ref) return

    this.ref = this.modalService.open(this.modal, {
      centered: true,
      backdrop: 'static',
      keyboard: false,
      size: 'md'
    })
  }
}