]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+register/steps/register-step-channel.component.ts
Redesign register steps
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +register / steps / register-step-channel.component.ts
CommitLineData
67ed6552
C
1import { concat, of } from 'rxjs'
2import { pairwise } from 'rxjs/operators'
1d5342ab 3import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
1d5342ab 4import { FormGroup } from '@angular/forms'
7ed1edbb
C
5import { VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, VIDEO_CHANNEL_NAME_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
6import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
d92d070c 7import { UserSignupService } from '@app/shared/shared-users'
1d5342ab
C
8
9@Component({
b247a132
C
10 selector: 'my-register-step-channel',
11 templateUrl: './register-step-channel.component.html',
6f03f944 12 styleUrls: [ './step.component.scss' ]
1d5342ab 13})
b247a132 14export class RegisterStepChannelComponent extends FormReactive implements OnInit {
1d5342ab 15 @Input() username: string
6f03f944
C
16 @Input() instanceName: string
17 @Input() videoQuota: number
18
1d5342ab
C
19 @Output() formBuilt = new EventEmitter<FormGroup>()
20
21 constructor (
22 protected formValidatorService: FormValidatorService,
d92d070c 23 private userSignupService: UserSignupService
1d5342ab
C
24 ) {
25 super()
26 }
27
28 get instanceHost () {
29 return window.location.host
30 }
31
1d5342ab
C
32 ngOnInit () {
33 this.buildForm({
7ed1edbb
C
34 displayName: VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR,
35 name: VIDEO_CHANNEL_NAME_VALIDATOR
1d5342ab
C
36 })
37
38 setTimeout(() => this.formBuilt.emit(this.form))
1f20622f
C
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
d92d070c 54 const newName = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, name)
1f20622f 55 this.form.patchValue({ name: newName })
1d5342ab
C
56 }
57}