]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
Add new anchors in my-settings and handle offset sub-menu height (#3032)
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
CommitLineData
67ed6552 1import { Subject } from 'rxjs'
ed56ad11 2import { Component, Input, OnInit } from '@angular/core'
67ed6552
C
3import { Notifier, User, UserService } from '@app/core'
4import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
b1d40cff 5import { I18n } from '@ngx-translate/i18n-polyfill'
ed56ad11
C
6
7@Component({
8 selector: 'my-account-profile',
9 templateUrl: './my-account-profile.component.html',
10 styleUrls: [ './my-account-profile.component.scss' ]
11})
12export class MyAccountProfileComponent extends FormReactive implements OnInit {
13 @Input() user: User = null
d18d6478 14 @Input() userInformationLoaded: Subject<any>
ed56ad11
C
15
16 error: string = null
17
ed56ad11 18 constructor (
d18d6478 19 protected formValidatorService: FormValidatorService,
e309822b 20 private userValidatorsService: UserValidatorsService,
f8b2c1b4 21 private notifier: Notifier,
b1d40cff
C
22 private userService: UserService,
23 private i18n: I18n
ed56ad11
C
24 ) {
25 super()
26 }
27
d18d6478
C
28 ngOnInit () {
29 this.buildForm({
1f20622f 30 'display-name': this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
e309822b 31 description: this.userValidatorsService.USER_DESCRIPTION
ed56ad11
C
32 })
33
d18d6478
C
34 this.userInformationLoaded.subscribe(() => {
35 this.form.patchValue({
36 'display-name': this.user.account.displayName,
37 description: this.user.account.description
38 })
39 })
ed56ad11
C
40 }
41
42 updateMyProfile () {
43 const displayName = this.form.value['display-name']
360329cc 44 const description = this.form.value['description'] || null
ed56ad11
C
45
46 this.error = null
47
48 this.userService.updateMyProfile({ displayName, description }).subscribe(
49 () => {
50 this.user.account.displayName = displayName
51 this.user.account.description = description
52
f8b2c1b4 53 this.notifier.success(this.i18n('Profile updated.'))
ed56ad11
C
54 },
55
56 err => this.error = err.message
57 )
58 }
59}