mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-05-17 04:12:40 +00:00
338633ce72
They can prevent tree shaking
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { Subject } from 'rxjs'
|
|
import { Component, Input, OnInit } from '@angular/core'
|
|
import { Notifier, User, UserService } from '@app/core'
|
|
import { USER_DESCRIPTION_VALIDATOR, USER_DISPLAY_NAME_REQUIRED_VALIDATOR } from '@app/shared/form-validators/user-validators'
|
|
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
|
|
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|
import { NgIf, NgClass } from '@angular/common'
|
|
|
|
@Component({
|
|
selector: 'my-account-profile',
|
|
templateUrl: './my-account-profile.component.html',
|
|
styleUrls: [ './my-account-profile.component.scss' ],
|
|
standalone: true,
|
|
imports: [ NgIf, FormsModule, ReactiveFormsModule, NgClass ]
|
|
})
|
|
export class MyAccountProfileComponent extends FormReactive implements OnInit {
|
|
@Input() user: User = null
|
|
@Input() userInformationLoaded: Subject<any>
|
|
|
|
error: string = null
|
|
|
|
constructor (
|
|
protected formReactiveService: FormReactiveService,
|
|
private notifier: Notifier,
|
|
private userService: UserService
|
|
) {
|
|
super()
|
|
}
|
|
|
|
ngOnInit () {
|
|
this.buildForm({
|
|
'username': null,
|
|
'display-name': USER_DISPLAY_NAME_REQUIRED_VALIDATOR,
|
|
'description': USER_DESCRIPTION_VALIDATOR
|
|
})
|
|
this.form.controls['username'].disable()
|
|
|
|
this.userInformationLoaded.subscribe(() => {
|
|
this.form.patchValue({
|
|
'username': this.user.username,
|
|
'display-name': this.user.account.displayName,
|
|
'description': this.user.account.description
|
|
})
|
|
})
|
|
}
|
|
|
|
get instanceHost () {
|
|
return window.location.host
|
|
}
|
|
|
|
updateMyProfile () {
|
|
const displayName = this.form.value['display-name']
|
|
const description = this.form.value['description'] || null
|
|
|
|
this.error = null
|
|
|
|
this.userService.updateMyProfile({ displayName, description })
|
|
.subscribe({
|
|
next: () => {
|
|
this.user.account.displayName = displayName
|
|
this.user.account.description = description
|
|
|
|
this.notifier.success($localize`Profile updated.`)
|
|
},
|
|
|
|
error: err => this.error = err.message
|
|
})
|
|
}
|
|
}
|