aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/modal/account-setup-warning-modal.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/modal/account-setup-warning-modal.component.ts')
-rw-r--r--client/src/app/modal/account-setup-warning-modal.component.ts79
1 files changed, 79 insertions, 0 deletions
diff --git a/client/src/app/modal/account-setup-warning-modal.component.ts b/client/src/app/modal/account-setup-warning-modal.component.ts
new file mode 100644
index 000000000..c78de447d
--- /dev/null
+++ b/client/src/app/modal/account-setup-warning-modal.component.ts
@@ -0,0 +1,79 @@
1import { Component, ElementRef, ViewChild } from '@angular/core'
2import { Notifier, ServerService, User, UserService } from '@app/core'
3import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
4import { 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})
11export 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) {
35 return !!user.account.avatar
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}