aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-settings/my-account-interface
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-02-28 13:52:21 +0100
committerGitHub <noreply@github.com>2020-02-28 13:52:21 +0100
commitd3217560a611b94f888ecf3de93b428a7521d4de (patch)
tree26fc984f351afb994dc13c94e138476ded50c76a /client/src/app/+my-account/my-account-settings/my-account-interface
parent64645512b08875c18ebdc009a550cdfa69def955 (diff)
downloadPeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.gz
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.tar.zst
PeerTube-d3217560a611b94f888ecf3de93b428a7521d4de.zip
Add visitor settings, rework logged-in dropdown (#2514)
* Add visitor settings, rework logged-in dropdown * Make user dropdown P2P switch functional * Fix lint * Fix unnecessary notification when user logs out * Simplify visitor settings code and remove unnecessary icons * Catch parsing errors and reindent menu styles
Diffstat (limited to 'client/src/app/+my-account/my-account-settings/my-account-interface')
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html2
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts40
2 files changed, 30 insertions, 12 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html
index f034c6bb3..6f48d8f7d 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html
+++ b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html
@@ -12,5 +12,5 @@
12 </div> 12 </div>
13 </div> 13 </div>
14 14
15 <input type="submit" i18n-value value="Save" [disabled]="!form.valid"> 15 <input *ngIf="!reactiveUpdate" type="submit" class="mt-0" i18n-value value="Save" [disabled]="!form.valid">
16</form> 16</form>
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts
index 441f89f10..b6c17c0e3 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts
@@ -1,21 +1,26 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit, OnDestroy } from '@angular/core'
2import { Notifier, ServerService } from '@app/core' 2import { Notifier, ServerService } from '@app/core'
3import { ServerConfig, UserUpdateMe } from '../../../../../../shared' 3import { ServerConfig, UserUpdateMe } from '../../../../../../shared'
4import { AuthService } from '../../../core' 4import { AuthService } from '../../../core'
5import { FormReactive, User, UserService } from '../../../shared' 5import { FormReactive } from '../../../shared/forms/form-reactive'
6import { User, UserService } from '../../../shared/users'
6import { I18n } from '@ngx-translate/i18n-polyfill' 7import { I18n } from '@ngx-translate/i18n-polyfill'
7import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 8import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8import { Subject } from 'rxjs' 9import { Subject, Subscription } from 'rxjs'
9 10
10@Component({ 11@Component({
11 selector: 'my-account-interface-settings', 12 selector: 'my-account-interface-settings',
12 templateUrl: './my-account-interface-settings.component.html', 13 templateUrl: './my-account-interface-settings.component.html',
13 styleUrls: [ './my-account-interface-settings.component.scss' ] 14 styleUrls: [ './my-account-interface-settings.component.scss' ]
14}) 15})
15export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit { 16export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit, OnDestroy {
16 @Input() user: User = null 17 @Input() user: User = null
18 @Input() reactiveUpdate = false
19 @Input() notifyOnUpdate = true
17 @Input() userInformationLoaded: Subject<any> 20 @Input() userInformationLoaded: Subject<any>
18 21
22 formValuesWatcher: Subscription
23
19 private serverConfig: ServerConfig 24 private serverConfig: ServerConfig
20 25
21 constructor ( 26 constructor (
@@ -48,9 +53,17 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements
48 this.form.patchValue({ 53 this.form.patchValue({
49 theme: this.user.theme 54 theme: this.user.theme
50 }) 55 })
56
57 if (this.reactiveUpdate) {
58 this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings())
59 }
51 }) 60 })
52 } 61 }
53 62
63 ngOnDestroy () {
64 this.formValuesWatcher?.unsubscribe()
65 }
66
54 updateInterfaceSettings () { 67 updateInterfaceSettings () {
55 const theme = this.form.value['theme'] 68 const theme = this.form.value['theme']
56 69
@@ -58,14 +71,19 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements
58 theme 71 theme
59 } 72 }
60 73
61 this.userService.updateMyProfile(details).subscribe( 74 if (this.authService.isLoggedIn()) {
62 () => { 75 this.userService.updateMyProfile(details).subscribe(
63 this.authService.refreshUserInformation() 76 () => {
77 this.authService.refreshUserInformation()
64 78
65 this.notifier.success(this.i18n('Interface settings updated.')) 79 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
66 }, 80 },
67 81
68 err => this.notifier.error(err.message) 82 err => this.notifier.error(err.message)
69 ) 83 )
84 } else {
85 this.userService.updateMyAnonymousProfile(details)
86 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
87 }
70 } 88 }
71} 89}