From 6f03f944c34f78b38a68128413b55186e0676949 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Jun 2022 13:54:54 +0200 Subject: Redesign register steps --- .../steps/register-step-channel.component.ts | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 client/src/app/+signup/+register/steps/register-step-channel.component.ts (limited to 'client/src/app/+signup/+register/steps/register-step-channel.component.ts') diff --git a/client/src/app/+signup/+register/steps/register-step-channel.component.ts b/client/src/app/+signup/+register/steps/register-step-channel.component.ts new file mode 100644 index 000000000..c10b568ba --- /dev/null +++ b/client/src/app/+signup/+register/steps/register-step-channel.component.ts @@ -0,0 +1,57 @@ +import { concat, of } from 'rxjs' +import { pairwise } from 'rxjs/operators' +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' +import { FormGroup } from '@angular/forms' +import { VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, VIDEO_CHANNEL_NAME_VALIDATOR } from '@app/shared/form-validators/video-channel-validators' +import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' +import { UserSignupService } from '@app/shared/shared-users' + +@Component({ + selector: 'my-register-step-channel', + templateUrl: './register-step-channel.component.html', + styleUrls: [ './step.component.scss' ] +}) +export class RegisterStepChannelComponent extends FormReactive implements OnInit { + @Input() username: string + @Input() instanceName: string + @Input() videoQuota: number + + @Output() formBuilt = new EventEmitter() + + constructor ( + protected formValidatorService: FormValidatorService, + private userSignupService: UserSignupService + ) { + super() + } + + get instanceHost () { + return window.location.host + } + + ngOnInit () { + this.buildForm({ + displayName: VIDEO_CHANNEL_DISPLAY_NAME_VALIDATOR, + name: VIDEO_CHANNEL_NAME_VALIDATOR + }) + + setTimeout(() => this.formBuilt.emit(this.form)) + + concat( + of(''), + this.form.get('displayName').valueChanges + ).pipe(pairwise()) + .subscribe(([ oldValue, newValue ]) => this.onDisplayNameChange(oldValue, newValue)) + } + + isSameThanUsername () { + return this.username && this.username === this.form.value['name'] + } + + private onDisplayNameChange (oldDisplayName: string, newDisplayName: string) { + const name = this.form.value['name'] || '' + + const newName = this.userSignupService.getNewUsername(oldDisplayName, newDisplayName, name) + this.form.patchValue({ name: newName }) + } +} -- cgit v1.2.3