]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
Fix some accessibility issues
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-profile / my-account-profile.component.ts
1 import { Subject } from 'rxjs'
2 import { Component, Input, OnInit } from '@angular/core'
3 import { Notifier, User, UserService } from '@app/core'
4 import { USER_DESCRIPTION_VALIDATOR, USER_DISPLAY_NAME_REQUIRED_VALIDATOR } from '@app/shared/form-validators/user-validators'
5 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
6
7 @Component({
8 selector: 'my-account-profile',
9 templateUrl: './my-account-profile.component.html',
10 styleUrls: [ './my-account-profile.component.scss' ]
11 })
12 export class MyAccountProfileComponent extends FormReactive implements OnInit {
13 @Input() user: User = null
14 @Input() userInformationLoaded: Subject<any>
15
16 error: string = null
17
18 constructor (
19 protected formValidatorService: FormValidatorService,
20 private notifier: Notifier,
21 private userService: UserService
22 ) {
23 super()
24 }
25
26 ngOnInit () {
27 this.buildForm({
28 'display-name': USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
29 description: USER_DESCRIPTION_VALIDATOR
30 })
31
32 this.userInformationLoaded.subscribe(() => {
33 this.form.patchValue({
34 'display-name': this.user.account.displayName,
35 description: this.user.account.description
36 })
37 })
38 }
39
40 updateMyProfile () {
41 const displayName = this.form.value['display-name']
42 const description = this.form.value['description'] || null
43
44 this.error = null
45
46 this.userService.updateMyProfile({ displayName, description }).subscribe(
47 () => {
48 this.user.account.displayName = displayName
49 this.user.account.description = description
50
51 this.notifier.success($localize`Profile updated.`)
52 },
53
54 err => this.error = err.message
55 )
56 }
57 }