aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/modal/admin-welcome-modal.component.ts
blob: 7a9b89d3d0044ced06dbb3c7c940f5c9d27866c2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                                                
                                                       
                                                     
                                             
                                                                         

            


                                                       
  
                                         

                                                         



                                        





                                     





                                                                                                       
 
           

                                        



                         

   
                     

                                                                                  
                                                              
                  
                                                                             
 

                                                      

   
import { Component, ElementRef, ViewChild } from '@angular/core'
import { Notifier, User, UserService } from '@app/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { logger } from '@root-helpers/logger'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'

@Component({
  selector: 'my-admin-welcome-modal',
  templateUrl: './admin-welcome-modal.component.html',
  styleUrls: [ './admin-welcome-modal.component.scss' ]
})
export class AdminWelcomeModalComponent {
  @ViewChild('modal', { static: true }) modal: ElementRef

  private LOCAL_STORAGE_KEYS = {
    NO_WELCOME_MODAL: 'no_welcome_modal'
  }

  constructor (
    private userService: UserService,
    private modalService: NgbModal,
    private notifier: Notifier
  ) { }

  shouldOpen (user: User) {
    if (user.noWelcomeModal === true) return false
    if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL) === 'true') return false

    return true
  }

  show () {
    this.modalService.open(this.modal, {
      centered: true,
      backdrop: 'static',
      keyboard: false,
      size: 'lg'
    })
  }

  doNotOpenAgain () {
    peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL, 'true')

    this.userService.updateMyProfile({ noWelcomeModal: true })
      .subscribe({
        next: () => logger.info('We will not open the welcome modal again.'),

        error: err => this.notifier.error(err.message)
      })
  }
}