Skip to content

Commit 8e3254b

Browse files
committed
🐛 close modal auth keyup esc
1 parent 2784044 commit 8e3254b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/app/auth/auth.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
1+
import { Component, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { Subscription } from 'rxjs';
33

44
import { AuthService } from '@services/auth.service';
@@ -15,6 +15,8 @@ export class AuthComponent implements OnInit, OnDestroy {
1515
private bodyElement = document.body as HTMLBodyElement;
1616
public showLogin: boolean = true;
1717

18+
private modalOpen: boolean = false;
19+
1820
constructor(private authService: AuthService) {}
1921

2022
ngOnDestroy(): void {
@@ -28,15 +30,24 @@ export class AuthComponent implements OnInit, OnDestroy {
2830
openModal(): void {
2931
this.bodyElement.classList.add('modal-open');
3032
this.modalAuth.nativeElement.classList.add('modal-open');
33+
this.modalOpen = true;
3134
}
3235

3336
closeModal(): void {
3437
this.bodyElement.classList.remove('modal-open');
3538
this.modalAuth.nativeElement.classList.remove('modal-open');
39+
this.modalOpen = false;
3640
}
3741

3842
changePage(show: boolean) {
3943
this.showLogin = show;
4044
}
4145

46+
@HostListener('window:keyup.esc', ['$event'])
47+
onKeyup(event: any) {
48+
if(this.modalOpen) {
49+
this.closeModal();
50+
}
51+
}
52+
4253
}

src/app/core/components/sidebar/sidebar.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export class SidebarComponent implements OnInit, AfterViewInit, OnDestroy {
3939
ngOnInit(): void {
4040
this.isAuthenticated = this.authService.isAuthenticated();
4141
this.userActiveSubscription = this.authService.isAuthenticatedEmitter.subscribe(resp => {
42-
if(resp) this.setUserInfoActive();
42+
if(resp) {
43+
this.setUserInfoActive();
44+
this.isAuthenticated = true;
45+
};
4346
});
4447
}
4548

0 commit comments

Comments
 (0)