]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { concat, of } from 'rxjs' |
2 | import { pairwise } from 'rxjs/operators' | |
1d5342ab | 3 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
1d5342ab | 4 | import { FormGroup } from '@angular/forms' |
9589907c | 5 | import { SignupService } from '@app/+signup/shared/signup.service' |
7ed1edbb | 6 | import { VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, VIDEO_CHANNEL_NAME_VALIDATOR } from '@app/shared/form-validators/video-channel-validators' |
5c5bcea2 | 7 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
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 | 14 | export 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 ( | |
5c5bcea2 | 22 | protected formReactiveService: FormReactiveService, |
9589907c | 23 | private signupService: SignupService |
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 | ||
9589907c | 54 | const newName = this.signupService.getNewUsername(oldDisplayName, newDisplayName, name) |
1f20622f | 55 | this.form.patchValue({ name: newName }) |
1d5342ab C |
56 | } |
57 | } |