From 49c17327f56a284bc5bb110c8222692b82cd4ba0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Tue, 12 Feb 2019 22:19:48 +0100
Subject: [PATCH] Implement room-joining

---
 .../new-landing/new-landing.component.html    |  9 ++-----
 .../home/new-landing/new-landing.component.ts | 24 +++++++------------
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/src/app/components/home/new-landing/new-landing.component.html b/src/app/components/home/new-landing/new-landing.component.html
index ee605c7b9..0ef05f5c9 100644
--- a/src/app/components/home/new-landing/new-landing.component.html
+++ b/src/app/components/home/new-landing/new-landing.component.html
@@ -2,15 +2,10 @@
   <form>
     <div fxLayout="row" fxLayoutAlign="center" fxLayoutGap="10px">
       <mat-form-field class="number">
-        <input matInput #roomId placeholder="Join Session!" maxlength="8" [matAutocomplete]="auto"/>
+        <input matInput #roomId placeholder="Join Session!" maxlength="8"/>
         <mat-hint align="end">{{roomId.value.length}} / 8</mat-hint>
-        <mat-autocomplete #auto="matAutocomplete">
-          <mat-option *ngFor="let session of sessions" [value]="session.id">
-            {{session.name}}
-          </mat-option>
-        </mat-autocomplete>
       </mat-form-field>
-      <button mat-fab color="primary" type="submit" (click)="login()">
+      <button mat-fab color="primary" type="submit" (click)="joinRoom(roomId.value)">
         <mat-icon>input</mat-icon>
       </button>
     </div>
diff --git a/src/app/components/home/new-landing/new-landing.component.ts b/src/app/components/home/new-landing/new-landing.component.ts
index 43fab4e43..35116f0dc 100644
--- a/src/app/components/home/new-landing/new-landing.component.ts
+++ b/src/app/components/home/new-landing/new-landing.component.ts
@@ -4,16 +4,7 @@ import { MatDialog } from '@angular/material';
 import { AuthenticationService } from '../../../services/http/authentication.service';
 import { User } from '../../../models/user';
 import { UserRole } from '../../../models/user-roles.enum';
-
-export class Session {
-  name: string;
-  id: number;
-
-  constructor(name: string, id: number) {
-    this.id = id;
-    this.name = name;
-  }
-}
+import { Router } from '@angular/router';
 
 @Component({
   selector: 'app-new-landing',
@@ -22,17 +13,14 @@ export class Session {
 })
 export class NewLandingComponent implements OnInit {
 
-  sessions: Session[] = new Array<Session>();
   user: User;
 
   constructor(public authenticationService: AuthenticationService,
+              private router: Router,
               public dialog: MatDialog) {
   }
 
   ngOnInit() {
-    this.sessions[0] = new Session('Angular', 98299243);
-    this.sessions[1] = new Session('Typescript', 52009627);
-    this.sessions[2] = new Session('Angular', 48590407);
     this.authenticationService.watchUser.subscribe(newUser => this.user = newUser);
   }
 
@@ -42,9 +30,13 @@ export class NewLandingComponent implements OnInit {
     });
   }
 
-  login(): void {
+  joinRoom(id: number) {
     if (!this.user) {
-      this.authenticationService.guestLogin(UserRole.PARTICIPANT).subscribe();
+      this.authenticationService.guestLogin(UserRole.PARTICIPANT).subscribe(loggedIn => {
+        if (loggedIn === 'true') {
+          this.router.navigate([`/participant/room/${id}`]);
+        }
+      });
     }
   }
 }
-- 
GitLab