742a7dd413e645148be667f128de587ed2e2631e
[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   isDefaultShortDescription (description: string) {
35     return description === 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly ' +
36       'in the web browser with WebTorrent and Angular.'
37   }
38
39   private doNotOpenAgain () {
40     this.userService.updateMyProfile({ noInstanceConfigWarningModal: true })
41         .subscribe(
42           () => console.log('We will not open the instance config warning modal again.'),
43
44           err => this.notifier.error(err.message)
45         )
46   }
47 }