]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+signup/+register/steps/register-step-channel.component.ts
df92c514554b30dbc666d888d375a3077cea1674
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / steps / register-step-channel.component.ts
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 { VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, VIDEO_CHANNEL_NAME_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
6 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
7 import { UserSignupService } from '@app/shared/shared-users'
8
9 @Component({
10 selector: 'my-register-step-channel',
11 templateUrl: './register-step-channel.component.html',
12 styleUrls: [ './step.component.scss' ]
13 })
14 export class RegisterStepChannelComponent extends FormReactive implements OnInit {
15 @Input() username: string
16 @Input() instanceName: string
17 @Input() videoQuota: number
18
19 @Output() formBuilt = new EventEmitter<FormGroup>()
20
21 constructor (
22 protected formReactiveService: FormReactiveService,
23 private userSignupService: UserSignupService
24 ) {
25 super()
26 }
27
28 get instanceHost () {
29 return window.location.host
30 }
31
32 ngOnInit () {
33 this.buildForm({
34 displayName: VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
35 name: VIDEO_CHANNEL_NAME_VALIDATOR
36 })
37
38 setTimeout(() => this.formBuilt.emit(this.form))
39
40 concat(
41 of(''),
42 this.form.get('displayName').valueChanges
43 ).pipe(pairwise())
44 .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue))
45 }
46
47 isSameThanUsername () {
48 return this.username && this.username === this.form.value['name']
49 }
50
51 private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) {
52 const name = this.form.value['name'] || ''
53
54 const newName = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, name)
55 this.form.patchValue({ name: newName })
56 }
57 }