]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/register-step-channel.component.ts
Merge branch 'open-api-clients' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / register-step-channel.component.ts
CommitLineData
1d5342ab
C
1import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
2import { AuthService } from '@app/core'
1f20622f 3import { FormReactive, UserService, VideoChannelValidatorsService } from '@app/shared'
1d5342ab
C
4import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5import { FormGroup } from '@angular/forms'
1f20622f
C
6import { pairwise } from 'rxjs/operators'
7import { concat, of } from 'rxjs'
1d5342ab
C
8
9@Component({
b247a132
C
10 selector: 'my-register-step-channel',
11 templateUrl: './register-step-channel.component.html',
12 styleUrls: [ './register.component.scss' ]
1d5342ab 13})
b247a132 14export class RegisterStepChannelComponent extends FormReactive implements OnInit {
1d5342ab
C
15 @Input() username: string
16 @Output() formBuilt = new EventEmitter<FormGroup>()
17
18 constructor (
19 protected formValidatorService: FormValidatorService,
20 private authService: AuthService,
1f20622f 21 private userService: UserService,
1d5342ab
C
22 private videoChannelValidatorsService: VideoChannelValidatorsService
23 ) {
24 super()
25 }
26
27 get instanceHost () {
28 return window.location.host
29 }
30
1d5342ab
C
31 ngOnInit () {
32 this.buildForm({
1f20622f
C
33 displayName: this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
34 name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME
1d5342ab
C
35 })
36
37 setTimeout(() => this.formBuilt.emit(this.form))
1f20622f
C
38
39 concat(
40 of(''),
41 this.form.get('displayName').valueChanges
42 ).pipe(pairwise())
43 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
44 }
45
46 isSameThanUsername () {
47 return this.username && this.username === this.form.value['name']
48 }
49
50 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
51 const name = this.form.value['name'] || ''
52
53 const newName = this.userService.getNewUsername(oldDisplayName, newDisplayName, name)
54 this.form.patchValue({ name: newName })
1d5342ab
C
55 }
56}