1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { Notifier, ServerService, User, UserService } from '@app/core'
3 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
7 selector: 'my-account-setup-warning-modal',
8 templateUrl: './account-setup-warning-modal.component.html',
9 styleUrls: [ './account-setup-warning-modal.component.scss' ]
11 export class AccountSetupWarningModalComponent {
12 @ViewChild('modal', { static: true }) modal: ElementRef
14 stopDisplayModal = false
19 private LOCAL_STORAGE_KEYS = {
20 NO_ACCOUNT_SETUP_WARNING_MODAL: 'no_account_setup_warning_modal'
24 private userService: UserService,
25 private modalService: NgbModal,
26 private notifier: Notifier,
27 private serverService: ServerService
31 return this.serverService.getHTMLConfig().instance.name
34 hasAccountAvatar (user: User) {
35 return user.account.avatars.length !== 0
38 hasAccountDescription (user: User) {
39 return !!user.account.description
42 shouldOpen (user: User) {
43 if (user.noAccountSetupWarningModal === true) return false
44 if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL) === 'true') return false
46 if (this.hasAccountAvatar(user) && this.hasAccountDescription(user)) return false
47 if (this.userService.hasSignupInThisSession()) return false
57 this.ref = this.modalService.open(this.modal, {
64 this.ref.result.finally(() => {
65 if (this.stopDisplayModal === true) this.doNotOpenAgain()
69 private doNotOpenAgain () {
70 peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL, 'true')
72 this.userService.updateMyProfile({ noAccountSetupWarningModal: true })
74 next: () => console.log('We will not open the account setup modal again.'),
76 error: err => this.notifier.error(err.message)