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