1 import { concat, of } from 'rxjs'
2 import { pairwise } from 'rxjs/operators'
3 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
4 import { FormGroup } from '@angular/forms'
5 import { UserService } from '@app/core'
6 import { FormReactive, FormValidatorService, VideoChannelValidatorsService } from '@app/shared/shared-forms'
9 selector: 'my-register-step-channel',
10 templateUrl: './register-step-channel.component.html',
11 styleUrls: [ './register.component.scss' ]
13 export class RegisterStepChannelComponent extends FormReactive implements OnInit {
14 @Input() username: string
15 @Output() formBuilt = new EventEmitter<FormGroup>()
18 protected formValidatorService: FormValidatorService,
19 private userService: UserService,
20 private videoChannelValidatorsService: VideoChannelValidatorsService
26 return window.location.host
31 displayName: this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME,
32 name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME
35 setTimeout(() => this.formBuilt.emit(this.form))
39 this.form.get('displayName').valueChanges
41 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
44 isSameThanUsername () {
45 return this.username && this.username === this.form.value['name']
48 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
49 const name = this.form.value['name'] || ''
51 const newName = this.userService.getNewUsername(oldDisplayName, newDisplayName, name)
52 this.form.patchValue({ name: newName })