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