add return type to modal result

This commit is contained in:
MathieuG-P
2022-07-19 20:56:09 +02:00
parent 23eb716916
commit c21cb3b6fa
3 changed files with 9 additions and 7 deletions
@@ -5,7 +5,7 @@ import { BsmImage } from "renderer/components/shared/bsm-image.component";
import { BsmButton } from "renderer/components/shared/bsm-button.component";
import { useTranslation } from "renderer/hooks/use-translation.hook";
export function GuardModal({resolver}: {resolver: (x: ModalResponse) => void}) {
export function GuardModal({resolver}: {resolver: (x: ModalResponse<string>) => void}) {
const [guardCode, setGuardCode] = useState('');
const t = useTranslation();
@@ -5,7 +5,7 @@ import { useTranslation } from "renderer/hooks/use-translation.hook";
import { ModalExitCode, ModalResponse } from "renderer/services/modale.service";
import BeatImpatient from '../../../../../assets/images/apngs/beat-impatient.png'
export function LoginModal({resolver}: {resolver: (x: ModalResponse) => void}) {
export function LoginModal({resolver}: {resolver: (x: ModalResponse<any>) => void}) {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
+7 -5
View File
@@ -32,14 +32,14 @@ export class ModalService{
return this.resolver;
}
public resolve(data: ModalResponse): void{
public resolve(data: ModalResponse<unknown>): void{
this.resolver(data);
}
public async openModal(modalType: ModalType, data?: any): Promise<ModalResponse>{
public async openModal<T>(modalType: ModalType, data?: any): Promise<ModalResponse<T>>{
this.close();
await timeout(100); //Must wait resolve
const promise = new Promise<ModalResponse>((resolve) => { this.resolver = resolve; });
const promise = new Promise<ModalResponse<T>>((resolve) => { this.resolver = resolve; });
promise.then(() => this.close());
this.modalType$.next(modalType);
if(data){ this.modalData = data; }
@@ -54,6 +54,8 @@ export enum ModalType {
GUARD_CODE = "GUARD_CODE",
UNINSTALL = "UNINSTALL",
INSTALLATION_FOLDER = "INSTALLATION_FOLDER",
EDIT_VERSION = "EDIT_VERSION",
CLONE_VERSION = "CLONE_VERSION"
}
export enum ModalExitCode {
@@ -63,7 +65,7 @@ export enum ModalExitCode {
CANCELED = 2,
}
export interface ModalResponse {
export interface ModalResponse<T> {
exitCode: ModalExitCode,
data?: any
data?: T
}