1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
2 import { AuthService } from '@app/core'
3 import { FormReactive, UserService, VideoChannelValidatorsService } from '@app/shared'
4 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
5 import { FormGroup } from '@angular/forms'
6 import { pairwise } from 'rxjs/operators'
7 import { concat, of } from 'rxjs'
10 selector: 'my-register-step-channel',
11 templateUrl: './register-step-channel.component.html',
12 styleUrls: [ './register.component.scss' ]
14 export class RegisterStepChannelComponent extends FormReactive implements OnInit {
15 @Input() username: string
16 @Output() formBuilt = new EventEmitter<FormGroup>()
19 protected formValidatorService: FormValidatorService,
20 private authService: AuthService,
21 private userService: UserService,
22 private videoChannelValidatorsService: VideoChannelValidatorsService
28 return window.location.host
33 displayName: this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
34 name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME
37 setTimeout(() => this.formBuilt.emit(this.form))
41 this.form.get('displayName').valueChanges
43 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
46 isSameThanUsername () {
47 return this.username && this.username === this.form.value['name']
50 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
51 const name = this.form.value['name'] || ''
53 const newName = this.userService.getNewUsername(oldDisplayName, newDisplayName, name)
54 this.form.patchValue({ name: newName })