]> 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
Bumped to version v5.2.1
[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, FormReactiveService } 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 formReactiveService: FormReactiveService,
20 private notifier: Notifier,
21 private userService: UserService
22 ) {
23 super()
24 }
25
26 ngOnInit () {
27 this.buildForm({
28 'username': null,
29 'display-name': USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
30 'description': USER_DESCRIPTION_VALIDATOR
31 })
32 this.form.controls['username'].disable()
33
34 this.userInformationLoaded.subscribe(() => {
35 this.form.patchValue({
36 'username': this.user.username,
37 'display-name': this.user.account.displayName,
38 'description': this.user.account.description
39 })
40 })
41 }
42
43 get instanceHost () {
44 return window.location.host
45 }
46
47 updateMyProfile () {
48 const displayName = this.form.value['display-name']
49 const description = this.form.value['description'] || null
50
51 this.error = null
52
53 this.userService.updateMyProfile({ displayName, description })
54 .subscribe({
55 next: () => {
56 this.user.account.displayName = displayName
57 this.user.account.description = description
58
59 this.notifier.success($localize`Profile updated.`)
60 },
61
62 error: err => this.error = err.message
63 })
64 }
65 }