Add config instance warning modal
[oweals/peertube.git] / client / src / app / modal / instance-config-warning-modal.component.ts
1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { About } from '@shared/models/server'
5 import { UserService } from '@app/shared'
6
7 @Component({
8   selector: 'my-instance-config-warning-modal',
9   templateUrl: './instance-config-warning-modal.component.html',
10   styleUrls: [ './instance-config-warning-modal.component.scss' ]
11 })
12 export class InstanceConfigWarningModalComponent {
13   @ViewChild('modal', { static: true }) modal: ElementRef
14
15   stopDisplayModal = false
16   about: About
17
18   constructor (
19     private userService: UserService,
20     private modalService: NgbModal,
21     private notifier: Notifier
22   ) { }
23
24   show (about: About) {
25     this.about = about
26
27     const ref = this.modalService.open(this.modal)
28
29     ref.result.finally(() => {
30       if (this.stopDisplayModal === true) this.doNotOpenAgain()
31     })
32   }
33
34   private doNotOpenAgain () {
35     this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
36         .subscribe(
37           () => console.log('We will not open the instance config warning modal again.'),
38
39           err => this.notifier.error(err.message)
40         )
41   }
42 }