diff --git a/src/app/components/shared/header/header.component.html b/src/app/components/shared/header/header.component.html index 1a8291d98edc4f03ce09b9fe836faee71b91cf9b..51b46b99a09e312b7dd76a5197be6422237e5eb6 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 69c95063fe6c472fa1727c2cd21ce4bce7647c72..5993dc3dad3fe8f7c48bdc7f0df9a3dcb71fcfa3 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(); } }