]>
Commit | Line | Data |
---|---|---|
1 | import { Location } from '@angular/common' | |
2 | import { Component, ElementRef, ViewChild } from '@angular/core' | |
3 | import { Notifier, UserService } from '@app/core' | |
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | |
5 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | |
6 | import { About } from '@shared/models/server' | |
7 | ||
8 | @Component({ | |
9 | selector: 'my-instance-config-warning-modal', | |
10 | templateUrl: './instance-config-warning-modal.component.html', | |
11 | styleUrls: [ './instance-config-warning-modal.component.scss' ] | |
12 | }) | |
13 | export class InstanceConfigWarningModalComponent { | |
14 | @ViewChild('modal', { static: true }) modal: ElementRef | |
15 | ||
16 | stopDisplayModal = false | |
17 | about: About | |
18 | ||
19 | private LOCAL_STORAGE_KEYS = { | |
20 | NO_INSTANCE_CONFIG_WARNING_MODAL: 'no_instance_config_warning_modal' | |
21 | } | |
22 | ||
23 | constructor ( | |
24 | private userService: UserService, | |
25 | private location: Location, | |
26 | private modalService: NgbModal, | |
27 | private notifier: Notifier | |
28 | ) { } | |
29 | ||
30 | show (about: About) { | |
31 | const result = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL) | |
32 | if (result === 'true') return | |
33 | ||
34 | if (this.location.path().startsWith('/admin/config/edit-custom')) return | |
35 | ||
36 | this.about = about | |
37 | ||
38 | const ref = this.modalService.open(this.modal, { centered: true }) | |
39 | ||
40 | ref.result.finally(() => { | |
41 | if (this.stopDisplayModal === true) this.doNotOpenAgain() | |
42 | }) | |
43 | } | |
44 | ||
45 | isDefaultShortDescription (description: string) { | |
46 | return description === 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | |
47 | } | |
48 | ||
49 | private doNotOpenAgain () { | |
50 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_INSTANCE_CONFIG_WARNING_MODAL, 'true') | |
51 | ||
52 | this.userService.updateMyProfile({ noInstanceConfigWarningModal: true }) | |
53 | .subscribe( | |
54 | () => console.log('We will not open the instance config warning modal again.'), | |
55 | ||
56 | err => this.notifier.error(err.message) | |
57 | ) | |
58 | } | |
59 | } |