diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-28 13:52:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 13:52:21 +0100 |
commit | d3217560a611b94f888ecf3de93b428a7521d4de (patch) | |
tree | 26fc984f351afb994dc13c94e138476ded50c76a /client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts | |
parent | 64645512b08875c18ebdc009a550cdfa69def955 (diff) | |
download | PeerTube-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/my-account-interface-settings.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts | 40 |
1 files changed, 29 insertions, 11 deletions
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 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit, OnDestroy } from '@angular/core' |
2 | import { Notifier, ServerService } from '@app/core' | 2 | import { Notifier, ServerService } from '@app/core' |
3 | import { ServerConfig, UserUpdateMe } from '../../../../../../shared' | 3 | import { ServerConfig, UserUpdateMe } from '../../../../../../shared' |
4 | import { AuthService } from '../../../core' | 4 | import { AuthService } from '../../../core' |
5 | import { FormReactive, User, UserService } from '../../../shared' | 5 | import { FormReactive } from '../../../shared/forms/form-reactive' |
6 | import { User, UserService } from '../../../shared/users' | ||
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
8 | import { Subject } from 'rxjs' | 9 | import { 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 | }) |
15 | export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit { | 16 | export 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 | } |