diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-27 10:15:55 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-27 10:15:55 +0200 |
commit | 8f581725651c4b2c213d75fc028e306bbf239d3e (patch) | |
tree | 8deb842327c2a227d8e302d9a84bd9f8f9f7affa /client/src/app/modal/account-setup-warning-modal.component.ts | |
parent | 1ff15061b31245df4248e47228d0a90b07ab3f01 (diff) | |
download | PeerTube-8f581725651c4b2c213d75fc028e306bbf239d3e.tar.gz PeerTube-8f581725651c4b2c213d75fc028e306bbf239d3e.tar.zst PeerTube-8f581725651c4b2c213d75fc028e306bbf239d3e.zip |
Allow accounts to skip account setup modal
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.ts | 79 |
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 @@ | |||
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) { | ||
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 | } | ||