Commit 4db291f8 authored by Christopher Fullarton's avatar Christopher Fullarton

Fixes subscription logic in router param calls

parent f8f48e47
Pipeline #34021 passed with stages
in 15 minutes and 3 seconds
......@@ -29,8 +29,8 @@ export class QuizDuplicateComponent implements OnInit, OnDestroy {
public ngOnInit(): void {
this.route.paramMap.pipe(map(params => params.get('name')), filter(() => this.userService.isAuthorizedFor(UserRole.CreateQuiz)),
distinctUntilChanged(), takeUntil(this._destroy), switchMap(name => this.quizApiService.initQuizInstance(name)))
.subscribe(data => {
this.storageService.db.Quiz.put(data.payload.quiz);
.subscribe(async data => {
await this.storageService.db.Quiz.put(data.payload.quiz);
this.quizService.quiz = new QuizEntity(data.payload.quiz);
this.quizService.isOwner = true;
this.router.navigate(['/quiz', 'flow']);
......
......@@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { SimpleMQ } from 'ng2-simple-mq';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators';
import { environment } from '../../../../environments/environment';
import { StorageKey } from '../../../lib/enums/enums';
import { MessageProtocol } from '../../../lib/enums/Message';
......@@ -32,7 +32,6 @@ export class LeaderboardComponent implements OnInit, OnDestroy, IHasTriggeredNav
public hasTriggeredNavigation: boolean;
private _questionIndex: number;
private readonly _destroy = new Subject();
get questionIndex(): number {
return this._questionIndex;
......@@ -62,6 +61,7 @@ export class LeaderboardComponent implements OnInit, OnDestroy, IHasTriggeredNav
return this._ownResponse;
}
private readonly _destroy = new Subject();
private _serverUnavailableModal: NgbModalRef;
private _name: string;
private readonly _messageSubscriptions: Array<string> = [];
......@@ -78,7 +78,9 @@ export class LeaderboardComponent implements OnInit, OnDestroy, IHasTriggeredNav
private connectionService: ConnectionService,
private i18nService: I18nService,
private leaderboardApiService: LeaderboardApiService,
private ngbModal: NgbModal, private messageQueue: SimpleMQ, private customMarkdownService: CustomMarkdownService,
private ngbModal: NgbModal,
private messageQueue: SimpleMQ,
private customMarkdownService: CustomMarkdownService,
) {
this.footerBarService.TYPE_REFERENCE = LeaderboardComponent.TYPE;
}
......@@ -171,14 +173,15 @@ export class LeaderboardComponent implements OnInit, OnDestroy, IHasTriggeredNav
}
private initData(): void {
this.route.params.pipe(takeUntil(this._destroy)).subscribe(params => {
this._questionIndex = +params['questionIndex'];
this.route.paramMap.pipe(map(params => parseInt(params.get('questionIndex'), 10)), distinctUntilChanged(), takeUntil(this._destroy))
.subscribe(questionIndex => {
this._questionIndex = questionIndex;
this._isGlobalRanking = isNaN(this._questionIndex);
if (this._isGlobalRanking) {
this.headerLabelService.headerLabel = 'component.leaderboard.global_header';
this._questionIndex = null;
if (params['questionIndex']) {
if (!!questionIndex) {
this.hasTriggeredNavigation = true;
this.router.navigate(['/quiz', 'flow', 'leaderboard']);
return;
......@@ -206,8 +209,7 @@ export class LeaderboardComponent implements OnInit, OnDestroy, IHasTriggeredNav
this.messageQueue.subscribe(MessageProtocol.NextQuestion, payload => {
this.quizService.quiz.currentQuestionIndex = payload.nextQuestionIndex;
sessionStorage.removeItem(StorageKey.CurrentQuestionIndex);
}),
this.messageQueue.subscribe(MessageProtocol.Start, payload => {
}), this.messageQueue.subscribe(MessageProtocol.Start, payload => {
this.hasTriggeredNavigation = true;
this.router.navigate(['/quiz', 'flow', 'voting']);
}), this.messageQueue.subscribe(MessageProtocol.UpdatedResponse, payload => {
......
import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators';
import { MessageProtocol, StatusProtocol } from '../../lib/enums/Message';
import { IMessage } from '../../lib/interfaces/communication/IMessage';
import { QuizApiService } from '../../service/api/quiz/quiz-api.service';
import { CasLoginService } from '../../service/login/cas-login.service';
import { QuizService } from '../../service/quiz/quiz.service';
......@@ -31,17 +32,19 @@ export class QuizJoinComponent implements OnInit, OnDestroy {
}
public ngOnInit(): void {
this.route.queryParams.pipe(takeUntil(this._destroy)).subscribe(queryParams => {
this.route.queryParams.pipe(distinctUntilChanged(), takeUntil(this._destroy)).subscribe(queryParams => {
this.casService.ticket = queryParams.ticket;
});
this.route.params.pipe(takeUntil(this._destroy)).subscribe(async params => {
if (!params || !params.quizName) {
this.route.paramMap.pipe(map(val => val.get('quizName')), distinctUntilChanged(), takeUntil(this._destroy)).subscribe(quizname => {
console.log(quizname);
if (!quizname) {
this.router.navigate(['/']);
return;
}
this.sharedService.isLoadingEmitter.next(true);
this.quizApiService.getFullQuizStatusData(params.quizName).subscribe(quizStatusData => this.resolveQuizStatusData(quizStatusData));
this.quizApiService.getFullQuizStatusData(quizname).subscribe(quizStatusData => this.resolveQuizStatusData(quizStatusData));
});
}
......@@ -50,7 +53,7 @@ export class QuizJoinComponent implements OnInit, OnDestroy {
this._destroy.complete();
}
private resolveQuizStatusData(quizStatusData): void {
private resolveQuizStatusData(quizStatusData: IMessage): void {
if (quizStatusData.status !== StatusProtocol.Success || quizStatusData.step !== MessageProtocol.Available) {
this.router.navigate(['/']);
return;
......
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { Subject } from 'rxjs';
import { distinctUntilChanged, takeUntil } from 'rxjs/operators';
import { environment } from '../../../environments/environment';
import { DefaultSettings } from '../../lib/default.settings';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
......@@ -17,7 +18,7 @@ export class InfoComponent implements OnInit, OnDestroy, AfterViewInit {
public static TYPE = 'InfoComponent';
public currentData: string;
public readonly infoButtons: Array<{ id: string, i18nRef: string }> = [];
private _routerSubscription: Subscription;
private readonly _destroy = new Subject();
@ViewChild('buttonHeader', { static: true }) private buttonHeader: ElementRef;
......@@ -58,7 +59,7 @@ export class InfoComponent implements OnInit, OnDestroy, AfterViewInit {
}
public ngOnInit(): void {
this._routerSubscription = this.route.data.subscribe(data => {
this.route.data.pipe(distinctUntilChanged(), takeUntil(this._destroy)).subscribe(data => {
this.currentData = data.content;
});
}
......@@ -74,7 +75,8 @@ export class InfoComponent implements OnInit, OnDestroy, AfterViewInit {
}
public ngOnDestroy(): void {
this._routerSubscription.unsubscribe();
this._destroy.next();
this._destroy.complete();
}
public toInfoContent(target: string): void {
......
......@@ -17,7 +17,7 @@ export class SentryErrorHandler implements ErrorHandler {
release: environment.version,
});
setExtra('nonErrorException', true);
setExtra('nonErrorException', false);
}
public handleError(error): void {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment