]>
Commit | Line | Data |
---|---|---|
8f581725 C |
1 | import { Component, ElementRef, ViewChild } from '@angular/core' |
2 | import { Notifier, ServerService, User, UserService } from '@app/core' | |
3 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' | |
4 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | |
5 | ||
6 | @Component({ | |
7 | selector: 'my-account-setup-warning-modal', | |
8 | templateUrl: './account-setup-warning-modal.component.html', | |
9 | styleUrls: [ './account-setup-warning-modal.component.scss' ] | |
10 | }) | |
11 | export class AccountSetupWarningModalComponent { | |
12 | @ViewChild('modal', { static: true }) modal: ElementRef | |
13 | ||
14 | stopDisplayModal = false | |
15 | ref: NgbModalRef | |
16 | ||
17 | user: User | |
18 | ||
19 | private LOCAL_STORAGE_KEYS = { | |
20 | NO_ACCOUNT_SETUP_WARNING_MODAL: 'no_account_setup_warning_modal' | |
21 | } | |
22 | ||
23 | constructor ( | |
24 | private userService: UserService, | |
25 | private modalService: NgbModal, | |
26 | private notifier: Notifier, | |
27 | private serverService: ServerService | |
28 | ) { } | |
29 | ||
30 | get instanceName () { | |
31 | return this.serverService.getHTMLConfig().instance.name | |
32 | } | |
33 | ||
34 | hasAccountAvatar (user: User) { | |
d0800f76 | 35 | return user.account.avatars.length !== 0 |
8f581725 C |
36 | } |
37 | ||
38 | hasAccountDescription (user: User) { | |
39 | return !!user.account.description | |
40 | } | |
41 | ||
42 | shouldOpen (user: User) { | |
43 | if (user.noAccountSetupWarningModal === true) return false | |
44 | if (peertubeLocalStorage.getItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL) === 'true') return false | |
45 | ||
46 | if (this.hasAccountAvatar(user) && this.hasAccountDescription(user)) return false | |
47 | if (this.userService.hasSignupInThisSession()) return false | |
48 | ||
49 | return true | |
50 | } | |
51 | ||
52 | show (user: User) { | |
53 | this.user = user | |
54 | ||
55 | if (this.ref) return | |
56 | ||
57 | this.ref = this.modalService.open(this.modal, { | |
58 | centered: true, | |
59 | backdrop: 'static', | |
60 | keyboard: false, | |
61 | size: 'md' | |
62 | }) | |
63 | ||
64 | this.ref.result.finally(() => { | |
65 | if (this.stopDisplayModal === true) this.doNotOpenAgain() | |
66 | }) | |
67 | } | |
68 | ||
69 | private doNotOpenAgain () { | |
70 | peertubeLocalStorage.setItem(this.LOCAL_STORAGE_KEYS.NO_ACCOUNT_SETUP_WARNING_MODAL, 'true') | |
71 | ||
72 | this.userService.updateMyProfile({ noAccountSetupWarningModal: true }) | |
73 | .subscribe({ | |
74 | next: () => console.log('We will not open the account setup modal again.'), | |
75 | ||
76 | error: err => this.notifier.error(err.message) | |
77 | }) | |
78 | } | |
79 | } |