From d3446870d4b39289b7772e42c41350c0f73d2e0a Mon Sep 17 00:00:00 2001
From: Ruben Bimberg <ruben.bimberg@mni.thm.de>
Date: Wed, 11 Aug 2021 13:09:14 +0200
Subject: [PATCH] Fix redirect to question list

[Ticket: #203]
---
 .../shared/header/header.component.html       |  2 +-
 .../shared/quiz-now/quiz-now.component.ts     | 33 +++++++++++++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/app/components/shared/header/header.component.html b/src/app/components/shared/header/header.component.html
index 1a8291d98..51b46b99a 100644
--- a/src/app/components/shared/header/header.component.html
+++ b/src/app/components/shared/header/header.component.html
@@ -420,7 +420,7 @@
       <button mat-menu-item
               *ngIf="user && router.url.endsWith('/quiz')"
               tabindex="0"
-              (click)="goBack()">
+              (click)="navigateQuestionBoard()">
         <mat-icon class="header-icons">forum</mat-icon>
         <span>{{'header.back-to-questionboard' | translate}}</span>
       </button>
diff --git a/src/app/components/shared/quiz-now/quiz-now.component.ts b/src/app/components/shared/quiz-now/quiz-now.component.ts
index 69c95063f..5993dc3da 100644
--- a/src/app/components/shared/quiz-now/quiz-now.component.ts
+++ b/src/app/components/shared/quiz-now/quiz-now.component.ts
@@ -1,19 +1,46 @@
-import { Component, OnInit } from '@angular/core';
+import { Component, OnDestroy, OnInit } from '@angular/core';
 import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
+import { EventService } from '../../../services/util/event.service';
+import { Router } from '@angular/router';
 
 @Component({
   selector: 'app-quiz-now',
   templateUrl: './quiz-now.component.html',
   styleUrls: ['./quiz-now.component.scss']
 })
-export class QuizNowComponent implements OnInit {
+export class QuizNowComponent implements OnInit, OnDestroy {
   urlSafe: SafeResourceUrl;
   isLoading = true;
+  shortId: string;
+  roleString: string;
+  private _headerSubscription;
 
-  constructor(public sanitizer: DomSanitizer) {
+  constructor(public sanitizer: DomSanitizer,
+              private router: Router,
+              private eventService: EventService) {
+    this.shortId = localStorage.getItem('shortId');
+    const access = (JSON.parse(localStorage.getItem('ROOM_ACCESS')) || []) as string[];
+    const roomAccess = access.find(e => e.endsWith('_' + this.shortId)) || '0_' + this.shortId;
+    const role = parseInt(roomAccess.substr(0, 1), 10);
+    if (role === 3) {
+      this.roleString = 'creator';
+    } else if (role > 0) {
+      this.roleString = 'moderator';
+    } else {
+      this.roleString = 'participant';
+    }
   }
 
   ngOnInit() {
     this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl('https://staging.antworte.jetzt/');
+    this._headerSubscription = this.eventService.on<string>('navigate').subscribe(action => {
+      if (action === 'questionBoard') {
+        this.router.navigate(['/' + this.roleString + '/room/' + this.shortId + '/comments']);
+      }
+    });
+  }
+
+  ngOnDestroy() {
+    this._headerSubscription.unsubscribe();
   }
 }
-- 
GitLab