]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/modal/account-setup-modal.component.ts
Avoid layout shift in account setup modal
[github/Chocobozzz/PeerTube.git] / client / src / app / modal / account-setup-modal.component.ts
CommitLineData
7dca45f9 1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
bf80903f 2import { AuthService, ServerService, User, UserService } from '@app/core'
7dca45f9
MK
3import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4import { HTMLServerConfig } from '@shared/models'
5
6@Component({
7 selector: 'my-account-setup-modal',
8 templateUrl: './account-setup-modal.component.html',
9 styleUrls: [ './account-setup-modal.component.scss' ]
10})
11export class AccountSetupModalComponent implements OnInit {
12 @ViewChild('modal', { static: true }) modal: ElementRef
13
14 user: User = null
15 ref: NgbModalRef = null
16
17 private serverConfig: HTMLServerConfig
18
19 constructor (
bf80903f 20 private userService: UserService,
7dca45f9
MK
21 private authService: AuthService,
22 private modalService: NgbModal,
23 private serverService: ServerService
24 ) { }
25
26 get userInformationLoaded () {
27 return this.authService.userInformationLoaded
28 }
29
30 get instanceName () {
31 return this.serverConfig.instance.name
32 }
33
34 get isUserRoot () {
35 return this.user.username === 'root'
36 }
37
38 get hasAccountAvatar () {
39 return !!this.user.account.avatar
40 }
41
42 get hasAccountDescription () {
43 return !!this.user.account.description
44 }
45
46 ngOnInit () {
47 this.serverConfig = this.serverService.getHTMLConfig()
7dca45f9
MK
48
49 this.authService.userInformationLoaded
50 .subscribe(
51 () => {
1ff15061
C
52 this.user = this.authService.getUser()
53
bf80903f
C
54 if (this.isUserRoot) return
55 if (this.hasAccountAvatar && this.hasAccountDescription) return
56 if (this.userService.hasSignupInThisSession()) return
7dca45f9
MK
57
58 this.show()
59 }
60 )
61 }
62
63 show () {
bf80903f 64 if (this.ref) return
7dca45f9
MK
65
66 this.ref = this.modalService.open(this.modal, {
67 centered: true,
68 backdrop: 'static',
69 keyboard: false,
70 size: 'md'
71 })
72 }
73}