From 1f20622f2b087eaf8738d60fae00a44b9c558ca3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 Jun 2019 16:59:53 +0200 Subject: Improve registration * Add ability to set the user display name * Use display name to guess the username/channel name * Add explanations about what is the purpose of a username/channel name * Add a loader at the "done" step --- .../+register/register-step-channel.component.ts | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'client/src/app/+signup/+register/register-step-channel.component.ts') diff --git a/client/src/app/+signup/+register/register-step-channel.component.ts b/client/src/app/+signup/+register/register-step-channel.component.ts index 9e13f75b3..e434b91a7 100644 --- a/client/src/app/+signup/+register/register-step-channel.component.ts +++ b/client/src/app/+signup/+register/register-step-channel.component.ts @@ -1,8 +1,10 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { AuthService } from '@app/core' -import { FormReactive, VideoChannelValidatorsService } from '@app/shared' +import { FormReactive, UserService, VideoChannelValidatorsService } from '@app/shared' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { FormGroup } from '@angular/forms' +import { pairwise } from 'rxjs/operators' +import { concat, of } from 'rxjs' @Component({ selector: 'my-register-step-channel', @@ -16,6 +18,7 @@ export class RegisterStepChannelComponent extends FormReactive implements OnInit constructor ( protected formValidatorService: FormValidatorService, private authService: AuthService, + private userService: UserService, private videoChannelValidatorsService: VideoChannelValidatorsService ) { super() @@ -25,16 +28,29 @@ export class RegisterStepChannelComponent extends FormReactive implements OnInit return window.location.host } - isSameThanUsername () { - return this.username && this.username === this.form.value['name'] - } - ngOnInit () { this.buildForm({ - name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME, - displayName: this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME + displayName: this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, + name: this.videoChannelValidatorsService.VIDEO_CHANNEL_NAME }) 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.userService.getNewUsername(oldDisplayName, newDisplayName, name) + this.form.patchValue({ name: newName }) } } -- cgit v1.2.3