]>
Commit | Line | Data |
---|---|---|
1 | import { Component, ElementRef, ViewChild } from '@angular/core' | |
2 | import { Notifier, UserService } from '@app/core' | |
3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | |
4 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | |
5 | ||
6 | @Component({ | |
7 | selector: 'my-welcome-modal', | |
8 | templateUrl: './welcome-modal.component.html', | |
9 | styleUrls: [ './welcome-modal.component.scss' ] | |
10 | }) | |
11 | export class WelcomeModalComponent { | |
12 | @ViewChild('modal', { static: true }) modal: ElementRef | |
13 | ||
14 | private LOCAL_STORAGE_KEYS = { | |
15 | NO_WELCOME_MODAL: 'no_welcome_modal' | |
16 | } | |
17 | ||
18 | constructor ( | |
19 | private userService: UserService, | |
20 | private modalService: NgbModal, | |
21 | private notifier: Notifier | |
22 | ) { } | |
23 | ||
24 | show () { | |
25 | const result = peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL) | |
26 | if (result === 'true') return | |
27 | ||
28 | this.modalService.open(this.modal, { | |
29 | centered: true, | |
30 | backdrop: 'static', | |
31 | keyboard: false, | |
32 | size: 'lg' | |
33 | }) | |
34 | } | |
35 | ||
36 | doNotOpenAgain () { | |
37 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_WELCOME_MODAL, 'true') | |
38 | ||
39 | this.userService.updateMyProfile({ noWelcomeModal: true }) | |
40 | .subscribe( | |
41 | () => console.log('We will not open the welcome modal again.'), | |
42 | ||
43 | err => this.notifier.error(err.message) | |
44 | ) | |
45 | } | |
46 | } |