]> 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
Update build steps for localization
[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 { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
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 userValidatorsService: UserValidatorsService,
21 private notifier: Notifier,
22 private userService: UserService,
23 private i18n: I18n
24 ) {
25 super()
26 }
27
28 ngOnInit () {
29 this.buildForm({
30 'display-name': this.userValidatorsService.USER_DISPLAY_NAME_REQUIRED,
31 description: this.userValidatorsService.USER_DESCRIPTION
32 })
33
34 this.userInformationLoaded.subscribe(() => {
35 this.form.patchValue({
36 'display-name': this.user.account.displayName,
37 description: this.user.account.description
38 })
39 })
40 }
41
42 updateMyProfile () {
43 const displayName = this.form.value['display-name']
44 const description = this.form.value['description'] || null
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
53 this.notifier.success(this.i18n('Profile updated.'))
54 },
55
56 err => this.error = err.message
57 )
58 }
59 }