Skip to content

Commit

Permalink
Add unsubscription logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eceeeren committed May 5, 2024
1 parent d0ce53d commit 0adb203
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AlertService } from 'app/core/util/alert.service';
import { HttpErrorResponse } from '@angular/common/http';
import dayjs from 'dayjs/esm';
import { StudentExamService } from 'app/exam/manage/student-exams/student-exam.service';
import { Subject } from 'rxjs';
import { Subject, Subscription } from 'rxjs';

@Component({
selector: 'jhi-exam-checklist',
Expand All @@ -18,6 +18,7 @@ import { Subject } from 'rxjs';
export class ExamChecklistComponent implements OnChanges, OnInit, OnDestroy {
@Input() exam: Exam;
@Input() getExamRoutesByIdentifier: any;
private longestWorkingTimeSub: Subscription | null = null;

examChecklist: ExamChecklist;
isLoading = false;
Expand Down Expand Up @@ -68,7 +69,7 @@ export class ExamChecklistComponent implements OnChanges, OnInit, OnDestroy {
this.websocketService.subscribe(startedTopic);
this.websocketService.receive(startedTopic).subscribe(() => (this.numberOfStarted += 1));
if (this.exam?.id) {
this.studentExamService.getLongestWorkingTimeForExam(this.exam.id).subscribe((res) => {
this.longestWorkingTimeSub = this.studentExamService.getLongestWorkingTimeForExam(this.exam.id).subscribe((res) => {
this.longestWorkingTime = res;
this.calculateIsExamOver();
});
Expand Down Expand Up @@ -104,6 +105,9 @@ export class ExamChecklistComponent implements OnChanges, OnInit, OnDestroy {
this.websocketService.unsubscribe(submittedTopic);
const startedTopic = this.examChecklistService.getStartedTopic(this.exam);
this.websocketService.unsubscribe(startedTopic);
if (this.longestWorkingTimeSub) {
this.longestWorkingTimeSub.unsubscribe();
}
}

/**
Expand Down

0 comments on commit 0adb203

Please sign in to comment.