feat: Added a chatroom component, that is navigatable by the chatroom's ID
[demos/kafka/chat] / src / app / user / user.component.ts
index 0ec3026..23817da 100644 (file)
@@ -11,16 +11,22 @@ import { UserService } from "../user.service";
 })
 export class UserComponent {
 
-  usernameForm = new FormControl('', Validators.required);
+  usernameForm = new FormControl('', [ Validators.required, this.noWhitespaceValidator ]);
 
   updateName(): void {
     var input = this.usernameForm.getRawValue();
     if (input !== null) {
-      this.userService.setUser(input);
+      this.userService.setUser(input.trim());
       this.router.navigate(['chatrooms'])
     }
   }
 
+  noWhitespaceValidator(control: FormControl) {
+    const isWhitespace = (control.value || '').trim().length === 0;
+    const isValid = !isWhitespace;
+    return isValid ? null : { 'whitespace': true };
+  }
+
   constructor(
     private userService: UserService,
     private router: Router) {}