/
logout-confirm.component.ts
52 lines (44 loc) · 1.24 KB
/
logout-confirm.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnDestroy,
OnInit,
} from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { Subject, interval, takeUntil } from 'rxjs';
import { LogoutService } from 'src/app/services/logout.service';
@Component({
selector: 'app-logout-confirm',
templateUrl: './logout-confirm.component.html',
styleUrls: ['./logout-confirm.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LogoutConfirmComponent implements OnInit, OnDestroy {
count = 30;
private destroyed$ = new Subject<void>();
constructor(
private changeDetection: ChangeDetectorRef,
private logoutService: LogoutService,
private matDialogRef: MatDialogRef<LogoutConfirmComponent>
) {}
ngOnInit(): void {
interval(1000)
.pipe(takeUntil(this.destroyed$))
.subscribe(() => {
if (this.count === 1) {
this.logoutService.ourLogoutFunction();
this.destroyed$.next();
}
this.count--;
this.changeDetection.detectChanges();
});
}
ngOnDestroy(): void {
this.destroyed$.next();
}
restartCountdown() {
this.matDialogRef.close();
this.logoutService.restartCountdown();
}
}