-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leonardo Albuquerque
committed
Feb 21, 2023
1 parent
bc29971
commit 60256f5
Showing
6 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
interface IModal { | ||
id: string; | ||
visible: boolean; | ||
} | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ModalService { | ||
private visible: boolean = false; | ||
private modals: IModal[] = []; | ||
|
||
register(id: string): void { | ||
this.modals.push({ id, visible: false }); | ||
} | ||
|
||
unregister(id: string): void { | ||
this.modals = this.modals.filter((modal) => modal.id !== id); | ||
} | ||
|
||
isModalOpen(): boolean { | ||
return this.visible; | ||
isModalOpen(id: string): boolean { | ||
return !!this.modals.find((modal) => modal.id === id)?.visible; | ||
} | ||
|
||
toggleModal(): void { | ||
this.visible = !this.visible; | ||
toggleModal(id: string): void { | ||
const modal = this.modals.find((modal) => modal.id === id); | ||
if (modal) { | ||
modal.visible = !modal.visible; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { ModalService } from 'src/app/services/modal.service'; | ||
|
||
@Component({ | ||
selector: 'app-auth-modal', | ||
templateUrl: './auth-modal.component.html', | ||
styleUrls: ['./auth-modal.component.css'] | ||
styleUrls: ['./auth-modal.component.css'], | ||
}) | ||
export class AuthModalComponent { | ||
export class AuthModalComponent implements OnInit, OnDestroy { | ||
constructor(public modal: ModalService) {} | ||
|
||
ngOnInit(): void { | ||
this.modal.register('auth'); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.modal.unregister('auth'); | ||
} | ||
} |